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

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service.h

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: LGTM nits Created 6 years, 9 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 12 matching lines...) Expand all
23 23
24 namespace user_prefs { 24 namespace user_prefs {
25 class PrefRegistrySyncable; 25 class PrefRegistrySyncable;
26 } 26 }
27 27
28 namespace message_center { 28 namespace message_center {
29 struct Notifier; 29 struct Notifier;
30 } 30 }
31 31
32 namespace notifier { 32 namespace notifier {
33 class SyncedNotificationAppInfoTemp; 33 class SyncedNotificationAppInfo;
34 class SyncedNotificationAppInfoService;
34 35
35 // The name of our first synced notification service. 36 // The name of our first synced notification service.
36 // TODO(petewil): remove this hardcoding once we have the synced notification 37 // TODO(petewil): Remove this once we figure out how to do UMA for each sending
37 // signalling sync data type set up to provide this. 38 // service name without knowing the name in advance.
38 // crbug.com/248337
39 extern const char kFirstSyncedNotificationServiceId[]; 39 extern const char kFirstSyncedNotificationServiceId[];
40 extern const char kServiceEnabledOnce[]; 40 extern const char kServiceEnabledOnce[];
41 extern const char kSyncedNotificationFirstRun[]; 41 extern const char kSyncedNotificationFirstRun[];
42 extern const char kSyncedNotificationsWelcomeOrigin[]; 42 extern const char kSyncedNotificationsWelcomeOrigin[];
43 43
44 enum ChromeNotifierServiceActionType { 44 enum ChromeNotifierServiceActionType {
45 CHROME_NOTIFIER_SERVICE_ACTION_UNKNOWN, 45 CHROME_NOTIFIER_SERVICE_ACTION_UNKNOWN,
46 CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_ENABLED, 46 CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_ENABLED,
47 CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_DISABLED, 47 CHROME_NOTIFIER_SERVICE_ACTION_FIRST_SERVICE_DISABLED,
48 // NOTE: Add new action types only immediately above this line. Also, 48 // NOTE: Add new action types only immediately above this line. Also,
(...skipping 25 matching lines...) Expand all
74 syncer::ModelType type) const OVERRIDE; 74 syncer::ModelType type) const OVERRIDE;
75 virtual syncer::SyncError ProcessSyncChanges( 75 virtual syncer::SyncError ProcessSyncChanges(
76 const tracked_objects::Location& from_here, 76 const tracked_objects::Location& from_here,
77 const syncer::SyncChangeList& change_list) OVERRIDE; 77 const syncer::SyncChangeList& change_list) OVERRIDE;
78 78
79 // Convert from internal representation to SyncData representation. 79 // Convert from internal representation to SyncData representation.
80 static syncer::SyncData CreateSyncDataFromNotification( 80 static syncer::SyncData CreateSyncDataFromNotification(
81 const SyncedNotification& notification); 81 const SyncedNotification& notification);
82 82
83 // Convert from SyncData representation to internal representation. 83 // Convert from SyncData representation to internal representation.
84 static scoped_ptr<SyncedNotification> CreateNotificationFromSyncData( 84 scoped_ptr<SyncedNotification> CreateNotificationFromSyncData(
85 const syncer::SyncData& sync_data); 85 const syncer::SyncData& sync_data);
86 86
87 // Get a pointer to a notification. ChromeNotifierService owns this pointer. 87 // Get a pointer to a notification. ChromeNotifierService owns this pointer.
88 virtual notifier::SyncedNotification* FindNotificationById( 88 virtual notifier::SyncedNotification* FindNotificationById(
89 const std::string& notification_id); 89 const std::string& notification_id);
90 90
91 // Get the list of synced notification services and fill their meta data to 91 // Get the list of synced notification services and fill their meta data to
92 // |notifiers|. 92 // |notifiers|.
93 void GetSyncedNotificationServices( 93 void GetSyncedNotificationServices(
94 std::vector<message_center::Notifier*>* notifiers); 94 std::vector<message_center::Notifier*>* notifiers);
95 95
96 // Called when we dismiss a notification. This is virtual so that test 96 // Called when we dismiss a notification. This is virtual so that test
97 // subclasses can override it. 97 // subclasses can override it.
98 virtual void MarkNotificationAsRead(const std::string& id); 98 virtual void MarkNotificationAsRead(const std::string& id);
99 99
100 // Called when a notier is enabled or disabled. 100 // Called when a notier is enabled or disabled.
101 void OnSyncedNotificationServiceEnabled( 101 void OnSyncedNotificationServiceEnabled(
102 const std::string& notifier_id, 102 const std::string& notifier_id,
103 bool enabled); 103 bool enabled);
104 104
105 // When app ids are added or removed, unblock or remove associated messages.
106 void OnAddedAppIds(std::vector<std::string> added_app_ids);
107 void OnRemovedAppIds(std::vector<std::string> removed_app_ids);
108
105 // Register the preferences we use to save state. 109 // Register the preferences we use to save state.
106 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 110 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
107 111
108 Profile* profile() const { return profile_; } 112 Profile* profile() const { return profile_; }
109 113
114 // Find and retun the sending service Id for this notification.
115 std::string GetSendingServiceId(
116 const SyncedNotification* synced_notification);
117
110 // Functions for test. 118 // Functions for test.
111 void AddForTest(scoped_ptr<notifier::SyncedNotification> notification); 119 void AddForTest(scoped_ptr<notifier::SyncedNotification> notification);
112 120
121 void SetSyncedNotificationAppInfoServiceForTest(
122 SyncedNotificationAppInfoService* synced_notification_app_info_service);
123
113 // If we allow the tests to do bitmap fetching, they will attempt to fetch 124 // If we allow the tests to do bitmap fetching, they will attempt to fetch
114 // a URL from the web, which will fail. We can already test the majority 125 // a URL from the web, which will fail. We can already test the majority
115 // of what we want without also trying to fetch bitmaps. Other tests will 126 // of what we want without also trying to fetch bitmaps. Other tests will
116 // cover bitmap fetching. 127 // cover bitmap fetching.
117 static void set_avoid_bitmap_fetching_for_test(bool avoid) { 128 static void set_avoid_bitmap_fetching_for_test(bool avoid) {
118 avoid_bitmap_fetching_for_test_ = avoid; 129 avoid_bitmap_fetching_for_test_ = avoid;
119 } 130 }
120 131
121 // Initialize the preferences we use for the ChromeNotificationService. 132 // Initialize the preferences we use for the ChromeNotificationService.
122 void InitializePrefs(); 133 void InitializePrefs();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 std::set<std::string>* ids_field); 170 std::set<std::string>* ids_field);
160 171
161 // Called when our "first run" boolean pref has been changed. 172 // Called when our "first run" boolean pref has been changed.
162 void OnSyncedNotificationFirstRunBooleanPrefChanged(bool* new_value); 173 void OnSyncedNotificationFirstRunBooleanPrefChanged(bool* new_value);
163 174
164 // Convert our internal set of strings to a list value. 175 // Convert our internal set of strings to a list value.
165 // The second param is an outparam which the function fills in. 176 // The second param is an outparam which the function fills in.
166 void BuildServiceListValueInplace( 177 void BuildServiceListValueInplace(
167 std::set<std::string> services, base::ListValue* list_value); 178 std::set<std::string> services, base::ListValue* list_value);
168 179
169 SyncedNotificationAppInfoTemp* FindAppInfo(const std::string& app_id) const; 180 // Finds an app info by using the AppId
181 notifier::SyncedNotificationAppInfo* FindAppInfoByAppId(
182 const std::string& app_id) const;
170 183
184 // Builds a welcome notification for the listed sending service.
171 const Notification CreateWelcomeNotificationForService( 185 const Notification CreateWelcomeNotificationForService(
172 SyncedNotificationAppInfoTemp* app_info); 186 SyncedNotificationAppInfo* app_info);
173 187
174 // Preferences for storing which SyncedNotificationServices are enabled 188 // Preferences for storing which SyncedNotificationServices are enabled
175 StringListPrefMember enabled_sending_services_prefs_; 189 StringListPrefMember enabled_sending_services_prefs_;
176 StringListPrefMember initialized_sending_services_prefs_; 190 StringListPrefMember initialized_sending_services_prefs_;
177 191
178 // Preferences to avoid toasting on SyncedNotification first run. 192 // Preferences to avoid toasting on SyncedNotification first run.
179 BooleanPrefMember synced_notification_first_run_prefs_; 193 BooleanPrefMember synced_notification_first_run_prefs_;
180 194
181 // Back pointer to the owning profile. 195 // Back pointer to the owning profile.
182 Profile* const profile_; 196 Profile* const profile_;
183 NotificationUIManager* const notification_manager_; 197 NotificationUIManager* const notification_manager_;
184 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 198 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
185 std::set<std::string> enabled_sending_services_; 199 std::set<std::string> enabled_sending_services_;
186 std::set<std::string> initialized_sending_services_; 200 std::set<std::string> initialized_sending_services_;
187 bool synced_notification_first_run_; 201 bool synced_notification_first_run_;
188 static bool avoid_bitmap_fetching_for_test_; 202 static bool avoid_bitmap_fetching_for_test_;
189 base::ThreadChecker thread_checker_; 203 base::ThreadChecker thread_checker_;
204 // Unowned pointer to the App Info service. The lifetime is managed by the
205 // profile service, this service depends on the App Info service, so it should
206 // always be in scope whenever our service is active.
207 SyncedNotificationAppInfoService* synced_notification_app_info_service_;
190 208
191 ScopedVector<SyncedNotificationAppInfoTemp> app_info_data_;
192 // TODO(petewil): Consider whether a map would better suit our data. 209 // TODO(petewil): Consider whether a map would better suit our data.
193 // If there are many entries, lookup time may trump locality of reference. 210 // If there are many entries, lookup time may trump locality of reference.
194 ScopedVector<SyncedNotification> notification_data_; 211 ScopedVector<SyncedNotification> notification_data_;
195 212
196 friend class ChromeNotifierServiceTest; 213 friend class ChromeNotifierServiceTest;
197 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, ServiceEnabledTest); 214 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, ServiceEnabledTest);
198 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, 215 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest,
199 AddNewSendingServicesTest); 216 AddNewSendingServicesTest);
200 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, 217 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest,
201 CheckInitializedServicesTest); 218 CheckInitializedServicesTest);
202 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, 219 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest,
203 GetEnabledSendingServicesFromPreferencesTest); 220 GetEnabledSendingServicesFromPreferencesTest);
204 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, CheckFindAppInfo); 221 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, CheckFindAppInfo);
222 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, SetAddedAppIdsTest);
223 FRIEND_TEST_ALL_PREFIXES(ChromeNotifierServiceTest, SetRemovedAppIdsTest);
205 224
206 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierService); 225 DISALLOW_COPY_AND_ASSIGN(ChromeNotifierService);
207 }; 226 };
208 227
209 } // namespace notifier 228 } // namespace notifier
210 229
211 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_ 230 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_CHROME_NOTIFIER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698