OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ |
| 6 #define CHROME_BROWSER_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "chrome/browser/notifier/synced_notification.h" |
| 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 13 #include "sync/api/syncable_service.h" |
| 14 |
| 15 class Profile; |
| 16 class NotificationUIManager; |
| 17 |
| 18 namespace notifier { |
| 19 |
| 20 // The ChromeNotifierService holds notifications which represent the state of |
| 21 // delivered notifications for chrome. These are obtained from the sync service |
| 22 // and kept up to date. |
| 23 class ChromeNotifierService : public syncer::SyncableService, |
| 24 public ProfileKeyedService { |
| 25 |
| 26 public: |
| 27 ChromeNotifierService(Profile* profile, NotificationUIManager* manager); |
| 28 virtual ~ChromeNotifierService(); |
| 29 |
| 30 // Methods from ProfileKeyedService. |
| 31 virtual void Shutdown() OVERRIDE; |
| 32 |
| 33 // syncer::SyncableService implementation. |
| 34 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
| 35 syncer::ModelType type, |
| 36 const syncer::SyncDataList& initial_sync_data, |
| 37 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 38 scoped_ptr<syncer::SyncErrorFactory> error_handler) OVERRIDE; |
| 39 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; |
| 40 virtual syncer::SyncDataList GetAllSyncData( |
| 41 syncer::ModelType type) const OVERRIDE; |
| 42 virtual syncer::SyncError ProcessSyncChanges( |
| 43 const tracked_objects::Location& from_here, |
| 44 const syncer::SyncChangeList& change_list) OVERRIDE; |
| 45 |
| 46 // Convert from internal representation to SyncData representation. |
| 47 static const syncer::SyncData CreateSyncDataFromNotification( |
| 48 const SyncedNotification& notification); |
| 49 |
| 50 // Convert from SyncData representation to internal representation. |
| 51 static SyncedNotification* CreateNotificationFromSyncData( |
| 52 const syncer::SyncData& sync_data); |
| 53 |
| 54 // Add a notification to our list. This takes ownership of the pointer. |
| 55 void Add(scoped_ptr<notifier::SyncedNotification> notification); |
| 56 |
| 57 void Show(notifier::SyncedNotification* notification); |
| 58 |
| 59 // Get a pointer to a notification. ChromeNotifierService owns this pointer. |
| 60 // The caller must not free it. |
| 61 notifier::SyncedNotification* FindNotificationById(const std::string& id); |
| 62 |
| 63 private: |
| 64 // Back pointer to the owning profile. |
| 65 Profile* profile_; |
| 66 NotificationUIManager* notification_manager_; |
| 67 |
| 68 // TODO(petewil): consider whether a map would better suit our data. |
| 69 // If there are many entries, lookup time may trump locality of reference. |
| 70 ScopedVector<notifier::SyncedNotification> notification_data_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierService); |
| 73 }; |
| 74 |
| 75 } // namespace notifier |
| 76 |
| 77 #endif // CHROME_BROWSER_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ |
OLD | NEW |