OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/invalidation/invalidator_registrar.h" | 5 #include "components/invalidation/invalidator_registrar.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 CHECK(handler_to_ids_map_.empty()); | 21 CHECK(handler_to_ids_map_.empty()); |
22 } | 22 } |
23 | 23 |
24 void InvalidatorRegistrar::RegisterHandler(InvalidationHandler* handler) { | 24 void InvalidatorRegistrar::RegisterHandler(InvalidationHandler* handler) { |
25 DCHECK(thread_checker_.CalledOnValidThread()); | 25 DCHECK(thread_checker_.CalledOnValidThread()); |
26 CHECK(handler); | 26 CHECK(handler); |
27 CHECK(!handlers_.HasObserver(handler)); | 27 CHECK(!handlers_.HasObserver(handler)); |
28 handlers_.AddObserver(handler); | 28 handlers_.AddObserver(handler); |
29 } | 29 } |
30 | 30 |
31 void InvalidatorRegistrar::UpdateRegisteredIds( | 31 bool InvalidatorRegistrar::UpdateRegisteredIds(InvalidationHandler* handler, |
32 InvalidationHandler* handler, | 32 const ObjectIdSet& ids) { |
33 const ObjectIdSet& ids) { | |
34 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
35 CHECK(handler); | 34 CHECK(handler); |
36 CHECK(handlers_.HasObserver(handler)); | 35 CHECK(handlers_.HasObserver(handler)); |
37 | 36 |
38 for (HandlerIdsMap::const_iterator it = handler_to_ids_map_.begin(); | 37 for (HandlerIdsMap::const_iterator it = handler_to_ids_map_.begin(); |
39 it != handler_to_ids_map_.end(); ++it) { | 38 it != handler_to_ids_map_.end(); ++it) { |
40 if (it->first == handler) { | 39 if (it->first == handler) { |
41 continue; | 40 continue; |
42 } | 41 } |
43 | 42 |
44 std::vector<invalidation::ObjectId> intersection; | 43 std::vector<invalidation::ObjectId> intersection; |
45 std::set_intersection( | 44 std::set_intersection( |
46 it->second.begin(), it->second.end(), | 45 it->second.begin(), it->second.end(), |
47 ids.begin(), ids.end(), | 46 ids.begin(), ids.end(), |
48 std::inserter(intersection, intersection.end()), | 47 std::inserter(intersection, intersection.end()), |
49 ObjectIdLessThan()); | 48 ObjectIdLessThan()); |
50 CHECK(intersection.empty()) | 49 if (!intersection.empty()) { |
51 << "Duplicate registration: trying to register " | 50 DVLOG(0) << "Duplicate registration: trying to register " |
maniscalco
2015/05/18 15:42:28
Can you walk me through the thought process on the
pavely
2015/05/18 18:38:04
I think LOG(ERROR) and DVLOG(0) have the same effe
maniscalco
2015/05/18 18:56:05
Cool. As we discussed offline, the V in DVLOG sta
| |
52 << ObjectIdToString(*intersection.begin()) << " for " | 51 << ObjectIdToString(*intersection.begin()) << " for " << handler |
53 << handler << " when it's already registered for " | 52 << " when it's already registered for " << it->first; |
54 << it->first; | 53 return false; |
54 } | |
55 } | 55 } |
56 | 56 |
57 if (ids.empty()) { | 57 if (ids.empty()) { |
58 handler_to_ids_map_.erase(handler); | 58 handler_to_ids_map_.erase(handler); |
59 } else { | 59 } else { |
60 handler_to_ids_map_[handler] = ids; | 60 handler_to_ids_map_[handler] = ids; |
61 } | 61 } |
62 return true; | |
62 } | 63 } |
63 | 64 |
64 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { | 65 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { |
65 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
66 CHECK(handler); | 67 CHECK(handler); |
67 CHECK(handlers_.HasObserver(handler)); | 68 CHECK(handlers_.HasObserver(handler)); |
68 handlers_.RemoveObserver(handler); | 69 handlers_.RemoveObserver(handler); |
69 handler_to_ids_map_.erase(handler); | 70 handler_to_ids_map_.erase(handler); |
70 } | 71 } |
71 | 72 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
140 return handlers_.HasObserver(handler); | 141 return handlers_.HasObserver(handler); |
141 } | 142 } |
142 | 143 |
143 void InvalidatorRegistrar::DetachFromThreadForTest() { | 144 void InvalidatorRegistrar::DetachFromThreadForTest() { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
145 thread_checker_.DetachFromThread(); | 146 thread_checker_.DetachFromThread(); |
146 } | 147 } |
147 | 148 |
148 } // namespace syncer | 149 } // namespace syncer |
OLD | NEW |