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

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service.h

Issue 176823009: Show device information in chrome://gcm-internals page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
17 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
(...skipping 20 matching lines...) Expand all
39 class GCMProfileServiceTestConsumer; 40 class GCMProfileServiceTestConsumer;
40 41
41 // Acts as a bridge between GCM API and GCMClient layer. It is profile based. 42 // Acts as a bridge between GCM API and GCMClient layer. It is profile based.
42 class GCMProfileService : public BrowserContextKeyedService, 43 class GCMProfileService : public BrowserContextKeyedService,
43 public content::NotificationObserver { 44 public content::NotificationObserver {
44 public: 45 public:
45 typedef base::Callback<void(const std::string& registration_id, 46 typedef base::Callback<void(const std::string& registration_id,
46 GCMClient::Result result)> RegisterCallback; 47 GCMClient::Result result)> RegisterCallback;
47 typedef base::Callback<void(const std::string& message_id, 48 typedef base::Callback<void(const std::string& message_id,
48 GCMClient::Result result)> SendCallback; 49 GCMClient::Result result)> SendCallback;
50 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)>
51 RequestGCMStatisticsCallback;
49 52
53 // Any change made to this enum should have corresponding change in the
54 // GetGCMEnabledStateString(...) function.
50 enum GCMEnabledState { 55 enum GCMEnabledState {
51 // GCM is always enabled. GCMClient will always load and connect with GCM. 56 // GCM is always enabled. GCMClient will always load and connect with GCM.
52 ALWAYS_ENABLED, 57 ALWAYS_ENABLED,
53 // GCM is only enabled for apps. GCMClient will start to load and connect 58 // GCM is only enabled for apps. GCMClient will start to load and connect
54 // with GCM only when GCM API is used. 59 // with GCM only when GCM API is used.
55 ENABLED_FOR_APPS, 60 ENABLED_FOR_APPS,
56 // GCM is always disabled. GCMClient will never load and connect with GCM. 61 // GCM is always disabled. GCMClient will never load and connect with GCM.
57 ALWAYS_DISABLED 62 ALWAYS_DISABLED
58 }; 63 };
59 64
60 // For testing purpose. 65 // For testing purpose.
61 class TestingDelegate { 66 class TestingDelegate {
62 public: 67 public:
63 virtual GCMEventRouter* GetEventRouter() const = 0; 68 virtual GCMEventRouter* GetEventRouter() const = 0;
64 }; 69 };
65 70
66 // Returns the GCM enabled state. 71 // Returns the GCM enabled state.
67 static GCMEnabledState GetGCMEnabledState(Profile* profile); 72 static GCMEnabledState GetGCMEnabledState(Profile* profile);
68 73
74 // Returns text representation of a GCMEnabledState enum entry.
75 static std::string GetGCMEnabledStateString(GCMEnabledState state);
76
69 // Register profile-specific prefs for GCM. 77 // Register profile-specific prefs for GCM.
70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 78 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
71 79
72 explicit GCMProfileService(Profile* profile); 80 explicit GCMProfileService(Profile* profile);
73 virtual ~GCMProfileService(); 81 virtual ~GCMProfileService();
74 82
75 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory); 83 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory);
76 84
77 // Registers |sender_id| for an app. A registration ID will be returned by 85 // Registers |sender_id| for an app. A registration ID will be returned by
78 // the GCM server. 86 // the GCM server.
(...skipping 18 matching lines...) Expand all
97 const GCMClient::OutgoingMessage& message, 105 const GCMClient::OutgoingMessage& message,
98 SendCallback callback); 106 SendCallback callback);
99 107
100 // For testing purpose. 108 // For testing purpose.
101 GCMClient* GetGCMClientForTesting() const; 109 GCMClient* GetGCMClientForTesting() const;
102 110
103 void set_testing_delegate(TestingDelegate* testing_delegate) { 111 void set_testing_delegate(TestingDelegate* testing_delegate) {
104 testing_delegate_ = testing_delegate; 112 testing_delegate_ = testing_delegate;
105 } 113 }
106 114
115 // Returns true if the profile is signed in.
116 bool IsSignedIn() const;
117
118 // Returns true if the gcm client instance has been created.
119 bool IsGCMClientCreated() const;
120
121 // Returns true if the gcm client is ready.
122 bool IsGCMClientReady() const;
123
124 // Get GCM client internal states and statistics. If it has not been created
125 // then stats won't be modified.
126 void RequestGCMStatistics(RequestGCMStatisticsCallback callback);
127
107 private: 128 private:
108 friend class GCMProfileServiceTestConsumer; 129 friend class GCMProfileServiceTestConsumer;
109 130
110 class DelayedTaskController; 131 class DelayedTaskController;
111 class IOWorker; 132 class IOWorker;
112 133
113 struct RegistrationInfo { 134 struct RegistrationInfo {
114 RegistrationInfo(); 135 RegistrationInfo();
115 ~RegistrationInfo(); 136 ~RegistrationInfo();
116 bool IsValid() const; 137 bool IsValid() const;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void WriteRegisteredAppIDs(); 193 void WriteRegisteredAppIDs();
173 194
174 // Used to persist registration info into the app's state store. 195 // Used to persist registration info into the app's state store.
175 void DeleteRegistrationInfo(const std::string& app_id); 196 void DeleteRegistrationInfo(const std::string& app_id);
176 void WriteRegistrationInfo(const std::string& app_id); 197 void WriteRegistrationInfo(const std::string& app_id);
177 void ReadRegistrationInfo(const std::string& app_id); 198 void ReadRegistrationInfo(const std::string& app_id);
178 void ReadRegistrationInfoFinished(const std::string& app_id, 199 void ReadRegistrationInfoFinished(const std::string& app_id,
179 scoped_ptr<base::Value> value); 200 scoped_ptr<base::Value> value);
180 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, 201 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value,
181 RegistrationInfo* registration_info); 202 RegistrationInfo* registration_info);
203 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats);
182 204
183 // Returns the key used to identify the registration info saved into the 205 // Returns the key used to identify the registration info saved into the
184 // app's state store. Used for testing purpose. 206 // app's state store. Used for testing purpose.
185 static const char* GetPersistentRegisterKeyForTesting(); 207 static const char* GetPersistentRegisterKeyForTesting();
186 208
187 // The profile which owns this object. 209 // The profile which owns this object.
188 Profile* profile_; 210 Profile* profile_;
189 211
190 // Flag to indicate if GCMClient is ready. 212 // Flag to indicate if GCMClient is ready.
191 bool gcm_client_ready_; 213 bool gcm_client_ready_;
192 214
193 // The username of the signed-in profile. 215 // The username of the signed-in profile.
194 std::string username_; 216 std::string username_;
195 217
196 content::NotificationRegistrar registrar_; 218 content::NotificationRegistrar registrar_;
197 219
198 scoped_ptr<DelayedTaskController> delayed_task_controller_; 220 scoped_ptr<DelayedTaskController> delayed_task_controller_;
199 221
200 // For all the work occured in IO thread. 222 // For all the work occured in IO thread.
201 scoped_refptr<IOWorker> io_worker_; 223 scoped_refptr<IOWorker> io_worker_;
202 224
203 // Callback map (from app_id to callback) for Register. 225 // Callback map (from app_id to callback) for Register.
204 std::map<std::string, RegisterCallback> register_callbacks_; 226 std::map<std::string, RegisterCallback> register_callbacks_;
205 227
206 // Callback map (from <app_id, message_id> to callback) for Send. 228 // Callback map (from <app_id, message_id> to callback) for Send.
207 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; 229 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_;
208 230
231 // Callback for RequestGCMStatistics.
232 RequestGCMStatisticsCallback request_gcm_statistics_callback_;
233
209 // Map from app_id to registration info (sender ids & registration ID). 234 // Map from app_id to registration info (sender ids & registration ID).
210 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap; 235 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap;
211 RegistrationInfoMap registration_info_map_; 236 RegistrationInfoMap registration_info_map_;
212 237
213 // Event router to talk with JS API. 238 // Event router to talk with JS API.
214 #if !defined(OS_ANDROID) 239 #if !defined(OS_ANDROID)
215 scoped_ptr<GCMEventRouter> js_event_router_; 240 scoped_ptr<GCMEventRouter> js_event_router_;
216 #endif 241 #endif
217 242
218 // For testing purpose. 243 // For testing purpose.
219 TestingDelegate* testing_delegate_; 244 TestingDelegate* testing_delegate_;
220 245
221 // Used to pass a weak pointer to the IO worker. 246 // Used to pass a weak pointer to the IO worker.
222 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; 247 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_;
223 248
224 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); 249 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
225 }; 250 };
226 251
227 } // namespace gcm 252 } // namespace gcm
228 253
229 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 254 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698