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