Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_ARC_INSTANCE_HOLDER_H_ | 5 #ifndef COMPONENTS_ARC_INSTANCE_HOLDER_H_ |
| 6 #define COMPONENTS_ARC_INSTANCE_HOLDER_H_ | 6 #define COMPONENTS_ARC_INSTANCE_HOLDER_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 observer->OnInstanceReady(); | 55 observer->OnInstanceReady(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void RemoveObserver(Observer* observer) { | 58 void RemoveObserver(Observer* observer) { |
| 59 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 observer_list_.RemoveObserver(observer); | 60 observer_list_.RemoveObserver(observer); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Called when the channel is closed. | 63 // Called when the channel is closed. |
| 64 void CloseChannel() { | 64 void CloseChannel() { |
| 65 if (!ptr_) | 65 if (!ptr_ && !raw_ptr_) |
|
Luis Héctor Chávez
2016/07/25 17:31:17
I prefer if this would only be |!raw_ptr_|, since
lgcheng
2016/07/25 20:45:17
Done.
| |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 ptr_.reset(); | 68 ptr_.reset(); |
| 69 raw_ptr_ = nullptr; | 69 raw_ptr_ = nullptr; |
| 70 version_ = 0; | 70 version_ = 0; |
| 71 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceClosed()); | 71 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceClosed()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Sets the interface pointer to |ptr|, once the version is determined. This | 74 // Sets the interface pointer to |ptr|, once the version is determined. This |
| 75 // will eventually invoke SetInstance(), which will notify the observers. | 75 // will eventually invoke SetInstance(), which will notify the observers. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 // This needs to be the last member in order to cancel all inflight callbacks | 118 // This needs to be the last member in order to cancel all inflight callbacks |
| 119 // before destroying any other members. | 119 // before destroying any other members. |
| 120 base::WeakPtrFactory<InstanceHolder<T>> weak_factory_; | 120 base::WeakPtrFactory<InstanceHolder<T>> weak_factory_; |
| 121 | 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); | 122 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace arc | 125 } // namespace arc |
| 126 | 126 |
| 127 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_ | 127 #endif // COMPONENTS_ARC_INSTANCE_HOLDER_H_ |
| OLD | NEW |