Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "chrome/browser/extensions/app_notification.h" | 16 #include "chrome/browser/extensions/app_notification.h" |
| 17 #include "chrome/browser/extensions/app_notification_storage.h" | 17 #include "chrome/browser/extensions/app_notification_storage.h" |
| 18 #include "chrome/browser/sync/api/sync_change.h" | 18 #include "chrome/browser/sync/api/sync_change.h" |
| 19 #include "chrome/browser/sync/api/syncable_service.h" | 19 #include "chrome/browser/sync/api/syncable_service.h" |
| 20 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 | 23 |
| 24 namespace notification_manager_constants { | |
| 25 static const unsigned int kMaxNotificationPerApp = 5; | |
|
asargent_no_longer_on_chrome
2011/11/17 23:40:14
nit: We typically use int's instead of unsigned in
elvin
2011/11/18 00:10:18
Done, kept it unsigned as size() is unsigned?
On 2
| |
| 26 } | |
| 27 | |
| 24 class Profile; | 28 class Profile; |
| 25 | 29 |
| 26 // This class keeps track of notifications for installed apps. | 30 // This class keeps track of notifications for installed apps. |
| 27 class AppNotificationManager | 31 class AppNotificationManager |
| 28 : public base::RefCountedThreadSafe<AppNotificationManager>, | 32 : public base::RefCountedThreadSafe<AppNotificationManager>, |
| 29 public content::NotificationObserver, | 33 public content::NotificationObserver, |
| 30 public SyncableService { | 34 public SyncableService { |
| 31 public: | 35 public: |
| 32 explicit AppNotificationManager(Profile* profile); | 36 explicit AppNotificationManager(Profile* profile); |
| 33 virtual ~AppNotificationManager(); | 37 virtual ~AppNotificationManager(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 void Remove(const std::string& extension_id, const std::string& guid); | 127 void Remove(const std::string& extension_id, const std::string& guid); |
| 124 | 128 |
| 125 // Returns the notification for the given |extension_id| and |guid|, | 129 // Returns the notification for the given |extension_id| and |guid|, |
| 126 // NULL if no such notification exists. | 130 // NULL if no such notification exists. |
| 127 const AppNotification* GetNotification(const std::string& extension_id, | 131 const AppNotification* GetNotification(const std::string& extension_id, |
| 128 const std::string& guid); | 132 const std::string& guid); |
| 129 | 133 |
| 130 // Sends a change to syncer to add the given notification. | 134 // Sends a change to syncer to add the given notification. |
| 131 void SyncAddChange(const AppNotification& notif); | 135 void SyncAddChange(const AppNotification& notif); |
| 132 | 136 |
| 137 // Sends a change to syncer to remove the given notification. | |
| 138 void SyncRemoveChange(const AppNotification& notif); | |
| 139 | |
| 133 // Sends changes to syncer to remove all notifications in the given list. | 140 // Sends changes to syncer to remove all notifications in the given list. |
| 134 void SyncClearAllChange(const AppNotificationList& list); | 141 void SyncClearAllChange(const AppNotificationList& list); |
| 135 | 142 |
| 136 // Converters from AppNotification to SyncData and vice versa. | 143 // Converters from AppNotification to SyncData and vice versa. |
| 137 static SyncData CreateSyncDataFromNotification( | 144 static SyncData CreateSyncDataFromNotification( |
| 138 const AppNotification& notification); | 145 const AppNotification& notification); |
| 139 static AppNotification* CreateNotificationFromSyncData( | 146 static AppNotification* CreateNotificationFromSyncData( |
| 140 const SyncData& sync_data); | 147 const SyncData& sync_data); |
| 141 | 148 |
| 142 Profile* profile_; | 149 Profile* profile_; |
| 143 content::NotificationRegistrar registrar_; | 150 content::NotificationRegistrar registrar_; |
| 144 scoped_ptr<NotificationMap> notifications_; | 151 scoped_ptr<NotificationMap> notifications_; |
| 145 | 152 |
| 146 // This should only be used on the FILE thread. | 153 // This should only be used on the FILE thread. |
| 147 scoped_ptr<AppNotificationStorage> storage_; | 154 scoped_ptr<AppNotificationStorage> storage_; |
| 148 | 155 |
| 149 // Sync change processor we use to push all our changes. | 156 // Sync change processor we use to push all our changes. |
| 150 SyncChangeProcessor* sync_processor_; | 157 SyncChangeProcessor* sync_processor_; |
| 151 // Whether the sync model is associated with the local model. | 158 // Whether the sync model is associated with the local model. |
| 152 // In other words, whether we are ready to apply sync changes. | 159 // In other words, whether we are ready to apply sync changes. |
| 153 bool models_associated_; | 160 bool models_associated_; |
| 154 // Whether syncer changes are being processed right now. | 161 // Whether syncer changes are being processed right now. |
| 155 bool processing_syncer_changes_; | 162 bool processing_syncer_changes_; |
| 156 | 163 |
| 157 DISALLOW_COPY_AND_ASSIGN(AppNotificationManager); | 164 DISALLOW_COPY_AND_ASSIGN(AppNotificationManager); |
| 158 }; | 165 }; |
| 159 | 166 |
| 160 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ | 167 #endif // CHROME_BROWSER_EXTENSIONS_APP_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |