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

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

Issue 165993005: [GCM] Make sure GCM checkout logic is invoked when the profile is signed out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more feedback Created 6 years, 10 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 (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 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // |app_id|: application ID. 81 // |app_id|: application ID.
82 // |receiver_id|: registration ID of the receiver party. 82 // |receiver_id|: registration ID of the receiver party.
83 // |message|: message to be sent. 83 // |message|: message to be sent.
84 // |callback|: to be called once the asynchronous operation is done. 84 // |callback|: to be called once the asynchronous operation is done.
85 virtual void Send(const std::string& app_id, 85 virtual void Send(const std::string& app_id,
86 const std::string& receiver_id, 86 const std::string& receiver_id,
87 const GCMClient::OutgoingMessage& message, 87 const GCMClient::OutgoingMessage& message,
88 SendCallback callback); 88 SendCallback callback);
89 89
90 // For testing purpose. 90 // For testing purpose.
91 GCMClient* GetGCMClientForTesting() const;
92
91 void set_testing_delegate(TestingDelegate* testing_delegate) { 93 void set_testing_delegate(TestingDelegate* testing_delegate) {
92 testing_delegate_ = testing_delegate; 94 testing_delegate_ = testing_delegate;
93 } 95 }
94 96
95 protected: 97 protected:
96 // Flag that could be set by the testing code to enable GCM. Otherwise, 98 // Flag that could be set by the testing code to enable GCM. Otherwise,
97 // tests from official build will fail. 99 // tests from official build will fail.
98 static bool enable_gcm_for_testing_; 100 static bool enable_gcm_for_testing_;
99 101
100 private: 102 private:
101 friend class GCMProfileServiceTestConsumer; 103 friend class GCMProfileServiceTestConsumer;
102 104
103 class DelayedTaskController; 105 class DelayedTaskController;
104 class IOWorker; 106 class IOWorker;
105 107
106 struct RegistrationInfo { 108 struct RegistrationInfo {
107 RegistrationInfo(); 109 RegistrationInfo();
108 ~RegistrationInfo(); 110 ~RegistrationInfo();
109 bool IsValid() const; 111 bool IsValid() const;
110 112
111 std::vector<std::string> sender_ids; 113 std::vector<std::string> sender_ids;
112 std::string registration_id; 114 std::string registration_id;
113 }; 115 };
114 116
115 // Overridden from content::NotificationObserver: 117 // Overridden from content::NotificationObserver:
116 virtual void Observe(int type, 118 virtual void Observe(int type,
117 const content::NotificationSource& source, 119 const content::NotificationSource& source,
118 const content::NotificationDetails& details) OVERRIDE; 120 const content::NotificationDetails& details) OVERRIDE;
119 121
120 // Checks in with GCM by creating and initializing GCMClient when the profile 122 // Returns true if GCM is enabled for the rollout channel. This controls if
121 // has been signed in. 123 // GCMProfileService should make GCMClient checked in or not.
Nicolas Zea 2014/02/21 20:58:58 nit: "should make GCMClient checked in or not" ->"
jianli 2014/02/22 00:03:06 This is removed since I decided to combine this an
122 void CheckIn(const std::string& username); 124 bool IsGCMChannelEnabled() const;
125
126 // Ensures that the GCMClient is initialized and the GCM check-in is done when
127 // the profile was signed in.
128 void EnsureCheckedIn();
123 129
124 // Checks out of GCM when the profile has been signed out. This will erase 130 // Checks out of GCM when the profile has been signed out. This will erase
125 // all the cached and persisted data. 131 // all the cached and persisted data.
126 void CheckOut(); 132 void CheckOut();
127 133
128 // Resets the GCMClient instance. This is called when the profile is being 134 // Resets the GCMClient instance. This is called when the profile is being
129 // destroyed. 135 // destroyed.
130 void ResetGCMClient(); 136 void ResetGCMClient();
131 137
132 // Ensures that the app is ready for GCM functions and events. 138 // Ensures that the app is ready for GCM functions and events.
(...skipping 15 matching lines...) Expand all
148 GCMClient::Result result); 154 GCMClient::Result result);
149 void SendFinished(const std::string& app_id, 155 void SendFinished(const std::string& app_id,
150 const std::string& message_id, 156 const std::string& message_id,
151 GCMClient::Result result); 157 GCMClient::Result result);
152 void MessageReceived(const std::string& app_id, 158 void MessageReceived(const std::string& app_id,
153 GCMClient::IncomingMessage message); 159 GCMClient::IncomingMessage message);
154 void MessagesDeleted(const std::string& app_id); 160 void MessagesDeleted(const std::string& app_id);
155 void MessageSendError(const std::string& app_id, 161 void MessageSendError(const std::string& app_id,
156 const std::string& message_id, 162 const std::string& message_id,
157 GCMClient::Result result); 163 GCMClient::Result result);
158 void FinishInitializationOnUI(bool ready); 164 void FinishInitializationOnUI();
159 void GCMClientReady(); 165 void GCMClientReady();
160 166
161 // Returns the event router to fire the event for the given app. 167 // Returns the event router to fire the event for the given app.
162 GCMEventRouter* GetEventRouter(const std::string& app_id) const; 168 GCMEventRouter* GetEventRouter(const std::string& app_id) const;
163 169
164 // Used to persist the IDs of registered apps. 170 // Used to persist the IDs of registered apps.
165 void ReadRegisteredAppIDs(); 171 void ReadRegisteredAppIDs();
166 void WriteRegisteredAppIDs(); 172 void WriteRegisteredAppIDs();
167 173
168 // Used to persist registration info into the app's state store. 174 // Used to persist registration info into the app's state store.
169 void DeleteRegistrationInfo(const std::string& app_id); 175 void DeleteRegistrationInfo(const std::string& app_id);
170 void WriteRegistrationInfo(const std::string& app_id); 176 void WriteRegistrationInfo(const std::string& app_id);
171 void ReadRegistrationInfo(const std::string& app_id); 177 void ReadRegistrationInfo(const std::string& app_id);
172 void ReadRegistrationInfoFinished(const std::string& app_id, 178 void ReadRegistrationInfoFinished(const std::string& app_id,
173 scoped_ptr<base::Value> value); 179 scoped_ptr<base::Value> value);
174 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, 180 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value,
175 RegistrationInfo* registration_info); 181 RegistrationInfo* registration_info);
176 182
177 // Returns the key used to identify the registration info saved into the 183 // Returns the key used to identify the registration info saved into the
178 // app's state store. Used for testing purpose. 184 // app's state store. Used for testing purpose.
179 static const char* GetPersistentRegisterKeyForTesting(); 185 static const char* GetPersistentRegisterKeyForTesting();
180 186
181 // The profile which owns this object. 187 // The profile which owns this object.
182 Profile* profile_; 188 Profile* profile_;
183 189
184 // Used to creat the GCMClient instance.
185 scoped_ptr<GCMClientFactory> gcm_client_factory_;
186
187 // Flag to indicate if GCMClient is ready. 190 // Flag to indicate if GCMClient is ready.
188 bool gcm_client_ready_; 191 bool gcm_client_ready_;
189 192
190 // The username of the signed-in profile. 193 // The username of the signed-in profile.
191 std::string username_; 194 std::string username_;
192 195
193 content::NotificationRegistrar registrar_; 196 content::NotificationRegistrar registrar_;
194 197
195 scoped_ptr<DelayedTaskController> delayed_task_controller_; 198 scoped_ptr<DelayedTaskController> delayed_task_controller_;
196 199
(...skipping 20 matching lines...) Expand all
217 220
218 // Used to pass a weak pointer to the IO worker. 221 // Used to pass a weak pointer to the IO worker.
219 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; 222 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_;
220 223
221 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); 224 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
222 }; 225 };
223 226
224 } // namespace gcm 227 } // namespace gcm
225 228
226 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 229 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698