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

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: Display android id as well. 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 is ready.
119 bool IsGCMClientReady() const;
120
121 // Get GCM client internal states and statistics. If it has not been created
122 // then stats won't be modified.
123 void RequestGCMStatistics(RequestGCMStatisticsCallback callback);
124
107 private: 125 private:
108 friend class GCMProfileServiceTestConsumer; 126 friend class GCMProfileServiceTestConsumer;
109 127
110 class DelayedTaskController; 128 class DelayedTaskController;
111 class IOWorker; 129 class IOWorker;
112 130
113 struct RegistrationInfo { 131 struct RegistrationInfo {
114 RegistrationInfo(); 132 RegistrationInfo();
115 ~RegistrationInfo(); 133 ~RegistrationInfo();
116 bool IsValid() const; 134 bool IsValid() const;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void WriteRegisteredAppIDs(); 190 void WriteRegisteredAppIDs();
173 191
174 // Used to persist registration info into the app's state store. 192 // Used to persist registration info into the app's state store.
175 void DeleteRegistrationInfo(const std::string& app_id); 193 void DeleteRegistrationInfo(const std::string& app_id);
176 void WriteRegistrationInfo(const std::string& app_id); 194 void WriteRegistrationInfo(const std::string& app_id);
177 void ReadRegistrationInfo(const std::string& app_id); 195 void ReadRegistrationInfo(const std::string& app_id);
178 void ReadRegistrationInfoFinished(const std::string& app_id, 196 void ReadRegistrationInfoFinished(const std::string& app_id,
179 scoped_ptr<base::Value> value); 197 scoped_ptr<base::Value> value);
180 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, 198 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value,
181 RegistrationInfo* registration_info); 199 RegistrationInfo* registration_info);
200 void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats);
182 201
183 // Returns the key used to identify the registration info saved into the 202 // Returns the key used to identify the registration info saved into the
184 // app's state store. Used for testing purpose. 203 // app's state store. Used for testing purpose.
185 static const char* GetPersistentRegisterKeyForTesting(); 204 static const char* GetPersistentRegisterKeyForTesting();
186 205
187 // The profile which owns this object. 206 // The profile which owns this object.
188 Profile* profile_; 207 Profile* profile_;
189 208
190 // Flag to indicate if GCMClient is ready. 209 // Flag to indicate if GCMClient is ready.
191 bool gcm_client_ready_; 210 bool gcm_client_ready_;
192 211
193 // The username of the signed-in profile. 212 // The username of the signed-in profile.
194 std::string username_; 213 std::string username_;
195 214
196 content::NotificationRegistrar registrar_; 215 content::NotificationRegistrar registrar_;
197 216
198 scoped_ptr<DelayedTaskController> delayed_task_controller_; 217 scoped_ptr<DelayedTaskController> delayed_task_controller_;
199 218
200 // For all the work occured in IO thread. 219 // For all the work occured in IO thread.
201 scoped_refptr<IOWorker> io_worker_; 220 scoped_refptr<IOWorker> io_worker_;
202 221
203 // Callback map (from app_id to callback) for Register. 222 // Callback map (from app_id to callback) for Register.
204 std::map<std::string, RegisterCallback> register_callbacks_; 223 std::map<std::string, RegisterCallback> register_callbacks_;
205 224
206 // Callback map (from <app_id, message_id> to callback) for Send. 225 // Callback map (from <app_id, message_id> to callback) for Send.
207 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_; 226 std::map<std::pair<std::string, std::string>, SendCallback> send_callbacks_;
208 227
228 // Callback for RequestGCMStatistics.
229 RequestGCMStatisticsCallback request_gcm_statistics_callback_;
230
209 // Map from app_id to registration info (sender ids & registration ID). 231 // Map from app_id to registration info (sender ids & registration ID).
210 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap; 232 typedef std::map<std::string, RegistrationInfo> RegistrationInfoMap;
211 RegistrationInfoMap registration_info_map_; 233 RegistrationInfoMap registration_info_map_;
212 234
213 // Event router to talk with JS API. 235 // Event router to talk with JS API.
214 #if !defined(OS_ANDROID) 236 #if !defined(OS_ANDROID)
215 scoped_ptr<GCMEventRouter> js_event_router_; 237 scoped_ptr<GCMEventRouter> js_event_router_;
216 #endif 238 #endif
217 239
218 // For testing purpose. 240 // For testing purpose.
219 TestingDelegate* testing_delegate_; 241 TestingDelegate* testing_delegate_;
220 242
221 // Used to pass a weak pointer to the IO worker. 243 // Used to pass a weak pointer to the IO worker.
222 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; 244 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_;
223 245
224 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); 246 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
225 }; 247 };
226 248
227 } // namespace gcm 249 } // namespace gcm
228 250
229 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 251 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698