Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "sync/notifier/invalidator_registrar.h" | 5 #include "sync/notifier/invalidator_registrar.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { | 59 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | 60 DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 CHECK(handler); | 61 CHECK(handler); |
| 62 CHECK(handlers_.HasObserver(handler)); | 62 CHECK(handlers_.HasObserver(handler)); |
| 63 handlers_.RemoveObserver(handler); | 63 handlers_.RemoveObserver(handler); |
| 64 } | 64 } |
| 65 | 65 |
| 66 ObjectIdSet InvalidatorRegistrar::GetRegisteredIds( | |
| 67 InvalidationHandler* handler) const { | |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 69 ObjectIdSet registered_ids; | |
| 70 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); | |
| 71 it != id_to_handler_map_.end(); ++it) { | |
| 72 if (it->second == handler) { | |
| 73 registered_ids.insert(it->first); | |
|
Nicolas Zea
2012/08/29 23:41:05
break after?
akalin
2012/08/30 22:20:38
no, it has to find all registered IDs
| |
| 74 } | |
| 75 } | |
| 76 return registered_ids; | |
| 77 } | |
| 78 | |
| 66 ObjectIdSet InvalidatorRegistrar::GetAllRegisteredIds() const { | 79 ObjectIdSet InvalidatorRegistrar::GetAllRegisteredIds() const { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 ObjectIdSet registered_ids; | 81 ObjectIdSet registered_ids; |
| 69 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); | 82 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); |
| 70 it != id_to_handler_map_.end(); ++it) { | 83 it != id_to_handler_map_.end(); ++it) { |
| 71 registered_ids.insert(it->first); | 84 registered_ids.insert(it->first); |
| 72 } | 85 } |
| 73 return registered_ids; | 86 return registered_ids; |
| 74 } | 87 } |
| 75 | 88 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, | 126 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, |
| 114 OnNotificationsDisabled(reason)); | 127 OnNotificationsDisabled(reason)); |
| 115 } | 128 } |
| 116 | 129 |
| 117 bool InvalidatorRegistrar::IsHandlerRegisteredForTest( | 130 bool InvalidatorRegistrar::IsHandlerRegisteredForTest( |
| 118 InvalidationHandler* handler) const { | 131 InvalidationHandler* handler) const { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 132 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 return handlers_.HasObserver(handler); | 133 return handlers_.HasObserver(handler); |
| 121 } | 134 } |
| 122 | 135 |
| 123 ObjectIdSet InvalidatorRegistrar::GetRegisteredIdsForTest( | |
| 124 InvalidationHandler* handler) const { | |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 126 ObjectIdSet registered_ids; | |
| 127 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); | |
| 128 it != id_to_handler_map_.end(); ++it) { | |
| 129 if (it->second == handler) { | |
| 130 registered_ids.insert(it->first); | |
| 131 } | |
| 132 } | |
| 133 return registered_ids; | |
| 134 } | |
| 135 | |
| 136 void InvalidatorRegistrar::DetachFromThreadForTest() { | 136 void InvalidatorRegistrar::DetachFromThreadForTest() { |
| 137 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
| 138 thread_checker_.DetachFromThread(); | 138 thread_checker_.DetachFromThread(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( | 141 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( |
| 142 const invalidation::ObjectId& id) { | 142 const invalidation::ObjectId& id) { |
| 143 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
| 144 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); | 144 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); |
| 145 return (it == id_to_handler_map_.end()) ? NULL : it->second; | 145 return (it == id_to_handler_map_.end()) ? NULL : it->second; |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace syncer | 148 } // namespace syncer |
| OLD | NEW |