Commit 093de9b3 authored by dcheng's avatar dcheng Committed by Commit bot

Convert //base to use std::unique_ptr

With bonus IWYU fixes that weren't caught by local android gn, cros gn,
linux gn, mac gyp, and win gyp builds.

BUG=554298
TBR=brettw@chromium.org

Review URL: https://codereview.chromium.org/1852433005

Cr-Commit-Position: refs/heads/master@{#385011}
parent 9eb26a39
......@@ -9,11 +9,11 @@
#include <string.h>
#include <unistd.h>
#include <memory>
#include <new>
#include <vector>
#include "base/atomicops.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_local.h"
......@@ -126,7 +126,7 @@ class AllocatorShimTest : public testing::Test {
size_t reallocs_intercepted_by_size[kMaxSizeTracked];
size_t reallocs_intercepted_by_addr[kMaxSizeTracked];
size_t frees_intercepted_by_addr[kMaxSizeTracked];
scoped_ptr<ThreadLocalBoolean> did_fail_realloc_0x42_once;
std::unique_ptr<ThreadLocalBoolean> did_fail_realloc_0x42_once;
subtle::Atomic32 num_new_handler_calls;
private:
......
......@@ -3,10 +3,12 @@
// found in the LICENSE file.
#include "base/android/application_status_listener.h"
#include <memory>
#include "base/bind.h"
#include "base/callback_forward.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
......@@ -92,7 +94,7 @@ class MultiThreadedTest {
base::WaitableEvent event_;
base::Thread thread_;
base::MessageLoop main_;
scoped_ptr<ApplicationStatusListener> listener_;
std::unique_ptr<ApplicationStatusListener> listener_;
};
} // namespace
......
......@@ -7,8 +7,9 @@
#include <jni.h>
#include <memory>
#include "base/android/scoped_java_ref.h"
#include "base/memory/scoped_ptr.h"
namespace base {
......@@ -43,7 +44,7 @@ class BASE_EXPORT JavaHandlerThread {
static bool RegisterBindings(JNIEnv* env);
private:
scoped_ptr<base::MessageLoop> message_loop_;
std::unique_ptr<base::MessageLoop> message_loop_;
ScopedJavaGlobalRef<jobject> java_thread_;
};
......
......@@ -314,7 +314,7 @@ jint GetHistogramValueCountForTesting(
return 0;
}
scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
std::unique_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
return samples->GetCount(static_cast<int>(sample));
}
......
......@@ -6,18 +6,19 @@
// don't have their own base_paths_OS.cc implementation (i.e. all but Mac and
// Android).
#include "base/base_paths.h"
#include <limits.h>
#include <stddef.h>
#include <memory>
#include <ostream>
#include <string>
#include "base/base_paths.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/nix/xdg_util.h"
#include "base/path_service.h"
#include "base/process/process_metrics.h"
......@@ -79,7 +80,7 @@ bool PathProviderPosix(int key, FilePath* result) {
case base::DIR_SOURCE_ROOT: {
// Allow passing this in the environment, for more flexibility in build
// tree configurations (sub-project builds, gyp --output_dir, etc.)
scoped_ptr<base::Environment> env(base::Environment::Create());
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string cr_source_root;
if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) {
path = FilePath(cr_source_root);
......@@ -106,7 +107,7 @@ bool PathProviderPosix(int key, FilePath* result) {
*result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop");
return true;
case base::DIR_CACHE: {
scoped_ptr<base::Environment> env(base::Environment::Create());
std::unique_ptr<base::Environment> env(base::Environment::Create());
FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME",
".cache"));
*result = cache_dir;
......
......@@ -70,7 +70,7 @@ bool PathProviderWin(int key, FilePath* result) {
#if !defined(_WIN64)
if (base::win::OSInfo::GetInstance()->wow64_status() ==
base::win::OSInfo::WOW64_ENABLED) {
scoped_ptr<base::Environment> env(base::Environment::Create());
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string programfiles_w6432;
// 32-bit process running in WOW64 sets ProgramW6432 environment
// variable. See
......
......@@ -121,10 +121,11 @@
//
// EXAMPLE OF Passed():
//
// void TakesOwnership(scoped_ptr<Foo> arg) { }
// scoped_ptr<Foo> CreateFoo() { return scoped_ptr<Foo>(new Foo()); }
// void TakesOwnership(std::unique_ptr<Foo> arg) { }
// std::unique_ptr<Foo> CreateFoo() { return std::unique_ptr<Foo>(new Foo());
// }
//
// scoped_ptr<Foo> f(new Foo());
// std::unique_ptr<Foo> f(new Foo());
//
// // |cb| is given ownership of Foo(). |f| is now NULL.
// // You can use std::move(f) in place of &f, but it's more verbose.
......@@ -353,7 +354,7 @@ struct IgnoreResultHelper<Callback<T> > {
// An alternate implementation is to avoid the destructive copy, and instead
// specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to
// a class that is essentially a scoped_ptr<>.
// a class that is essentially a std::unique_ptr<>.
//
// The current implementation has the benefit though of leaving ParamTraits<>
// fully in callback_internal.h as well as avoiding type conversions during
......
......@@ -10,8 +10,8 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -817,7 +817,7 @@ struct CustomDeleter {
};
using MoveOnlyTypesToTest =
::testing::Types<scoped_ptr<DeleteCounter>,
::testing::Types<std::unique_ptr<DeleteCounter>,
std::unique_ptr<DeleteCounter>,
std::unique_ptr<DeleteCounter, CustomDeleter>>;
TYPED_TEST_CASE(BindMoveOnlyTypeTest, MoveOnlyTypesToTest);
......@@ -874,23 +874,23 @@ TYPED_TEST(BindMoveOnlyTypeTest, UnboundForwarding) {
EXPECT_EQ(1, deletes);
}
void VerifyVector(const std::vector<scoped_ptr<int>>& v) {
void VerifyVector(const std::vector<std::unique_ptr<int>>& v) {
ASSERT_EQ(1u, v.size());
EXPECT_EQ(12345, *v[0]);
}
std::vector<scoped_ptr<int>> AcceptAndReturnMoveOnlyVector(
std::vector<scoped_ptr<int>> v) {
std::vector<std::unique_ptr<int>> AcceptAndReturnMoveOnlyVector(
std::vector<std::unique_ptr<int>> v) {
VerifyVector(v);
return v;
}
// Test that a vector containing move-only types can be used with Callback.
TEST_F(BindTest, BindMoveOnlyVector) {
using MoveOnlyVector = std::vector<scoped_ptr<int>>;
using MoveOnlyVector = std::vector<std::unique_ptr<int>>;
MoveOnlyVector v;
v.push_back(make_scoped_ptr(new int(12345)));
v.push_back(WrapUnique(new int(12345)));
// Early binding should work:
base::Callback<MoveOnlyVector()> bound_cb =
......
......@@ -187,8 +187,8 @@
//
// PASSING PARAMETERS AS A scoped_ptr
//
// void TakesOwnership(scoped_ptr<Foo> arg) {}
// scoped_ptr<Foo> f(new Foo);
// void TakesOwnership(std::unique_ptr<Foo> arg) {}
// std::unique_ptr<Foo> f(new Foo);
// // f becomes null during the following call.
// base::Closure cb = base::Bind(&TakesOwnership, base::Passed(&f));
//
......
......@@ -18,7 +18,6 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
namespace base {
namespace internal {
......
......@@ -6,13 +6,13 @@
#define BASE_CALLBACK_LIST_H_
#include <list>
#include <memory>
#include "base/callback.h"
#include "base/callback_internal.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
// OVERVIEW:
//
......@@ -29,7 +29,7 @@
//
// typedef base::Callback<void(const Foo&)> OnFooCallback;
//
// scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription>
// RegisterCallback(const OnFooCallback& cb) {
// return callback_list_.Add(cb);
// }
......@@ -62,7 +62,7 @@
// // Do something.
// }
//
// scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
// std::unique_ptr<base::CallbackList<void(const Foo&)>::Subscription>
// foo_subscription_;
//
// DISALLOW_COPY_AND_ASSIGN(MyWidgetListener);
......@@ -103,9 +103,9 @@ class CallbackListBase {
// Add a callback to the list. The callback will remain registered until the
// returned Subscription is destroyed, which must occur before the
// CallbackList is destroyed.
scoped_ptr<Subscription> Add(const CallbackType& cb) WARN_UNUSED_RESULT {
std::unique_ptr<Subscription> Add(const CallbackType& cb) WARN_UNUSED_RESULT {
DCHECK(!cb.is_null());
return scoped_ptr<Subscription>(
return std::unique_ptr<Subscription>(
new Subscription(this, callbacks_.insert(callbacks_.end(), cb)));
}
......
......@@ -4,12 +4,12 @@
#include "base/callback_list.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......@@ -38,7 +38,7 @@ class Remover {
removal_subscription_.reset();
}
void SetSubscriptionToRemove(
scoped_ptr<CallbackList<void(void)>::Subscription> sub) {
std::unique_ptr<CallbackList<void(void)>::Subscription> sub) {
removal_subscription_ = std::move(sub);
}
......@@ -46,7 +46,7 @@ class Remover {
private:
int total_;
scoped_ptr<CallbackList<void(void)>::Subscription> removal_subscription_;
std::unique_ptr<CallbackList<void(void)>::Subscription> removal_subscription_;
DISALLOW_COPY_AND_ASSIGN(Remover);
};
......@@ -74,7 +74,7 @@ class Adder {
bool added_;
int total_;
CallbackList<void(void)>* cb_reg_;
scoped_ptr<CallbackList<void(void)>::Subscription> subscription_;
std::unique_ptr<CallbackList<void(void)>::Subscription> subscription_;
DISALLOW_COPY_AND_ASSIGN(Adder);
};
......@@ -118,42 +118,43 @@ TEST(CallbackListTest, ArityTest) {
Summer s;
CallbackList<void(int)> c1;
scoped_ptr<CallbackList<void(int)>::Subscription> subscription1 =
std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 =
c1.Add(Bind(&Summer::AddOneParam, Unretained(&s)));
c1.Notify(1);
EXPECT_EQ(1, s.value());
CallbackList<void(int, int)> c2;
scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s)));
c2.Notify(1, 2);
EXPECT_EQ(3, s.value());
CallbackList<void(int, int, int)> c3;
scoped_ptr<CallbackList<void(int, int, int)>::Subscription>
std::unique_ptr<CallbackList<void(int, int, int)>::Subscription>
subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s)));
c3.Notify(1, 2, 3);
EXPECT_EQ(6, s.value());
CallbackList<void(int, int, int, int)> c4;
scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription>
std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription>
subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s)));
c4.Notify(1, 2, 3, 4);
EXPECT_EQ(10, s.value());
CallbackList<void(int, int, int, int, int)> c5;
scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s)));
c5.Notify(1, 2, 3, 4, 5);
EXPECT_EQ(15, s.value());
CallbackList<void(int, int, int, int, int, int)> c6;
scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription>
std::unique_ptr<
CallbackList<void(int, int, int, int, int, int)>::Subscription>
subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s)));
c6.Notify(1, 2, 3, 4, 5, 6);
......@@ -166,9 +167,9 @@ TEST(CallbackListTest, BasicTest) {
CallbackList<void(void)> cb_reg;
Listener a, b, c;
scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a)));
scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
EXPECT_TRUE(a_subscription.get());
......@@ -181,7 +182,7 @@ TEST(CallbackListTest, BasicTest) {
b_subscription.reset();
scoped_ptr<CallbackList<void(void)>::Subscription> c_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c)));
cb_reg.Notify();
......@@ -201,9 +202,9 @@ TEST(CallbackListTest, BasicTestWithParams) {
CallbackList<void(int)> cb_reg;
Listener a(1), b(-1), c(1);
scoped_ptr<CallbackList<void(int)>::Subscription> a_subscription =
std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a)));
scoped_ptr<CallbackList<void(int)>::Subscription> b_subscription =
std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b)));
EXPECT_TRUE(a_subscription.get());
......@@ -216,7 +217,7 @@ TEST(CallbackListTest, BasicTestWithParams) {
b_subscription.reset();
scoped_ptr<CallbackList<void(int)>::Subscription> c_subscription =
std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c)));
cb_reg.Notify(10);
......@@ -237,15 +238,15 @@ TEST(CallbackListTest, RemoveCallbacksDuringIteration) {
Listener a, b;
Remover remover_1, remover_2;
scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
Unretained(&remover_1)));
scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
Unretained(&remover_2)));
scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add(
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1)));
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add(
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2)));
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a)));
scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
// |remover_1| will remove itself.
......@@ -278,9 +279,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) {
CallbackList<void(void)> cb_reg;
Adder a(&cb_reg);
Listener b;
scoped_ptr<CallbackList<void(void)>::Subscription> a_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a)));
scoped_ptr<CallbackList<void(void)>::Subscription> b_subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b)));
cb_reg.Notify();
......@@ -308,7 +309,7 @@ TEST(CallbackList, RemovalCallback) {
cb_reg.set_removal_callback(
Bind(&Counter::Increment, Unretained(&remove_count)));
scoped_ptr<CallbackList<void(void)>::Subscription> subscription =
std::unique_ptr<CallbackList<void(void)>::Subscription> subscription =
cb_reg.Add(Bind(&DoNothing));
// Removing a subscription outside of iteration signals the callback.
......@@ -318,12 +319,12 @@ TEST(CallbackList, RemovalCallback) {
// Configure two subscriptions to remove themselves.
Remover remover_1, remover_2;
scoped_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
Unretained(&remover_1)));
scoped_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add(Bind(&Remover::IncrementTotalAndRemove,
Unretained(&remover_2)));
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add(
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1)));
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add(
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2)));
remover_1.SetSubscriptionToRemove(std::move(remover_1_sub));
remover_2.SetSubscriptionToRemove(std::move(remover_2_sub));
......
......@@ -7,12 +7,12 @@
#include "base/callback_list.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
namespace base {
......@@ -26,9 +26,9 @@ class FooListener {
public:
FooListener() {}
void GotAScopedFoo(scoped_ptr<Foo> f) { foo_ = std::move(f); }
void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); }
scoped_ptr<Foo> foo_;
std::unique_ptr<Foo> foo_;
private:
DISALLOW_COPY_AND_ASSIGN(FooListener);
......@@ -45,10 +45,10 @@ class FooListener {
// first callback has been run.
void WontCompile() {
FooListener f;
CallbackList<void(scoped_ptr<Foo>)> c1;
scoped_ptr<CallbackList<void(scoped_ptr<Foo>)>::Subscription> sub =
CallbackList<void(std::unique_ptr<Foo>)> c1;
std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub =
c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f)));
c1.Notify(scoped_ptr<Foo>(new Foo()));
c1.Notify(std::unique_ptr<Foo>(new Foo()));
}
#endif
......
......@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/callback.h"
#include <memory>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/callback_internal.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......
......@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be