Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chromecast/base/observer.h

Issue 2920723002: Use ContainsValue() instead of std::find() in chromecast/ (Closed)
Patch Set: Adding blank line and removing an extra line. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chromecast/graphics/cast_focus_client_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 // Safe Observer/Observable implementation. 5 // Safe Observer/Observable implementation.
6 // 6 //
7 // When using ObserverListThreadSafe, we were running into issues since there 7 // When using ObserverListThreadSafe, we were running into issues since there
8 // was no synchronization between getting the existing value, and registering 8 // was no synchronization between getting the existing value, and registering
9 // as an observer. See go/cast-platform-design-synchronized-value for more 9 // as an observer. See go/cast-platform-design-synchronized-value for more
10 // details. 10 // details.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 #include "base/bind.h" 108 #include "base/bind.h"
109 #include "base/callback.h" 109 #include "base/callback.h"
110 #include "base/location.h" 110 #include "base/location.h"
111 #include "base/logging.h" 111 #include "base/logging.h"
112 #include "base/macros.h" 112 #include "base/macros.h"
113 #include "base/memory/ptr_util.h" 113 #include "base/memory/ptr_util.h"
114 #include "base/memory/ref_counted.h" 114 #include "base/memory/ref_counted.h"
115 #include "base/sequence_checker.h" 115 #include "base/sequence_checker.h"
116 #include "base/sequenced_task_runner.h" 116 #include "base/sequenced_task_runner.h"
117 #include "base/stl_util.h"
117 #include "base/synchronization/lock.h" 118 #include "base/synchronization/lock.h"
118 #include "base/threading/sequenced_task_runner_handle.h" 119 #include "base/threading/sequenced_task_runner_handle.h"
119 120
120 namespace chromecast { 121 namespace chromecast {
121 122
122 namespace subtle { 123 namespace subtle {
123 template <typename T> 124 template <typename T>
124 class ObservableInternals; 125 class ObservableInternals;
125 } // namespace subtle 126 } // namespace subtle
126 127
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 SequenceOwnedInfo(const T& value) : value_(value) {} 260 SequenceOwnedInfo(const T& value) : value_(value) {}
260 261
261 const T& value() const { 262 const T& value() const {
262 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 263 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
263 return value_; 264 return value_;
264 } 265 }
265 266
266 void AddObserver(Observer<T>* observer) { 267 void AddObserver(Observer<T>* observer) {
267 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 268 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
268 DCHECK(observer); 269 DCHECK(observer);
269 DCHECK(std::find(observers_.begin(), observers_.end(), observer) == 270 DCHECK(!base::ContainsValue(observers_, observer));
270 observers_.end());
271 observers_.push_back(observer); 271 observers_.push_back(observer);
272 } 272 }
273 273
274 void RemoveObserver(Observer<T>* observer) { 274 void RemoveObserver(Observer<T>* observer) {
275 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 275 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
276 DCHECK(observer); 276 DCHECK(observer);
277 DCHECK(std::find(observers_.begin(), observers_.end(), observer) != 277 DCHECK(base::ContainsValue(observers_, observer));
278 observers_.end());
279 observers_.erase( 278 observers_.erase(
280 std::remove(observers_.begin(), observers_.end(), observer), 279 std::remove(observers_.begin(), observers_.end(), observer),
281 observers_.end()); 280 observers_.end());
282 } 281 }
283 282
284 bool Empty() const { 283 bool Empty() const {
285 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 284 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
286 return observers_.empty(); 285 return observers_.empty();
287 } 286 }
288 287
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 419 }
421 420
422 template <typename T> 421 template <typename T>
423 T Observable<T>::GetValueThreadSafe() const { 422 T Observable<T>::GetValueThreadSafe() const {
424 return internals_->GetValueThreadSafe(); 423 return internals_->GetValueThreadSafe();
425 } 424 }
426 425
427 } // namespace chromecast 426 } // namespace chromecast
428 427
429 #endif // CHROMECAST_BASE_OBSERVER_H_ 428 #endif // CHROMECAST_BASE_OBSERVER_H_
OLDNEW
« no previous file with comments | « no previous file | chromecast/graphics/cast_focus_client_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698