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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
84 ObjectIdSet registered_ids; | 84 ObjectIdSet registered_ids; |
85 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); | 85 for (IdHandlerMap::const_iterator it = id_to_handler_map_.begin(); |
86 it != id_to_handler_map_.end(); ++it) { | 86 it != id_to_handler_map_.end(); ++it) { |
87 registered_ids.insert(it->first); | 87 registered_ids.insert(it->first); |
88 } | 88 } |
89 return registered_ids; | 89 return registered_ids; |
90 } | 90 } |
91 | 91 |
92 void InvalidatorRegistrar::DispatchInvalidationsToHandlers( | 92 void InvalidatorRegistrar::DispatchInvalidationsToHandlers( |
93 const ObjectIdInvalidationMap& invalidation_map, | 93 const ObjectIdInvalidationMap& invalidation_map) { |
94 IncomingInvalidationSource source) { | |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
96 // If we have no handlers, there's nothing to do. | 95 // If we have no handlers, there's nothing to do. |
97 if (!handlers_.might_have_observers()) { | 96 if (!handlers_.might_have_observers()) { |
98 return; | 97 return; |
99 } | 98 } |
100 | 99 |
101 typedef std::map<InvalidationHandler*, ObjectIdInvalidationMap> DispatchMap; | 100 typedef std::map<InvalidationHandler*, ObjectIdInvalidationMap> DispatchMap; |
102 DispatchMap dispatch_map; | 101 DispatchMap dispatch_map; |
103 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); | 102 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); |
104 it != invalidation_map.end(); ++it) { | 103 it != invalidation_map.end(); ++it) { |
105 InvalidationHandler* const handler = ObjectIdToHandler(it->first); | 104 InvalidationHandler* const handler = ObjectIdToHandler(it->first); |
106 // Filter out invalidations for IDs with no handler. | 105 // Filter out invalidations for IDs with no handler. |
107 if (handler) | 106 if (handler) |
108 dispatch_map[handler].insert(*it); | 107 dispatch_map[handler].insert(*it); |
109 } | 108 } |
110 | 109 |
111 // Emit invalidations only for handlers in |handlers_|. | 110 // Emit invalidations only for handlers in |handlers_|. |
112 ObserverListBase<InvalidationHandler>::Iterator it(handlers_); | 111 ObserverListBase<InvalidationHandler>::Iterator it(handlers_); |
113 InvalidationHandler* handler = NULL; | 112 InvalidationHandler* handler = NULL; |
114 while ((handler = it.GetNext()) != NULL) { | 113 while ((handler = it.GetNext()) != NULL) { |
115 DispatchMap::const_iterator dispatch_it = dispatch_map.find(handler); | 114 DispatchMap::const_iterator dispatch_it = dispatch_map.find(handler); |
116 if (dispatch_it != dispatch_map.end()) | 115 if (dispatch_it != dispatch_map.end()) |
117 handler->OnIncomingInvalidation(dispatch_it->second, source); | 116 handler->OnIncomingInvalidation(dispatch_it->second); |
118 } | 117 } |
119 } | 118 } |
120 | 119 |
121 void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { | 120 void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { |
122 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
123 DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); | 122 DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); |
124 state_ = state; | 123 state_ = state; |
125 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, | 124 FOR_EACH_OBSERVER(InvalidationHandler, handlers_, |
126 OnInvalidatorStateChange(state)); | 125 OnInvalidatorStateChange(state)); |
127 } | 126 } |
(...skipping 15 matching lines...) Expand all Loading... |
143 } | 142 } |
144 | 143 |
145 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( | 144 InvalidationHandler* InvalidatorRegistrar::ObjectIdToHandler( |
146 const invalidation::ObjectId& id) { | 145 const invalidation::ObjectId& id) { |
147 DCHECK(thread_checker_.CalledOnValidThread()); | 146 DCHECK(thread_checker_.CalledOnValidThread()); |
148 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); | 147 IdHandlerMap::const_iterator it = id_to_handler_map_.find(id); |
149 return (it == id_to_handler_map_.end()) ? NULL : it->second; | 148 return (it == id_to_handler_map_.end()) ? NULL : it->second; |
150 } | 149 } |
151 | 150 |
152 } // namespace syncer | 151 } // namespace syncer |
OLD | NEW |