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 "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 5 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 void InitializeOnSyncThread(); | 31 void InitializeOnSyncThread(); |
32 void CleanupOnSyncThread(); | 32 void CleanupOnSyncThread(); |
33 | 33 |
34 void RegisterHandler(syncer::InvalidationHandler* handler); | 34 void RegisterHandler(syncer::InvalidationHandler* handler); |
35 void UpdateRegisteredIds(syncer::InvalidationHandler* handler, | 35 void UpdateRegisteredIds(syncer::InvalidationHandler* handler, |
36 const syncer::ObjectIdSet& ids); | 36 const syncer::ObjectIdSet& ids); |
37 void UnregisterHandler(syncer::InvalidationHandler* handler); | 37 void UnregisterHandler(syncer::InvalidationHandler* handler); |
38 | 38 |
39 void EmitInvalidation( | 39 void EmitInvalidation( |
40 const syncer::ObjectIdStateMap& state_map, | 40 const syncer::ObjectIdInvalidationMap& invalidation_map, |
41 syncer::IncomingInvalidationSource invalidation_source); | 41 syncer::IncomingInvalidationSource invalidation_source); |
42 | 42 |
43 bool IsHandlerRegisteredForTest(syncer::InvalidationHandler* handler) const; | 43 bool IsHandlerRegisteredForTest(syncer::InvalidationHandler* handler) const; |
44 syncer::ObjectIdSet GetRegisteredIdsForTest( | 44 syncer::ObjectIdSet GetRegisteredIdsForTest( |
45 syncer::InvalidationHandler* handler) const; | 45 syncer::InvalidationHandler* handler) const; |
46 | 46 |
47 private: | 47 private: |
48 friend class base::RefCountedThreadSafe<Core>; | 48 friend class base::RefCountedThreadSafe<Core>; |
49 | 49 |
50 // Destroyed on the UI thread or on |sync_task_runner_|. | 50 // Destroyed on the UI thread or on |sync_task_runner_|. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 invalidator_registrar_->UpdateRegisteredIds(handler, ids); | 90 invalidator_registrar_->UpdateRegisteredIds(handler, ids); |
91 } | 91 } |
92 | 92 |
93 void ChromeSyncNotificationBridge::Core::UnregisterHandler( | 93 void ChromeSyncNotificationBridge::Core::UnregisterHandler( |
94 syncer::InvalidationHandler* handler) { | 94 syncer::InvalidationHandler* handler) { |
95 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 95 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
96 invalidator_registrar_->UnregisterHandler(handler); | 96 invalidator_registrar_->UnregisterHandler(handler); |
97 } | 97 } |
98 | 98 |
99 void ChromeSyncNotificationBridge::Core::EmitInvalidation( | 99 void ChromeSyncNotificationBridge::Core::EmitInvalidation( |
100 const syncer::ObjectIdStateMap& state_map, | 100 const syncer::ObjectIdInvalidationMap& invalidation_map, |
101 syncer::IncomingInvalidationSource invalidation_source) { | 101 syncer::IncomingInvalidationSource invalidation_source) { |
102 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 102 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
103 const syncer::ObjectIdStateMap& effective_state_map = | 103 const syncer::ObjectIdInvalidationMap& effective_invalidation_map = |
104 state_map.empty() ? | 104 invalidation_map.empty() ? |
105 ObjectIdSetToStateMap( | 105 ObjectIdSetToInvalidationMap( |
106 invalidator_registrar_->GetAllRegisteredIds(), std::string()) : | 106 invalidator_registrar_->GetAllRegisteredIds(), std::string()) : |
107 state_map; | 107 invalidation_map; |
108 | 108 |
109 invalidator_registrar_->DispatchInvalidationsToHandlers( | 109 invalidator_registrar_->DispatchInvalidationsToHandlers( |
110 effective_state_map, invalidation_source); | 110 effective_invalidation_map, invalidation_source); |
111 } | 111 } |
112 | 112 |
113 bool ChromeSyncNotificationBridge::Core::IsHandlerRegisteredForTest( | 113 bool ChromeSyncNotificationBridge::Core::IsHandlerRegisteredForTest( |
114 syncer::InvalidationHandler* handler) const { | 114 syncer::InvalidationHandler* handler) const { |
115 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 115 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
116 return invalidator_registrar_->IsHandlerRegisteredForTest(handler); | 116 return invalidator_registrar_->IsHandlerRegisteredForTest(handler); |
117 } | 117 } |
118 | 118 |
119 syncer::ObjectIdSet | 119 syncer::ObjectIdSet |
120 ChromeSyncNotificationBridge::Core::GetRegisteredIdsForTest( | 120 ChromeSyncNotificationBridge::Core::GetRegisteredIdsForTest( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 syncer::IncomingInvalidationSource invalidation_source; | 190 syncer::IncomingInvalidationSource invalidation_source; |
191 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { | 191 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { |
192 invalidation_source = syncer::LOCAL_INVALIDATION; | 192 invalidation_source = syncer::LOCAL_INVALIDATION; |
193 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) { | 193 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) { |
194 invalidation_source = syncer::REMOTE_INVALIDATION; | 194 invalidation_source = syncer::REMOTE_INVALIDATION; |
195 } else { | 195 } else { |
196 NOTREACHED() << "Unexpected invalidation type: " << type; | 196 NOTREACHED() << "Unexpected invalidation type: " << type; |
197 return; | 197 return; |
198 } | 198 } |
199 | 199 |
200 // TODO(akalin): Use ObjectIdStateMap here instead. We'll have to | 200 // TODO(akalin): Use ObjectIdInvalidationMap here instead. We'll have to |
201 // make sure all emitters of the relevant notifications also use | 201 // make sure all emitters of the relevant notifications also use |
202 // ObjectIdStateMap. | 202 // ObjectIdInvalidationMap. |
203 content::Details<const syncer::ModelTypeStateMap> | 203 content::Details<const syncer::ModelTypeInvalidationMap> |
204 state_details(details); | 204 state_details(details); |
205 const syncer::ModelTypeStateMap& state_map = *(state_details.ptr()); | 205 const syncer::ModelTypeInvalidationMap& invalidation_map = |
| 206 *(state_details.ptr()); |
206 if (!sync_task_runner_->PostTask( | 207 if (!sync_task_runner_->PostTask( |
207 FROM_HERE, | 208 FROM_HERE, |
208 base::Bind(&Core::EmitInvalidation, | 209 base::Bind(&Core::EmitInvalidation, |
209 core_, | 210 core_, |
210 ModelTypeStateMapToObjectIdStateMap(state_map), | 211 ModelTypeInvalidationMapToObjectIdInvalidationMap( |
| 212 invalidation_map), |
211 invalidation_source))) { | 213 invalidation_source))) { |
212 NOTREACHED(); | 214 NOTREACHED(); |
213 } | 215 } |
214 } | 216 } |
215 | 217 |
216 } // namespace browser_sync | 218 } // namespace browser_sync |
OLD | NEW |