| 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 LOG(ERROR) << "Duplicate registration: trying to register " |
| 52 << ObjectIdToString(*intersection.begin()) << " for " | 51 << ObjectIdToString(*intersection.begin()) << " for " |
| 53 << handler << " when it's already registered for " | 52 << handler << " when it's already registered for " |
| 54 << it->first; | 53 << it->first; |
| 54 return false; |
| 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 if (ids.empty()) { | 58 if (ids.empty()) { |
| 58 handler_to_ids_map_.erase(handler); | 59 handler_to_ids_map_.erase(handler); |
| 59 } else { | 60 } else { |
| 60 handler_to_ids_map_[handler] = ids; | 61 handler_to_ids_map_[handler] = ids; |
| 61 } | 62 } |
| 63 return true; |
| 62 } | 64 } |
| 63 | 65 |
| 64 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { | 66 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 67 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 CHECK(handler); | 68 CHECK(handler); |
| 67 CHECK(handlers_.HasObserver(handler)); | 69 CHECK(handlers_.HasObserver(handler)); |
| 68 handlers_.RemoveObserver(handler); | 70 handlers_.RemoveObserver(handler); |
| 69 handler_to_ids_map_.erase(handler); | 71 handler_to_ids_map_.erase(handler); |
| 70 } | 72 } |
| 71 | 73 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
| 140 return handlers_.HasObserver(handler); | 142 return handlers_.HasObserver(handler); |
| 141 } | 143 } |
| 142 | 144 |
| 143 void InvalidatorRegistrar::DetachFromThreadForTest() { | 145 void InvalidatorRegistrar::DetachFromThreadForTest() { |
| 144 DCHECK(thread_checker_.CalledOnValidThread()); | 146 DCHECK(thread_checker_.CalledOnValidThread()); |
| 145 thread_checker_.DetachFromThread(); | 147 thread_checker_.DetachFromThread(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 } // namespace syncer | 150 } // namespace syncer |
| OLD | NEW |