Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: chrome/browser/sync/glue/chrome_sync_notification_bridge.cc

Issue 10916131: [Invalidations] Add GetInvalidatorState() to Invalidator{,Frontend} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 // All member functions below must be called on the sync task runner. 29 // All member functions below must be called on the sync task runner.
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 EmitNotification( 39 void EmitInvalidation(
40 const syncer::ObjectIdStateMap& state_map, 40 const syncer::ObjectIdStateMap& state_map,
41 syncer::IncomingNotificationSource notification_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_|.
51 ~Core(); 51 ~Core();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 89 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
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::EmitNotification( 99 void ChromeSyncNotificationBridge::Core::EmitInvalidation(
100 const syncer::ObjectIdStateMap& state_map, 100 const syncer::ObjectIdStateMap& state_map,
101 syncer::IncomingNotificationSource notification_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::ObjectIdStateMap& effective_state_map =
104 state_map.empty() ? 104 state_map.empty() ?
105 ObjectIdSetToStateMap( 105 ObjectIdSetToStateMap(
106 invalidator_registrar_->GetAllRegisteredIds(), std::string()) : 106 invalidator_registrar_->GetAllRegisteredIds(), std::string()) :
107 state_map; 107 state_map;
108 108
109 invalidator_registrar_->DispatchInvalidationsToHandlers( 109 invalidator_registrar_->DispatchInvalidationsToHandlers(
110 effective_state_map, notification_source); 110 effective_state_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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 180 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
181 return core_->GetRegisteredIdsForTest(handler); 181 return core_->GetRegisteredIdsForTest(handler);
182 } 182 }
183 183
184 void ChromeSyncNotificationBridge::Observe( 184 void ChromeSyncNotificationBridge::Observe(
185 int type, 185 int type,
186 const content::NotificationSource& source, 186 const content::NotificationSource& source,
187 const content::NotificationDetails& details) { 187 const content::NotificationDetails& details) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
189 189
190 syncer::IncomingNotificationSource notification_source; 190 syncer::IncomingInvalidationSource invalidation_source;
191 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { 191 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) {
192 notification_source = syncer::LOCAL_NOTIFICATION; 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 notification_source = syncer::REMOTE_NOTIFICATION; 194 invalidation_source = syncer::REMOTE_INVALIDATION;
195 } else { 195 } else {
196 NOTREACHED() << "Unexpected notification 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 ObjectIdStateMap 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 // ObjectIdStateMap.
203 content::Details<const syncer::ModelTypeStateMap> 203 content::Details<const syncer::ModelTypeStateMap>
204 state_details(details); 204 state_details(details);
205 const syncer::ModelTypeStateMap& state_map = *(state_details.ptr()); 205 const syncer::ModelTypeStateMap& state_map = *(state_details.ptr());
206 if (!sync_task_runner_->PostTask( 206 if (!sync_task_runner_->PostTask(
207 FROM_HERE, 207 FROM_HERE,
208 base::Bind(&Core::EmitNotification, 208 base::Bind(&Core::EmitInvalidation,
209 core_, 209 core_,
210 ModelTypeStateMapToObjectIdStateMap(state_map), 210 ModelTypeStateMapToObjectIdStateMap(state_map),
211 notification_source))) { 211 invalidation_source))) {
212 NOTREACHED(); 212 NOTREACHED();
213 } 213 }
214 } 214 }
215 215
216 } // namespace browser_sync 216 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698