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