| 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 << ObjectIdToString(insert_it->first) << " for " | 56 << ObjectIdToString(insert_it->first) << " for " |
| 57 << handler << " when it's already registered for " | 57 << handler << " when it's already registered for " |
| 58 << insert_it->second; | 58 << insert_it->second; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { | 62 void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 CHECK(handler); | 64 CHECK(handler); |
| 65 CHECK(handlers_.HasObserver(handler)); | 65 CHECK(handlers_.HasObserver(handler)); |
| 66 UpdateRegisteredIds(handler, ObjectIdSet()); |
| 66 handlers_.RemoveObserver(handler); | 67 handlers_.RemoveObserver(handler); |
| 67 } | 68 } |
| 68 | 69 |
| 69 ObjectIdSet InvalidatorRegistrar::GetRegisteredIds( | 70 ObjectIdSet InvalidatorRegistrar::GetRegisteredIds( |
| 70 InvalidationHandler* handler) const { | 71 InvalidationHandler* handler) const { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 ObjectIdSet registered_ids; | 73 ObjectIdSet registered_ids; |
| 73 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); | 74 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); |
| 74 it != id_to_handler_map_.end(); ++it) { | 75 it != id_to_handler_map_.end(); ++it) { |
| 75 if (it->second == handler) { | 76 if (it->second == handler) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 InvalidationHandler* handler = NULL; | 113 InvalidationHandler* handler = NULL; |
| 113 while ((handler = it.GetNext()) != NULL) { | 114 while ((handler = it.GetNext()) != NULL) { |
| 114 DispatchMap::const_iterator dispatch_it = dispatch_map.find(handler); | 115 DispatchMap::const_iterator dispatch_it = dispatch_map.find(handler); |
| 115 if (dispatch_it != dispatch_map.end()) | 116 if (dispatch_it != dispatch_map.end()) |
| 116 handler->OnIncomingInvalidation(dispatch_it->second); | 117 handler->OnIncomingInvalidation(dispatch_it->second); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { | 121 void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { |
| 121 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
| 122 DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); | 123 DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_) |
| 124 << " -> " << InvalidatorStateToString(state); |
| 123 state_ = state; | 125 state_ = state; |
| 124 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, | 126 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, |
| 125 OnInvalidatorStateChange(state)); | 127 OnInvalidatorStateChange(state)); |
| 126 } | 128 } |
| 127 | 129 |
| 128 InvalidatorState InvalidatorRegistrar::GetInvalidatorState() const { | 130 InvalidatorState InvalidatorRegistrar::GetInvalidatorState() const { |
| 129 DCHECK(thread_checker_.CalledOnValidThread()); | 131 DCHECK(thread_checker_.CalledOnValidThread()); |
| 130 return state_; | 132 return state_; |
| 131 } | 133 } |
| 132 | 134 |
| 133 bool InvalidatorRegistrar::IsHandlerRegisteredForTest( | 135 bool InvalidatorRegistrar::IsHandlerRegisteredForTest( |
| 134 InvalidationHandler* handler) const { | 136 InvalidationHandler* handler) const { |
| 135 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
| 136 return handlers_.HasObserver(handler); | 138 return handlers_.HasObserver(handler); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void InvalidatorRegistrar::DetachFromThreadForTest() { | 141 void InvalidatorRegistrar::DetachFromThreadForTest() { |
| 140 DCHECK(thread_checker_.CalledOnValidThread()); | 142 DCHECK(thread_checker_.CalledOnValidThread()); |
| 141 thread_checker_.DetachFromThread(); | 143 thread_checker_.DetachFromThread(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( | 146 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( |
| 145 const invalidation::ObjectId& id) { | 147 const invalidation::ObjectId& id) { |
| 146 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 147 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); | 149 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); |
| 148 return (it == id_to_handler_map_.end()) ? NULL : it->second; | 150 return (it == id_to_handler_map_.end()) ? NULL : it->second; |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace syncer | 153 } // namespace syncer |
| OLD | NEW |