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

Side by Side Diff: chrome/browser/notifications/sync_notifier/synced_notification_app_info_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: another windows fix 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SYNCED_NOTIFICATION_APP_INFO_ SERVICE_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_ SERVICE_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_ SERVICE_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_INFO_ SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h" 14 #include "chrome/browser/notifications/sync_notifier/synced_notification_app_inf o.h"
15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 15 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
16 #include "sync/api/syncable_service.h" 16 #include "sync/api/syncable_service.h"
17 17
18 class NotificationUIManager; 18 class NotificationUIManager;
19 class Profile; 19 class Profile;
20 20
21 namespace sync_pb { 21 namespace sync_pb {
22 class SyncedNotificationAppInfo; 22 class SyncedNotificationAppInfo;
23 } // namespace sync_pb 23 } // namespace sync_pb
24 24
25 namespace notifier { 25 namespace notifier {
26 26
27 struct SyncedNotificationSendingServiceSettingsData {
dewittj 2014/03/25 22:31:14 nit: class comment
Pete Williamson 2014/03/26 18:12:55 Done.
28 SyncedNotificationSendingServiceSettingsData(
29 std::string settings_display_name,
30 gfx::Image settings_icon,
31 message_center::NotifierId notifier_id);
32 std::string settings_display_name;
33 gfx::Image settings_icon;
34 message_center::NotifierId notifier_id;
35 };
36
37
38 class ChromeNotifierService;
39
27 // The SyncedNotificationAppInfoService contains and syncs AppInfo protobufs 40 // The SyncedNotificationAppInfoService contains and syncs AppInfo protobufs
28 // from the server with metadata about the services sending synced 41 // from the server with metadata about the services sending synced
29 // notifications. 42 // notifications.
30 class SyncedNotificationAppInfoService : public syncer::SyncableService, 43 class SyncedNotificationAppInfoService : public syncer::SyncableService,
31 public BrowserContextKeyedService { 44 public BrowserContextKeyedService {
32 public: 45 public:
33 explicit SyncedNotificationAppInfoService(Profile* profile); 46 explicit SyncedNotificationAppInfoService(Profile* profile);
34 virtual ~SyncedNotificationAppInfoService(); 47 virtual ~SyncedNotificationAppInfoService();
35 48
36 // Methods from BrowserContextKeyedService. 49 // Methods from BrowserContextKeyedService.
(...skipping 21 matching lines...) Expand all
58 const OVERRIDE; 71 const OVERRIDE;
59 72
60 // Handles the Add and Update cases. 73 // Handles the Add and Update cases.
61 void ProcessIncomingAppInfoProtobuf( 74 void ProcessIncomingAppInfoProtobuf(
62 const sync_pb::SyncedNotificationAppInfo& app_info); 75 const sync_pb::SyncedNotificationAppInfo& app_info);
63 76
64 // Handles the Removed case. 77 // Handles the Removed case.
65 void ProcessRemovedAppInfoProtobuf( 78 void ProcessRemovedAppInfoProtobuf(
66 const sync_pb::SyncedNotificationAppInfo& app_info); 79 const sync_pb::SyncedNotificationAppInfo& app_info);
67 80
81 // When the bitmaps are all ready, tell ChromeNotifierService about changes.
82 virtual void OnBitmapFetchesDone(std::vector<std::string> added_app_ids,
83 std::vector<std::string> removed_app_ids);
84
68 // Convert the protobuf to our internal format. 85 // Convert the protobuf to our internal format.
69 static scoped_ptr<SyncedNotificationAppInfo> 86 scoped_ptr<SyncedNotificationAppInfo>
70 CreateSyncedNotificationAppInfoFromProtobuf( 87 CreateSyncedNotificationAppInfoFromProtobuf(
71 const sync_pb::SyncedNotificationAppInfo& app_info); 88 const sync_pb::SyncedNotificationAppInfo& app_info);
72 89
90 // Get the app info that contains this sending service name.
91 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName(
92 const std::string& name);
93
94 // Get the app info that contains this app id.
95 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByAppId(
96 const std::string& app_id);
97
98 // Lookup the sending service name for a given app id.
99 std::string FindSendingServiceNameFromAppId(const std::string app_id);
100
101 // Return a list of all sending service names.
102 std::vector<SyncedNotificationSendingServiceSettingsData>
103 GetAllSendingServiceSettingsData();
104
105 void set_chrome_notifier_service(ChromeNotifierService* notifier) {
106 chrome_notifier_service_ = notifier;
107 }
108
73 // Functions for test. 109 // Functions for test.
74 void AddForTest( 110 void AddForTest(
75 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) { 111 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info) {
76 Add(sending_service_info.Pass()); 112 Add(sending_service_info.Pass());
77 } 113 }
78 114
115 // If we allow the tests to do bitmap fetching, they will attempt to fetch
116 // a URL from the web, which will fail. We can already test the majority
117 // of what we want without also trying to fetch bitmaps. Other tests will
118 // cover bitmap fetching.
119 static void set_avoid_bitmap_fetching_for_test(bool avoid) {
120 avoid_bitmap_fetching_for_test_ = avoid;
121 }
122
79 private: 123 private:
80 // Add an app_info object to our list. This takes ownership of the pointer. 124 // Add an app_info object to our list. This takes ownership of the pointer.
81 void Add( 125 void Add(
82 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info); 126 scoped_ptr<notifier::SyncedNotificationAppInfo> sending_service_info);
83 127
84 // Get the app info that contains this ID.
85 SyncedNotificationAppInfo* FindSyncedNotificationAppInfoByName(
86 const std::string& name);
87
88 // Remove this app info. 128 // Remove this app info.
89 void FreeSyncedNotificationAppInfoByName(const std::string& name); 129 void FreeSyncedNotificationAppInfoByName(const std::string& name);
90 130
91 size_t sending_service_infos_size() { return sending_service_infos_.size(); } 131 size_t sending_service_infos_size() { return sending_service_infos_.size(); }
92 132
93 // Back pointer to the owning profile. 133 // Back pointer to the owning profile.
94 Profile* const profile_; 134 Profile* const profile_;
95 135
96 // Debug testing member for checking thread is as expected. 136 // Debug testing member for checking thread is as expected.
97 base::ThreadChecker thread_checker_; 137 base::ThreadChecker thread_checker_;
98 138
99 // Member list of AppInfo objects. 139 // Member list of AppInfo objects.
100 ScopedVector<notifier::SyncedNotificationAppInfo> sending_service_infos_; 140 ScopedVector<notifier::SyncedNotificationAppInfo> sending_service_infos_;
101 141
102 // Cache of the sync info. 142 // Cache of the sync info.
103 syncer::SyncData sync_data_; 143 syncer::SyncData sync_data_;
104 144
145 // Don't let unit tests try to hit the network.
146 static bool avoid_bitmap_fetching_for_test_;
147
148 // Pointer to the ChromeNotifierService. Its lifetime is controlled by the
149 // ChromeNotifierService itself, which will zero out the pointer when it is
150 // destroyed.
151 ChromeNotifierService* chrome_notifier_service_;
152
105 friend class SyncedNotificationAppInfoServiceTest; 153 friend class SyncedNotificationAppInfoServiceTest;
106 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 154 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
107 MergeDataAndStartSyncingTest); 155 MergeDataAndStartSyncingTest);
108 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 156 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
109 ProcessSyncChangesEmptyModel); 157 ProcessSyncChangesEmptyModel);
110 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 158 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
111 ProcessSyncChangesNonEmptyModel); 159 ProcessSyncChangesNonEmptyModel);
112 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 160 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
113 FindSyncedNotificationAppInfoByNameTest); 161 FindSyncedNotificationAppInfoByNameTest);
114 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 162 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
163 FindSyncedNotificationAppInfoByNameTestTest);
164 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
115 FreeSyncedNotificationAppInfoByNameTest); 165 FreeSyncedNotificationAppInfoByNameTest);
116 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 166 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
117 CreateSyncedNotificationAppInfoFromProtobufTest); 167 CreateSyncedNotificationAppInfoFromProtobufTest);
118 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 168 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
119 ProcessIncomingAppInfoProtobufAddTest); 169 ProcessIncomingAppInfoProtobufAddTest);
120 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 170 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
121 ProcessIncomingAppInfoProtobufUpdateTest); 171 ProcessIncomingAppInfoProtobufUpdateTest);
122 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest, 172 FRIEND_TEST_ALL_PREFIXES(SyncedNotificationAppInfoServiceTest,
123 ProcessRemovedAppInfoProtobufTest); 173 ProcessRemovedAppInfoProtobufTest);
124 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationAppInfoService); 174 DISALLOW_COPY_AND_ASSIGN(SyncedNotificationAppInfoService);
125 }; 175 };
126 176
127 } // namespace notifier 177 } // namespace notifier
128 178
129 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_IN FO_SERVICE_H_ 179 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_SYNCED_NOTIFICATION_APP_IN FO_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698