Skip to content

Commit

Permalink
Revert "Use in-class initializers for base::WeakPtrFactory in base/."
Browse files Browse the repository at this point in the history
This reverts commit 66ec904.

Reason for revert: content_browsertests failing on chromium.memory/Mac
(guessed)

Original change's description:
> Use in-class initializers for base::WeakPtrFactory in base/.
> 
> Generated by: https://chromium-review.googlesource.com/c/chromium/src/+/1689216
> 
> Bug: 981415
> Change-Id: Ib185d9d46bbfa787b77fbbafcc3e5bfb7799dd20
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1688886
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Commit-Queue: Jeremy Roman <jbroman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#674950}

TBR=dcheng@chromium.org,gab@chromium.org,jbroman@chromium.org

Change-Id: Icba04326fde8bca8b2c30b6da051c2e37b681f6d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 981415, 981444
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1686590
Reviewed-by: Yoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#674965}
  • Loading branch information
Yoichi Osato authored and Commit Bot committed Jul 5, 2019
1 parent 2b5405d commit 7407a6c
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 37 deletions.
6 changes: 3 additions & 3 deletions base/cancelable_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ namespace internal {
template <typename CallbackType>
class CancelableCallbackImpl {
public:
CancelableCallbackImpl() {}
CancelableCallbackImpl() : weak_ptr_factory_(this) {}

// |callback| must not be null.
explicit CancelableCallbackImpl(CallbackType callback)
: callback_(std::move(callback)) {
: callback_(std::move(callback)), weak_ptr_factory_(this) {
DCHECK(callback_);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ class CancelableCallbackImpl {

// The stored closure that may be cancelled.
CallbackType callback_;
mutable base::WeakPtrFactory<CancelableCallbackImpl> weak_ptr_factory_{this};
mutable base::WeakPtrFactory<CancelableCallbackImpl> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(CancelableCallbackImpl);
};
Expand Down
3 changes: 2 additions & 1 deletion base/files/file_descriptor_watcher_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ FileDescriptorWatcher::Controller::Controller(MessagePumpForIO::Mode mode,
const RepeatingClosure& callback)
: callback_(callback),
io_thread_task_runner_(
tls_fd_watcher.Get().Get()->io_thread_task_runner()) {
tls_fd_watcher.Get().Get()->io_thread_task_runner()),
weak_factory_(this) {
DCHECK(!callback_.is_null());
DCHECK(io_thread_task_runner_);
watcher_ = std::make_unique<Watcher>(weak_factory_.GetWeakPtr(), mode, fd);
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_descriptor_watcher_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BASE_EXPORT FileDescriptorWatcher {
// instantiated.
SequenceChecker sequence_checker_;

WeakPtrFactory<Controller> weak_factory_{this};
WeakPtrFactory<Controller> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(Controller);
};
Expand Down
4 changes: 2 additions & 2 deletions base/files/file_path_watcher_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {
// appear after it, that is not possible.
WeakPtr<FilePathWatcherImpl> weak_ptr_;

WeakPtrFactory<FilePathWatcherImpl> weak_factory_{this};
WeakPtrFactory<FilePathWatcherImpl> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl);
};
Expand Down Expand Up @@ -391,7 +391,7 @@ void InotifyReader::OnInotifyEvent(const inotify_event* event) {
}
}

FilePathWatcherImpl::FilePathWatcherImpl() {
FilePathWatcherImpl::FilePathWatcherImpl() : weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
}

Expand Down
5 changes: 3 additions & 2 deletions base/files/file_proxy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class FileProxyTest : public testing::Test {
test::ScopedTaskEnvironment::MainThreadType::IO),
file_thread_("FileProxyTestFileThread"),
error_(File::FILE_OK),
bytes_written_(-1) {}
bytes_written_(-1),
weak_factory_(this) {}

void SetUp() override {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
Expand Down Expand Up @@ -102,7 +103,7 @@ class FileProxyTest : public testing::Test {
File::Info file_info_;
std::vector<char> buffer_;
int bytes_written_;
WeakPtrFactory<FileProxyTest> weak_factory_{this};
WeakPtrFactory<FileProxyTest> weak_factory_;
};

TEST_F(FileProxyTest, CreateOrOpen_Create) {
Expand Down
3 changes: 2 additions & 1 deletion base/files/important_file_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ ImportantFileWriter::ImportantFileWriter(
task_runner_(std::move(task_runner)),
serializer_(nullptr),
commit_interval_(interval),
histogram_suffix_(histogram_suffix ? histogram_suffix : "") {
histogram_suffix_(histogram_suffix ? histogram_suffix : ""),
weak_factory_(this) {
DCHECK(task_runner_);
}

Expand Down
2 changes: 1 addition & 1 deletion base/files/important_file_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class BASE_EXPORT ImportantFileWriter {

SEQUENCE_CHECKER(sequence_checker_);

WeakPtrFactory<ImportantFileWriter> weak_factory_{this};
WeakPtrFactory<ImportantFileWriter> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter);
};
Expand Down
4 changes: 2 additions & 2 deletions base/memory/weak_ptr_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ struct Arrow {
WeakPtr<Target> target;
};
struct TargetWithFactory : public Target {
TargetWithFactory() {}
WeakPtrFactory<Target> factory{this};
TargetWithFactory() : factory(this) {}
WeakPtrFactory<Target> factory;
};

// Helper class to create and destroy weak pointer copies
Expand Down
4 changes: 2 additions & 2 deletions base/metrics/statistics_recorder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class TestHistogramProvider : public StatisticsRecorder::HistogramProvider {
public:
explicit TestHistogramProvider(
std::unique_ptr<PersistentHistogramAllocator> allocator)
: allocator_(std::move(allocator)) {
: allocator_(std::move(allocator)), weak_factory_(this) {
StatisticsRecorder::RegisterHistogramProvider(weak_factory_.GetWeakPtr());
}

Expand All @@ -661,7 +661,7 @@ class TestHistogramProvider : public StatisticsRecorder::HistogramProvider {

private:
std::unique_ptr<PersistentHistogramAllocator> allocator_;
WeakPtrFactory<TestHistogramProvider> weak_factory_{this};
WeakPtrFactory<TestHistogramProvider> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(TestHistogramProvider);
};
Expand Down
5 changes: 3 additions & 2 deletions base/observer_list_threadsafe_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class AddRemoveThread : public Foo {
SingleThreadTaskRunnerThreadMode::DEDICATED)),
in_list_(false),
start_(Time::Now()),
do_notifies_(notify) {
do_notifies_(notify),
weak_factory_(this) {
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr()));
Expand Down Expand Up @@ -131,7 +132,7 @@ class AddRemoveThread : public Foo {

bool do_notifies_; // Whether these threads should do notifications.

base::WeakPtrFactory<AddRemoveThread> weak_factory_{this};
base::WeakPtrFactory<AddRemoveThread> weak_factory_;
};

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion base/observer_list_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace base {

CheckedObserver::CheckedObserver() {}
CheckedObserver::CheckedObserver() : factory_(this) {}
CheckedObserver::~CheckedObserver() = default;

bool CheckedObserver::IsInObserverList() const {
Expand Down
2 changes: 1 addition & 1 deletion base/observer_list_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BASE_EXPORT CheckedObserver {
friend class internal::CheckedObserverAdapter;

// Must be mutable to allow ObserverList<const Foo>.
mutable WeakPtrFactory<CheckedObserver> factory_{this};
mutable WeakPtrFactory<CheckedObserver> factory_;

DISALLOW_COPY_AND_ASSIGN(CheckedObserver);
};
Expand Down
3 changes: 2 additions & 1 deletion base/run_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void RunLoop::RegisterDelegateForCurrentThread(Delegate* delegate) {
RunLoop::RunLoop(Type type)
: delegate_(GetTlsDelegate().Get()),
type_(type),
origin_task_runner_(ThreadTaskRunnerHandle::Get()) {
origin_task_runner_(ThreadTaskRunnerHandle::Get()),
weak_factory_(this) {
DCHECK(delegate_) << "A RunLoop::Delegate must be bound to this thread prior "
"to using RunLoop.";
DCHECK(origin_task_runner_);
Expand Down
2 changes: 1 addition & 1 deletion base/run_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class BASE_EXPORT RunLoop {
const scoped_refptr<SingleThreadTaskRunner> origin_task_runner_;

// WeakPtrFactory for QuitClosure safety.
WeakPtrFactory<RunLoop> weak_factory_{this};
WeakPtrFactory<RunLoop> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(RunLoop);
};
Expand Down
4 changes: 2 additions & 2 deletions base/task/promise/promise_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class MockObject {
struct DummyError {};

struct Cancelable {
Cancelable() {}
Cancelable() : weak_ptr_factory(this) {}

void LogTask(std::vector<std::string>* log, std::string value) {
log->push_back(value);
}

void NopTask() {}

WeakPtrFactory<Cancelable> weak_ptr_factory{this};
WeakPtrFactory<Cancelable> weak_ptr_factory;
};

} // namespace
Expand Down
3 changes: 2 additions & 1 deletion base/task/sequence_manager/sequence_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ SequenceManagerImpl::SequenceManagerImpl(

empty_queues_to_reload_(associated_thread_),
memory_corruption_sentinel_(kMemoryCorruptionSentinelValue),
main_thread_only_(associated_thread_, settings_) {
main_thread_only_(associated_thread_, settings_),
weak_factory_(this) {
TRACE_EVENT_OBJECT_CREATED_WITH_ID(
TRACE_DISABLED_BY_DEFAULT("sequence_manager"), "SequenceManager", this);
main_thread_only().selector.SetTaskQueueSelectorObserver(this);
Expand Down
2 changes: 1 addition & 1 deletion base/task/sequence_manager/sequence_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class BASE_EXPORT SequenceManagerImpl
return main_thread_only_;
}

WeakPtrFactory<SequenceManagerImpl> weak_factory_{this};
WeakPtrFactory<SequenceManagerImpl> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(SequenceManagerImpl);
};
Expand Down
9 changes: 5 additions & 4 deletions base/task/sequence_manager/sequence_manager_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2520,14 +2520,15 @@ TEST_P(SequenceManagerTest, TaskQueueObserver_DelayedWorkWhichCanRunNow) {

class CancelableTask {
public:
explicit CancelableTask(const TickClock* clock) : clock_(clock) {}
explicit CancelableTask(const TickClock* clock)
: clock_(clock), weak_factory_(this) {}

void RecordTimeTask(std::vector<TimeTicks>* run_times) {
run_times->push_back(clock_->NowTicks());
}

const TickClock* clock_;
WeakPtrFactory<CancelableTask> weak_factory_{this};
WeakPtrFactory<CancelableTask> weak_factory_;
};

TEST_P(SequenceManagerTest, TaskQueueObserver_SweepCanceledDelayedTasks) {
Expand Down Expand Up @@ -4509,14 +4510,14 @@ TEST_P(SequenceManagerTest, TaskPriortyInterleaving) {

class CancelableTaskWithDestructionObserver {
public:
CancelableTaskWithDestructionObserver() {}
CancelableTaskWithDestructionObserver() : weak_factory_(this) {}

void Task(std::unique_ptr<ScopedClosureRunner> destruction_observer) {
destruction_observer_ = std::move(destruction_observer);
}

std::unique_ptr<ScopedClosureRunner> destruction_observer_;
WeakPtrFactory<CancelableTaskWithDestructionObserver> weak_factory_{this};
WeakPtrFactory<CancelableTaskWithDestructionObserver> weak_factory_;
};

TEST_P(SequenceManagerTest, PeriodicHousekeeping) {
Expand Down
2 changes: 1 addition & 1 deletion base/task/sequence_manager/test/test_task_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace sequence_manager {

TestTaskQueue::TestTaskQueue(std::unique_ptr<internal::TaskQueueImpl> impl,
const TaskQueue::Spec& spec)
: TaskQueue(std::move(impl), spec) {}
: TaskQueue(std::move(impl), spec), weak_factory_(this) {}

TestTaskQueue::~TestTaskQueue() = default;

Expand Down
2 changes: 1 addition & 1 deletion base/task/sequence_manager/test/test_task_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestTaskQueue : public TaskQueue {
~TestTaskQueue() override; // Ref-counted.

// Used to ensure that task queue is deleted in tests.
WeakPtrFactory<TestTaskQueue> weak_factory_{this};
WeakPtrFactory<TestTaskQueue> weak_factory_;
};

} // namespace sequence_manager
Expand Down
3 changes: 2 additions & 1 deletion base/task/sequence_manager/thread_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ThreadControllerImpl::ThreadControllerImpl(
? funneled_sequence_manager->GetTaskRunner()
: nullptr),
time_source_(time_source),
work_deduplicator_(associated_thread_) {
work_deduplicator_(associated_thread_),
weak_factory_(this) {
if (task_runner_ || funneled_sequence_manager_)
work_deduplicator_.BindToCurrentThread();
immediate_do_work_closure_ =
Expand Down
2 changes: 1 addition & 1 deletion base/task/sequence_manager/thread_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BASE_EXPORT ThreadControllerImpl : public ThreadController,
bool default_task_runner_set_ = false;
#endif

WeakPtrFactory<ThreadControllerImpl> weak_factory_{this};
WeakPtrFactory<ThreadControllerImpl> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(ThreadControllerImpl);
};
Expand Down
4 changes: 2 additions & 2 deletions base/task/sequence_manager/work_queue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class MockObserver : public WorkQueueSets::Observer {
void NopTask() {}

struct Cancelable {
Cancelable() {}
Cancelable() : weak_ptr_factory(this) {}

void NopTask() {}

WeakPtrFactory<Cancelable> weak_ptr_factory{this};
WeakPtrFactory<Cancelable> weak_ptr_factory;
};

class RealTimeDomainFake : public RealTimeDomain {
Expand Down
3 changes: 2 additions & 1 deletion base/trace_event/blame_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ BlameContext::BlameContext(const char* category,
id_(id),
parent_scope_(parent_context ? parent_context->scope() : nullptr),
parent_id_(parent_context ? parent_context->id() : 0),
category_group_enabled_(nullptr) {
category_group_enabled_(nullptr),
weak_factory_(this) {
DCHECK(!parent_context || !std::strcmp(name_, parent_context->name()))
<< "Parent blame context must have the same name";
}
Expand Down
2 changes: 1 addition & 1 deletion base/trace_event/blame_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BASE_EXPORT BlameContext
const unsigned char* category_group_enabled_;

ThreadChecker thread_checker_;
WeakPtrFactory<BlameContext> weak_factory_{this};
WeakPtrFactory<BlameContext> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(BlameContext);
};
Expand Down

0 comments on commit 7407a6c

Please sign in to comment.