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

Side by Side Diff: chrome/browser/extensions/app_notification_manager.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 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/extensions/app_notification_manager.h" 5 #include "chrome/browser/extensions/app_notification_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 void AppNotificationManager::Observe( 173 void AppNotificationManager::Observe(
174 int type, 174 int type,
175 const content::NotificationSource& source, 175 const content::NotificationSource& source,
176 const content::NotificationDetails& details) { 176 const content::NotificationDetails& details) {
177 CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED); 177 CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED);
178 ClearAll(*content::Details<const std::string>(details).ptr()); 178 ClearAll(*content::Details<const std::string>(details).ptr());
179 } 179 }
180 180
181 syncer::SyncDataList AppNotificationManager::GetAllSyncData( 181 syncer::SyncDataList AppNotificationManager::GetAllSyncData(
182 syncable::ModelType type) const { 182 syncer::ModelType type) const {
183 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 183 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
184 DCHECK(loaded()); 184 DCHECK(loaded());
185 DCHECK_EQ(syncable::APP_NOTIFICATIONS, type); 185 DCHECK_EQ(syncer::APP_NOTIFICATIONS, type);
186 syncer::SyncDataList data; 186 syncer::SyncDataList data;
187 for (NotificationMap::const_iterator iter = notifications_->begin(); 187 for (NotificationMap::const_iterator iter = notifications_->begin();
188 iter != notifications_->end(); ++iter) { 188 iter != notifications_->end(); ++iter) {
189 189
190 // Skip local notifications since they should not be synced. 190 // Skip local notifications since they should not be synced.
191 const AppNotificationList list = (*iter).second; 191 const AppNotificationList list = (*iter).second;
192 for (AppNotificationList::const_iterator list_iter = list.begin(); 192 for (AppNotificationList::const_iterator list_iter = list.begin();
193 list_iter != list.end(); ++list_iter) { 193 list_iter != list.end(); ++list_iter) {
194 const AppNotification* notification = (*list_iter).get(); 194 const AppNotification* notification = (*list_iter).get();
195 if (notification->is_local()) { 195 if (notification->is_local()) {
(...skipping 16 matching lines...) Expand all
212 FROM_HERE, 212 FROM_HERE,
213 "Models not yet associated."); 213 "Models not yet associated.");
214 } 214 }
215 215
216 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); 216 AutoReset<bool> processing_changes(&processing_syncer_changes_, true);
217 217
218 syncer::SyncError error; 218 syncer::SyncError error;
219 for (syncer::SyncChangeList::const_iterator iter = change_list.begin(); 219 for (syncer::SyncChangeList::const_iterator iter = change_list.begin();
220 iter != change_list.end(); ++iter) { 220 iter != change_list.end(); ++iter) {
221 syncer::SyncData sync_data = iter->sync_data(); 221 syncer::SyncData sync_data = iter->sync_data();
222 DCHECK_EQ(syncable::APP_NOTIFICATIONS, sync_data.GetDataType()); 222 DCHECK_EQ(syncer::APP_NOTIFICATIONS, sync_data.GetDataType());
223 syncer::SyncChange::SyncChangeType change_type = iter->change_type(); 223 syncer::SyncChange::SyncChangeType change_type = iter->change_type();
224 224
225 scoped_ptr<AppNotification> new_notif(CreateNotificationFromSyncData( 225 scoped_ptr<AppNotification> new_notif(CreateNotificationFromSyncData(
226 sync_data)); 226 sync_data));
227 if (!new_notif.get()) { 227 if (!new_notif.get()) {
228 NOTREACHED() << "Failed to read notification."; 228 NOTREACHED() << "Failed to read notification.";
229 continue; 229 continue;
230 } 230 }
231 const AppNotification* existing_notif = GetNotification( 231 const AppNotification* existing_notif = GetNotification(
232 new_notif->extension_id(), new_notif->guid()); 232 new_notif->extension_id(), new_notif->guid());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 break; 277 break;
278 default: 278 default:
279 break; 279 break;
280 } 280 }
281 } 281 }
282 282
283 return error; 283 return error;
284 } 284 }
285 285
286 syncer::SyncError AppNotificationManager::MergeDataAndStartSyncing( 286 syncer::SyncError AppNotificationManager::MergeDataAndStartSyncing(
287 syncable::ModelType type, 287 syncer::ModelType type,
288 const syncer::SyncDataList& initial_sync_data, 288 const syncer::SyncDataList& initial_sync_data,
289 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 289 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
290 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { 290 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
291 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
292 // AppNotificationDataTypeController ensures that modei is fully should before 292 // AppNotificationDataTypeController ensures that modei is fully should before
293 // this method is called by waiting until the load notification is received 293 // this method is called by waiting until the load notification is received
294 // from AppNotificationManager. 294 // from AppNotificationManager.
295 DCHECK(loaded()); 295 DCHECK(loaded());
296 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); 296 DCHECK_EQ(type, syncer::APP_NOTIFICATIONS);
297 DCHECK(!sync_processor_.get()); 297 DCHECK(!sync_processor_.get());
298 DCHECK(sync_processor.get()); 298 DCHECK(sync_processor.get());
299 DCHECK(sync_error_factory.get()); 299 DCHECK(sync_error_factory.get());
300 sync_processor_ = sync_processor.Pass(); 300 sync_processor_ = sync_processor.Pass();
301 sync_error_factory_ = sync_error_factory.Pass(); 301 sync_error_factory_ = sync_error_factory.Pass();
302 302
303 // We may add, or remove notifications here, so ensure we don't step on 303 // We may add, or remove notifications here, so ensure we don't step on
304 // our own toes. 304 // our own toes.
305 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); 305 AutoReset<bool> processing_changes(&processing_syncer_changes_, true);
306 306
307 SyncDataMap local_data_map; 307 SyncDataMap local_data_map;
308 PopulateGuidToSyncDataMap(GetAllSyncData(syncable::APP_NOTIFICATIONS), 308 PopulateGuidToSyncDataMap(GetAllSyncData(syncer::APP_NOTIFICATIONS),
309 &local_data_map); 309 &local_data_map);
310 310
311 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin(); 311 for (syncer::SyncDataList::const_iterator iter = initial_sync_data.begin();
312 iter != initial_sync_data.end(); ++iter) { 312 iter != initial_sync_data.end(); ++iter) {
313 const syncer::SyncData& sync_data = *iter; 313 const syncer::SyncData& sync_data = *iter;
314 DCHECK_EQ(syncable::APP_NOTIFICATIONS, sync_data.GetDataType()); 314 DCHECK_EQ(syncer::APP_NOTIFICATIONS, sync_data.GetDataType());
315 scoped_ptr<AppNotification> sync_notif(CreateNotificationFromSyncData( 315 scoped_ptr<AppNotification> sync_notif(CreateNotificationFromSyncData(
316 sync_data)); 316 sync_data));
317 CHECK(sync_notif.get()); 317 CHECK(sync_notif.get());
318 const AppNotification* local_notif = GetNotification( 318 const AppNotification* local_notif = GetNotification(
319 sync_notif->extension_id(), sync_notif->guid()); 319 sync_notif->extension_id(), sync_notif->guid());
320 if (local_notif) { 320 if (local_notif) {
321 local_data_map.erase(sync_notif->guid()); 321 local_data_map.erase(sync_notif->guid());
322 // Local notification should always match with sync notification as 322 // Local notification should always match with sync notification as
323 // notifications are immutable. 323 // notifications are immutable.
324 if (local_notif->is_local() || !sync_notif->Equals(*local_notif)) { 324 if (local_notif->is_local() || !sync_notif->Equals(*local_notif)) {
(...skipping 16 matching lines...) Expand all
341 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, iter->second)); 341 syncer::SyncChange(syncer::SyncChange::ACTION_ADD, iter->second));
342 } 342 }
343 343
344 syncer::SyncError error; 344 syncer::SyncError error;
345 if (new_changes.size() > 0) 345 if (new_changes.size() > 0)
346 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 346 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
347 models_associated_ = !error.IsSet(); 347 models_associated_ = !error.IsSet();
348 return error; 348 return error;
349 } 349 }
350 350
351 void AppNotificationManager::StopSyncing(syncable::ModelType type) { 351 void AppNotificationManager::StopSyncing(syncer::ModelType type) {
352 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); 352 DCHECK_EQ(type, syncer::APP_NOTIFICATIONS);
353 models_associated_ = false; 353 models_associated_ = false;
354 sync_processor_.reset(); 354 sync_processor_.reset();
355 sync_error_factory_.reset(); 355 sync_error_factory_.reset();
356 } 356 }
357 357
358 AppNotificationManager::~AppNotificationManager() { 358 AppNotificationManager::~AppNotificationManager() {
359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
360 // Post a task to delete our storage on the file thread. 360 // Post a task to delete our storage on the file thread.
361 BrowserThread::DeleteSoon(BrowserThread::FILE, 361 BrowserThread::DeleteSoon(BrowserThread::FILE,
362 FROM_HERE, 362 FROM_HERE,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 AppNotification* notification = new AppNotification( 570 AppNotification* notification = new AppNotification(
571 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), 571 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()),
572 specifics.guid(), specifics.app_id(), 572 specifics.guid(), specifics.app_id(),
573 specifics.title(), specifics.body_text()); 573 specifics.title(), specifics.body_text());
574 if (specifics.has_link_text()) 574 if (specifics.has_link_text())
575 notification->set_link_text(specifics.link_text()); 575 notification->set_link_text(specifics.link_text());
576 if (specifics.has_link_url()) 576 if (specifics.has_link_url())
577 notification->set_link_url(GURL(specifics.link_url())); 577 notification->set_link_url(GURL(specifics.link_url()));
578 return notification; 578 return notification;
579 } 579 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698