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

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

Issue 10837214: Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test 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 19 matching lines...) Expand all
30 void InitializeOnSyncThread(); 30 void InitializeOnSyncThread();
31 void CleanupOnSyncThread(); 31 void CleanupOnSyncThread();
32 32
33 void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types); 33 void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types);
34 void RegisterHandler(syncer::SyncNotifierObserver* handler); 34 void RegisterHandler(syncer::SyncNotifierObserver* handler);
35 void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler, 35 void UpdateRegisteredIds(syncer::SyncNotifierObserver* handler,
36 const syncer::ObjectIdSet& ids); 36 const syncer::ObjectIdSet& ids);
37 void UnregisterHandler(syncer::SyncNotifierObserver* handler); 37 void UnregisterHandler(syncer::SyncNotifierObserver* handler);
38 38
39 void EmitNotification( 39 void EmitNotification(
40 const syncer::ModelTypePayloadMap& payload_map, 40 const syncer::ModelTypeStateMap& state_map,
41 syncer::IncomingNotificationSource notification_source); 41 syncer::IncomingNotificationSource notification_source);
42 42
43 private: 43 private:
44 friend class base::RefCountedThreadSafe<Core>; 44 friend class base::RefCountedThreadSafe<Core>;
45 45
46 // Destroyed on the UI thread or on |sync_task_runner_|. 46 // Destroyed on the UI thread or on |sync_task_runner_|.
47 ~Core(); 47 ~Core();
48 48
49 const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; 49 const scoped_refptr<base::SequencedTaskRunner> sync_task_runner_;
50 50
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 notifier_registrar_->UpdateRegisteredIds(handler, ids); 93 notifier_registrar_->UpdateRegisteredIds(handler, ids);
94 } 94 }
95 95
96 void ChromeSyncNotificationBridge::Core::UnregisterHandler( 96 void ChromeSyncNotificationBridge::Core::UnregisterHandler(
97 syncer::SyncNotifierObserver* handler) { 97 syncer::SyncNotifierObserver* handler) {
98 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 98 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
99 notifier_registrar_->UnregisterHandler(handler); 99 notifier_registrar_->UnregisterHandler(handler);
100 } 100 }
101 101
102 void ChromeSyncNotificationBridge::Core::EmitNotification( 102 void ChromeSyncNotificationBridge::Core::EmitNotification(
103 const syncer::ModelTypePayloadMap& payload_map, 103 const syncer::ModelTypeStateMap& state_map,
104 syncer::IncomingNotificationSource notification_source) { 104 syncer::IncomingNotificationSource notification_source) {
105 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); 105 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread());
106 const syncer::ModelTypePayloadMap& effective_payload_map = 106 const syncer::ModelTypeStateMap& effective_state_map =
107 payload_map.empty() ? 107 state_map.empty() ?
108 syncer::ModelTypePayloadMapFromEnumSet(enabled_types_, std::string()) : 108 syncer::ModelTypeSetToStateMap(enabled_types_, std::string()) :
109 payload_map; 109 state_map;
110 110
111 notifier_registrar_->DispatchInvalidationsToHandlers( 111 notifier_registrar_->DispatchInvalidationsToHandlers(
112 ModelTypePayloadMapToObjectIdPayloadMap(effective_payload_map), 112 ModelTypeStateMapToObjectIdStateMap(effective_state_map),
113 notification_source); 113 notification_source);
114 } 114 }
115 115
116 ChromeSyncNotificationBridge::ChromeSyncNotificationBridge( 116 ChromeSyncNotificationBridge::ChromeSyncNotificationBridge(
117 const Profile* profile, 117 const Profile* profile,
118 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner) 118 const scoped_refptr<base::SequencedTaskRunner>& sync_task_runner)
119 : sync_task_runner_(sync_task_runner), 119 : sync_task_runner_(sync_task_runner),
120 core_(new Core(sync_task_runner_)) { 120 core_(new Core(sync_task_runner_)) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
122 DCHECK(profile); 122 DCHECK(profile);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 syncer::IncomingNotificationSource notification_source; 174 syncer::IncomingNotificationSource notification_source;
175 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) { 175 if (type == chrome::NOTIFICATION_SYNC_REFRESH_LOCAL) {
176 notification_source = syncer::LOCAL_NOTIFICATION; 176 notification_source = syncer::LOCAL_NOTIFICATION;
177 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) { 177 } else if (type == chrome::NOTIFICATION_SYNC_REFRESH_REMOTE) {
178 notification_source = syncer::REMOTE_NOTIFICATION; 178 notification_source = syncer::REMOTE_NOTIFICATION;
179 } else { 179 } else {
180 NOTREACHED() << "Unexpected notification type: " << type; 180 NOTREACHED() << "Unexpected notification type: " << type;
181 return; 181 return;
182 } 182 }
183 183
184 content::Details<const syncer::ModelTypePayloadMap> 184 content::Details<const syncer::ModelTypeStateMap>
185 payload_details(details); 185 state_details(details);
186 const syncer::ModelTypePayloadMap& payload_map = *(payload_details.ptr()); 186 const syncer::ModelTypeStateMap& state_map = *(state_details.ptr());
187 if (!sync_task_runner_->PostTask( 187 if (!sync_task_runner_->PostTask(
188 FROM_HERE, 188 FROM_HERE,
189 base::Bind(&Core::EmitNotification, 189 base::Bind(&Core::EmitNotification,
190 core_, payload_map, notification_source))) { 190 core_, state_map, notification_source))) {
191 NOTREACHED(); 191 NOTREACHED();
192 } 192 }
193 } 193 }
194 194
195 } // namespace browser_sync 195 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698