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

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 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.
Nicolas Zea 2014/02/21 18:43:33 nit: mention that this controls whether the GCMPS
jianli 2014/02/21 20:24:06 Done.
121 // has been signed in. 123 bool IsGCMChannelEnabled() const;
122 void CheckIn(const std::string& username); 124
125 // Ensures that the GCMClient is initialized and the GCM check-in is done when
126 // the profile was signed in.
127 void EnsureCheckedIn();
123 128
124 // Checks out of GCM when the profile has been signed out. This will erase 129 // Checks out of GCM when the profile has been signed out. This will erase
125 // all the cached and persisted data. 130 // all the cached and persisted data.
126 void CheckOut(); 131 void CheckOut();
127 132
128 // Resets the GCMClient instance. This is called when the profile is being 133 // Resets the GCMClient instance. This is called when the profile is being
129 // destroyed. 134 // destroyed.
130 void ResetGCMClient(); 135 void ResetGCMClient();
131 136
132 // Ensures that the app is ready for GCM functions and events. 137 // Ensures that the app is ready for GCM functions and events.
(...skipping 15 matching lines...) Expand all
148 GCMClient::Result result); 153 GCMClient::Result result);
149 void SendFinished(const std::string& app_id, 154 void SendFinished(const std::string& app_id,
150 const std::string& message_id, 155 const std::string& message_id,
151 GCMClient::Result result); 156 GCMClient::Result result);
152 void MessageReceived(const std::string& app_id, 157 void MessageReceived(const std::string& app_id,
153 GCMClient::IncomingMessage message); 158 GCMClient::IncomingMessage message);
154 void MessagesDeleted(const std::string& app_id); 159 void MessagesDeleted(const std::string& app_id);
155 void MessageSendError(const std::string& app_id, 160 void MessageSendError(const std::string& app_id,
156 const std::string& message_id, 161 const std::string& message_id,
157 GCMClient::Result result); 162 GCMClient::Result result);
158 void FinishInitializationOnUI(bool ready); 163 void FinishInitializationOnUI();
159 void GCMClientReady(); 164 void GCMClientReady();
160 165
161 // Returns the event router to fire the event for the given app. 166 // Returns the event router to fire the event for the given app.
162 GCMEventRouter* GetEventRouter(const std::string& app_id) const; 167 GCMEventRouter* GetEventRouter(const std::string& app_id) const;
163 168
164 // Used to persist the IDs of registered apps. 169 // Used to persist the IDs of registered apps.
165 void ReadRegisteredAppIDs(); 170 void ReadRegisteredAppIDs();
166 void WriteRegisteredAppIDs(); 171 void WriteRegisteredAppIDs();
167 172
168 // Used to persist registration info into the app's state store. 173 // Used to persist registration info into the app's state store.
169 void DeleteRegistrationInfo(const std::string& app_id); 174 void DeleteRegistrationInfo(const std::string& app_id);
170 void WriteRegistrationInfo(const std::string& app_id); 175 void WriteRegistrationInfo(const std::string& app_id);
171 void ReadRegistrationInfo(const std::string& app_id); 176 void ReadRegistrationInfo(const std::string& app_id);
172 void ReadRegistrationInfoFinished(const std::string& app_id, 177 void ReadRegistrationInfoFinished(const std::string& app_id,
173 scoped_ptr<base::Value> value); 178 scoped_ptr<base::Value> value);
174 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value, 179 bool ParsePersistedRegistrationInfo(scoped_ptr<base::Value> value,
175 RegistrationInfo* registration_info); 180 RegistrationInfo* registration_info);
176 181
177 // Returns the key used to identify the registration info saved into the 182 // Returns the key used to identify the registration info saved into the
178 // app's state store. Used for testing purpose. 183 // app's state store. Used for testing purpose.
179 static const char* GetPersistentRegisterKeyForTesting(); 184 static const char* GetPersistentRegisterKeyForTesting();
180 185
181 // The profile which owns this object. 186 // The profile which owns this object.
182 Profile* profile_; 187 Profile* profile_;
183 188
184 // Used to creat the GCMClient instance.
185 scoped_ptr<GCMClientFactory> gcm_client_factory_;
186
187 // Flag to indicate if GCMClient is ready. 189 // Flag to indicate if GCMClient is ready.
188 bool gcm_client_ready_; 190 bool gcm_client_ready_;
189 191
190 // The username of the signed-in profile. 192 // The username of the signed-in profile.
191 std::string username_; 193 std::string username_;
192 194
193 content::NotificationRegistrar registrar_; 195 content::NotificationRegistrar registrar_;
194 196
195 scoped_ptr<DelayedTaskController> delayed_task_controller_; 197 scoped_ptr<DelayedTaskController> delayed_task_controller_;
196 198
(...skipping 20 matching lines...) Expand all
217 219
218 // Used to pass a weak pointer to the IO worker. 220 // Used to pass a weak pointer to the IO worker.
219 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_; 221 base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_;
220 222
221 DISALLOW_COPY_AND_ASSIGN(GCMProfileService); 223 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
222 }; 224 };
223 225
224 } // namespace gcm 226 } // namespace gcm
225 227
226 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_ 228 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698