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/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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 iter != sync_data.end(); ++iter) { | 59 iter != sync_data.end(); ++iter) { |
60 (*data_map)[iter->GetSpecifics().app_notification().guid()] = *iter; | 60 (*data_map)[iter->GetSpecifics().app_notification().guid()] = *iter; |
61 } | 61 } |
62 } | 62 } |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 const unsigned int AppNotificationManager::kMaxNotificationPerApp = 5; | 65 const unsigned int AppNotificationManager::kMaxNotificationPerApp = 5; |
66 | 66 |
67 AppNotificationManager::AppNotificationManager(Profile* profile) | 67 AppNotificationManager::AppNotificationManager(Profile* profile) |
68 : profile_(profile), | 68 : profile_(profile), |
69 sync_processor_(NULL), | |
70 models_associated_(false), | 69 models_associated_(false), |
71 processing_syncer_changes_(false) { | 70 processing_syncer_changes_(false) { |
72 registrar_.Add(this, | 71 registrar_.Add(this, |
73 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 72 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
74 content::Source<Profile>(profile_)); | 73 content::Source<Profile>(profile_)); |
75 } | 74 } |
76 | 75 |
77 AppNotificationManager::~AppNotificationManager() { | 76 AppNotificationManager::~AppNotificationManager() { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
79 // Post a task to delete our storage on the file thread. | 78 // Post a task to delete our storage on the file thread. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 break; | 375 break; |
377 } | 376 } |
378 } | 377 } |
379 | 378 |
380 return error; | 379 return error; |
381 } | 380 } |
382 | 381 |
383 SyncError AppNotificationManager::MergeDataAndStartSyncing( | 382 SyncError AppNotificationManager::MergeDataAndStartSyncing( |
384 syncable::ModelType type, | 383 syncable::ModelType type, |
385 const SyncDataList& initial_sync_data, | 384 const SyncDataList& initial_sync_data, |
386 SyncChangeProcessor* sync_processor) { | 385 scoped_ptr<SyncChangeProcessor> sync_processor) { |
387 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
388 // AppNotificationDataTypeController ensures that modei is fully should before | 387 // AppNotificationDataTypeController ensures that modei is fully should before |
389 // this method is called by waiting until the load notification is received | 388 // this method is called by waiting until the load notification is received |
390 // from AppNotificationManager. | 389 // from AppNotificationManager. |
391 DCHECK(loaded()); | 390 DCHECK(loaded()); |
392 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); | 391 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); |
393 DCHECK(!sync_processor_); | 392 DCHECK(!sync_processor_.get()); |
394 sync_processor_ = sync_processor; | 393 DCHECK(sync_processor.get()); |
| 394 sync_processor_ = sync_processor.Pass(); |
395 | 395 |
396 // We may add, or remove notifications here, so ensure we don't step on | 396 // We may add, or remove notifications here, so ensure we don't step on |
397 // our own toes. | 397 // our own toes. |
398 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); | 398 AutoReset<bool> processing_changes(&processing_syncer_changes_, true); |
399 | 399 |
400 SyncDataMap local_data_map; | 400 SyncDataMap local_data_map; |
401 PopulateGuidToSyncDataMap(GetAllSyncData(syncable::APP_NOTIFICATIONS), | 401 PopulateGuidToSyncDataMap(GetAllSyncData(syncable::APP_NOTIFICATIONS), |
402 &local_data_map); | 402 &local_data_map); |
403 | 403 |
404 for (SyncDataList::const_iterator iter = initial_sync_data.begin(); | 404 for (SyncDataList::const_iterator iter = initial_sync_data.begin(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 SyncError error; | 436 SyncError error; |
437 if (new_changes.size() > 0) | 437 if (new_changes.size() > 0) |
438 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 438 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
439 models_associated_ = !error.IsSet(); | 439 models_associated_ = !error.IsSet(); |
440 return error; | 440 return error; |
441 } | 441 } |
442 | 442 |
443 void AppNotificationManager::StopSyncing(syncable::ModelType type) { | 443 void AppNotificationManager::StopSyncing(syncable::ModelType type) { |
444 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); | 444 DCHECK_EQ(type, syncable::APP_NOTIFICATIONS); |
445 models_associated_ = false; | 445 models_associated_ = false; |
446 sync_processor_ = NULL; | 446 sync_processor_.reset(); |
447 } | 447 } |
448 | 448 |
449 void AppNotificationManager::SyncAddChange(const AppNotification& notif) { | 449 void AppNotificationManager::SyncAddChange(const AppNotification& notif) { |
450 // Skip if either: | 450 // Skip if either: |
451 // - Notification is marked as local. | 451 // - Notification is marked as local. |
452 // - Sync is not enabled by user. | 452 // - Sync is not enabled by user. |
453 // - Change is generated from within the manager. | 453 // - Change is generated from within the manager. |
454 if (notif.is_local() || !models_associated_ || processing_syncer_changes_) | 454 if (notif.is_local() || !models_associated_ || processing_syncer_changes_) |
455 return; | 455 return; |
456 | 456 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 AppNotification* notification = new AppNotification( | 560 AppNotification* notification = new AppNotification( |
561 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), | 561 false, base::Time::FromInternalValue(specifics.creation_timestamp_ms()), |
562 specifics.guid(), specifics.app_id(), | 562 specifics.guid(), specifics.app_id(), |
563 specifics.title(), specifics.body_text()); | 563 specifics.title(), specifics.body_text()); |
564 if (specifics.has_link_text()) | 564 if (specifics.has_link_text()) |
565 notification->set_link_text(specifics.link_text()); | 565 notification->set_link_text(specifics.link_text()); |
566 if (specifics.has_link_url()) | 566 if (specifics.has_link_url()) |
567 notification->set_link_url(GURL(specifics.link_url())); | 567 notification->set_link_url(GURL(specifics.link_url())); |
568 return notification; | 568 return notification; |
569 } | 569 } |
OLD | NEW |