Commit 0dd0b2ff authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Update WeakPtrFactory examples to use in-class initializers.

This is now the more common, and simpler, pattern.

Bug: 981415
Change-Id: I082e75425a33f6256c2ddc3228d61f8b6fe8bc58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704677Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677960}
parent 121548c7
......@@ -16,14 +16,13 @@
//
// class Controller {
// public:
// Controller() : weak_factory_(this) {}
// void SpawnWorker() { Worker::StartNew(weak_factory_.GetWeakPtr()); }
// void WorkComplete(const Result& result) { ... }
// private:
// // Member variables should appear before the WeakPtrFactory, to ensure
// // that any WeakPtrs to Controller are invalidated before its members
// // variable's destructors are executed, rendering them invalid.
// WeakPtrFactory<Controller> weak_factory_;
// WeakPtrFactory<Controller> weak_factory_{this};
// };
//
// class Worker {
......
......@@ -355,13 +355,13 @@ To use `base::WeakPtr` with `base::Bind()`, `MyClass` will typically look like:
```cpp
class MyClass {
public:
MyClass() : weak_factory_(this) {
MyClass() {
weak_this_ = weak_factory_.GetWeakPtr();
}
private:
base::WeakPtr<MyClass> weak_this_;
// MyClass member variables go here.
base::WeakPtrFactory<MyClass> weak_factory_;
base::WeakPtrFactory<MyClass> weak_factory_{this};
};
```
......
......@@ -588,8 +588,6 @@ int Compute() { … }
class A {
public:
A() : weak_ptr_factory_(this) {}
void ComputeAndStore() {
// Schedule a call to Compute() in a thread pool followed by
// a call to A::Store() on the current sequence. The call to
......@@ -604,7 +602,7 @@ class A {
void Store(int value) { value_ = value; }
int value_;
base::WeakPtrFactory<A> weak_ptr_factory_;
base::WeakPtrFactory<A> weak_ptr_factory_{this};
};
```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment