| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ |
| 6 #define COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ |
| 7 |
| 8 #include <cstddef> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/bind.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/location.h" |
| 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/single_thread_task_runner.h" |
| 20 |
| 5 // Weak handles provides a way to refer to weak pointers from another | 21 // Weak handles provides a way to refer to weak pointers from another |
| 6 // thread. This is useful because it is not safe to reference a weak | 22 // thread. This is useful because it is not safe to reference a weak |
| 7 // pointer from a thread other than the thread on which it was | 23 // pointer from a thread other than the thread on which it was |
| 8 // created. | 24 // created. |
| 9 // | 25 // |
| 10 // Weak handles can be passed across threads, so for example, you can | 26 // Weak handles can be passed across threads, so for example, you can |
| 11 // use them to do the "real" work on one thread and get notified on | 27 // use them to do the "real" work on one thread and get notified on |
| 12 // another thread: | 28 // another thread: |
| 13 // | 29 // |
| 14 // class FooIOWorker { | 30 // class FooIOWorker { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 37 // SpawnFooIOWorkerOnIOThread(base::MakeWeakHandle(AsWeakPtr())); | 53 // SpawnFooIOWorkerOnIOThread(base::MakeWeakHandle(AsWeakPtr())); |
| 38 // } | 54 // } |
| 39 // | 55 // |
| 40 // /* Will always be called on the correct thread, and only if this | 56 // /* Will always be called on the correct thread, and only if this |
| 41 // object hasn't been destroyed. */ | 57 // object hasn't been destroyed. */ |
| 42 // void OnIOStart() { DCHECK(CalledOnValidThread(); ... } | 58 // void OnIOStart() { DCHECK(CalledOnValidThread(); ... } |
| 43 // void OnIOEvent(IOEvent e) { DCHECK(CalledOnValidThread(); ... } | 59 // void OnIOEvent(IOEvent e) { DCHECK(CalledOnValidThread(); ... } |
| 44 // void OnIOError(IOError err) { DCHECK(CalledOnValidThread(); ... } | 60 // void OnIOError(IOError err) { DCHECK(CalledOnValidThread(); ... } |
| 45 // }; | 61 // }; |
| 46 | 62 |
| 47 #ifndef COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ | |
| 48 #define COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ | |
| 49 | |
| 50 #include <cstddef> | |
| 51 #include <utility> | |
| 52 | |
| 53 #include "base/bind.h" | |
| 54 #include "base/compiler_specific.h" | |
| 55 #include "base/gtest_prod_util.h" | |
| 56 #include "base/location.h" | |
| 57 #include "base/logging.h" | |
| 58 #include "base/macros.h" | |
| 59 #include "base/memory/ref_counted.h" | |
| 60 #include "base/memory/weak_ptr.h" | |
| 61 #include "base/single_thread_task_runner.h" | |
| 62 | |
| 63 namespace tracked_objects { | 63 namespace tracked_objects { |
| 64 class Location; | 64 class Location; |
| 65 } // namespace tracked_objects | 65 } // namespace tracked_objects |
| 66 | 66 |
| 67 namespace syncer { | 67 namespace syncer { |
| 68 | 68 |
| 69 template <typename T> | 69 template <typename T> |
| 70 class WeakHandle; | 70 class WeakHandle; |
| 71 | 71 |
| 72 namespace internal { | 72 namespace internal { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 // Makes a WeakHandle from a WeakPtr. | 195 // Makes a WeakHandle from a WeakPtr. |
| 196 template <typename T> | 196 template <typename T> |
| 197 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { | 197 WeakHandle<T> MakeWeakHandle(const base::WeakPtr<T>& ptr) { |
| 198 return WeakHandle<T>(ptr); | 198 return WeakHandle<T>(ptr); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace syncer | 201 } // namespace syncer |
| 202 | 202 |
| 203 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ | 203 #endif // COMPONENTS_SYNC_BASE_WEAK_HANDLE_H_ |
| OLD | NEW |