| 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 #ifndef CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/sequenced_task_runner_helpers.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "chrome/browser/extensions/app_notification.h" | 17 #include "chrome/browser/extensions/app_notification.h" |
| 17 #include "chrome/browser/extensions/app_notification_storage.h" | 18 #include "chrome/browser/extensions/app_notification_storage.h" |
| 18 #include "chrome/browser/sync/api/sync_change.h" | 19 #include "chrome/browser/sync/api/sync_change.h" |
| 19 #include "chrome/browser/sync/api/syncable_service.h" | 20 #include "chrome/browser/sync/api/syncable_service.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 24 | 25 |
| 25 class PerfTimer; | 26 class PerfTimer; |
| 26 class Profile; | 27 class Profile; |
| 27 class SyncErrorFactory; | 28 class SyncErrorFactory; |
| 28 | 29 |
| 29 // This class keeps track of notifications for installed apps. | 30 // This class keeps track of notifications for installed apps. |
| 30 class AppNotificationManager | 31 class AppNotificationManager |
| 31 : public base::RefCountedThreadSafe< | 32 : public base::RefCountedThreadSafe< |
| 32 AppNotificationManager, | 33 AppNotificationManager, |
| 33 content::BrowserThread::DeleteOnUIThread>, | 34 content::BrowserThread::DeleteOnUIThread>, |
| 34 public content::NotificationObserver, | 35 public content::NotificationObserver, |
| 35 public SyncableService { | 36 public SyncableService { |
| 36 public: | 37 public: |
| 37 static const unsigned int kMaxNotificationPerApp; | 38 static const unsigned int kMaxNotificationPerApp; |
| 38 explicit AppNotificationManager(Profile* profile); | 39 explicit AppNotificationManager(Profile* profile); |
| 39 virtual ~AppNotificationManager(); | |
| 40 | 40 |
| 41 // Starts up the process of reading from persistent storage. | 41 // Starts up the process of reading from persistent storage. |
| 42 void Init(); | 42 void Init(); |
| 43 | 43 |
| 44 // Returns whether add was succcessful. | 44 // Returns whether add was succcessful. |
| 45 // Takes ownership of |item| in all cases. | 45 // Takes ownership of |item| in all cases. |
| 46 bool Add(AppNotification* item); | 46 bool Add(AppNotification* item); |
| 47 | 47 |
| 48 const AppNotificationList* GetAll(const std::string& extension_id) const; | 48 const AppNotificationList* GetAll(const std::string& extension_id) const; |
| 49 | 49 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 73 // Associate and merge sync data model with our data model. | 73 // Associate and merge sync data model with our data model. |
| 74 virtual SyncError MergeDataAndStartSyncing( | 74 virtual SyncError MergeDataAndStartSyncing( |
| 75 syncable::ModelType type, | 75 syncable::ModelType type, |
| 76 const SyncDataList& initial_sync_data, | 76 const SyncDataList& initial_sync_data, |
| 77 scoped_ptr<SyncChangeProcessor> sync_processor, | 77 scoped_ptr<SyncChangeProcessor> sync_processor, |
| 78 scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; | 78 scoped_ptr<SyncErrorFactory> sync_error_factory) OVERRIDE; |
| 79 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | 79 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 friend class AppNotificationManagerSyncTest; | 82 friend class AppNotificationManagerSyncTest; |
| 83 friend class base::DeleteHelper<AppNotificationManager>; |
| 84 friend struct content::BrowserThread::DeleteOnThread< |
| 85 content::BrowserThread::UI>; |
| 83 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 86 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 84 NotificationToSyncDataToNotification); | 87 NotificationToSyncDataToNotification); |
| 85 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 88 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 86 GetAllSyncDataNoLocal); | 89 GetAllSyncDataNoLocal); |
| 87 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 90 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 88 GetAllSyncDataSomeLocal); | 91 GetAllSyncDataSomeLocal); |
| 89 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 92 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 90 ModelAssocModelEmpty); | 93 ModelAssocModelEmpty); |
| 91 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 94 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 92 ModelAssocBothNonEmptyNoOverlap); | 95 ModelAssocBothNonEmptyNoOverlap); |
| 93 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 96 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 94 ModelAssocBothNonEmptySomeOverlap); | 97 ModelAssocBothNonEmptySomeOverlap); |
| 95 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 98 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 96 ModelAssocBothNonEmptyTitleMismatch); | 99 ModelAssocBothNonEmptyTitleMismatch); |
| 97 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 100 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 98 ModelAssocBothNonEmptyMatchesLocal); | 101 ModelAssocBothNonEmptyMatchesLocal); |
| 99 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 102 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 100 ProcessSyncChangesErrorModelAssocNotDone); | 103 ProcessSyncChangesErrorModelAssocNotDone); |
| 101 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 104 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 102 ProcessSyncChangesEmptyModel); | 105 ProcessSyncChangesEmptyModel); |
| 103 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 106 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 104 StopSyncing); | 107 StopSyncing); |
| 105 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, | 108 FRIEND_TEST_ALL_PREFIXES(AppNotificationManagerSyncTest, |
| 106 ClearAllGetsSynced); | 109 ClearAllGetsSynced); |
| 107 | 110 |
| 108 friend class base::RefCountedThreadSafe<AppNotificationManager>; | |
| 109 | |
| 110 // Maps extension id to a list of notifications for that extension. | 111 // Maps extension id to a list of notifications for that extension. |
| 111 typedef std::map<std::string, AppNotificationList> NotificationMap; | 112 typedef std::map<std::string, AppNotificationList> NotificationMap; |
| 112 | 113 |
| 114 virtual ~AppNotificationManager(); |
| 115 |
| 113 // Starts loading storage_ using |storage_path|. | 116 // Starts loading storage_ using |storage_path|. |
| 114 void LoadOnFileThread(const FilePath& storage_path); | 117 void LoadOnFileThread(const FilePath& storage_path); |
| 115 | 118 |
| 116 // Called on the UI thread to handle the loaded results from storage_. | 119 // Called on the UI thread to handle the loaded results from storage_. |
| 117 void HandleLoadResults(NotificationMap* map); | 120 void HandleLoadResults(NotificationMap* map); |
| 118 | 121 |
| 119 // Saves the contents of |list| to storage. | 122 // Saves the contents of |list| to storage. |
| 120 // Ownership of |list| is transferred here. | 123 // Ownership of |list| is transferred here. |
| 121 void SaveOnFileThread(const std::string& extension_id, | 124 void SaveOnFileThread(const std::string& extension_id, |
| 122 AppNotificationList* list); | 125 AppNotificationList* list); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Whether syncer changes are being processed right now. | 171 // Whether syncer changes are being processed right now. |
| 169 bool processing_syncer_changes_; | 172 bool processing_syncer_changes_; |
| 170 | 173 |
| 171 // Used for a histogram of load time. | 174 // Used for a histogram of load time. |
| 172 scoped_ptr<PerfTimer> load_timer_; | 175 scoped_ptr<PerfTimer> load_timer_; |
| 173 | 176 |
| 174 DISALLOW_COPY_AND_ASSIGN(AppNotificationManager); | 177 DISALLOW_COPY_AND_ASSIGN(AppNotificationManager); |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ | 180 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |