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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 2889683003: Rename TaskRunner::RunsTasksOnCurrentThread() in //components (Closed)
Patch Set: rebase Created 3 years, 6 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 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 #include "components/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 std::unique_ptr<GCMClient> gcm_client_; 128 std::unique_ptr<GCMClient> gcm_client_;
129 129
130 DISALLOW_COPY_AND_ASSIGN(IOWorker); 130 DISALLOW_COPY_AND_ASSIGN(IOWorker);
131 }; 131 };
132 132
133 GCMDriverDesktop::IOWorker::IOWorker( 133 GCMDriverDesktop::IOWorker::IOWorker(
134 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 134 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
135 const scoped_refptr<base::SequencedTaskRunner>& io_thread) 135 const scoped_refptr<base::SequencedTaskRunner>& io_thread)
136 : ui_thread_(ui_thread), 136 : ui_thread_(ui_thread),
137 io_thread_(io_thread) { 137 io_thread_(io_thread) {
138 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 138 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
139 } 139 }
140 140
141 GCMDriverDesktop::IOWorker::~IOWorker() { 141 GCMDriverDesktop::IOWorker::~IOWorker() {
142 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 142 DCHECK(io_thread_->RunsTasksInCurrentSequence());
143 } 143 }
144 144
145 void GCMDriverDesktop::IOWorker::Initialize( 145 void GCMDriverDesktop::IOWorker::Initialize(
146 std::unique_ptr<GCMClientFactory> gcm_client_factory, 146 std::unique_ptr<GCMClientFactory> gcm_client_factory,
147 const GCMClient::ChromeBuildInfo& chrome_build_info, 147 const GCMClient::ChromeBuildInfo& chrome_build_info,
148 const base::FilePath& store_path, 148 const base::FilePath& store_path,
149 const scoped_refptr<net::URLRequestContextGetter>& request_context, 149 const scoped_refptr<net::URLRequestContextGetter>& request_context,
150 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) { 150 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
151 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 151 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
152 tracked_objects::ScopedTracker tracking_profile( 152 tracked_objects::ScopedTracker tracking_profile(
153 FROM_HERE_WITH_EXPLICIT_FUNCTION( 153 FROM_HERE_WITH_EXPLICIT_FUNCTION(
154 "477117 GCMDriverDesktop::IOWorker::Initialize")); 154 "477117 GCMDriverDesktop::IOWorker::Initialize"));
155 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 155 DCHECK(io_thread_->RunsTasksInCurrentSequence());
156 156
157 gcm_client_ = gcm_client_factory->BuildInstance(); 157 gcm_client_ = gcm_client_factory->BuildInstance();
158 158
159 gcm_client_->Initialize( 159 gcm_client_->Initialize(
160 chrome_build_info, store_path, blocking_task_runner, request_context, 160 chrome_build_info, store_path, blocking_task_runner, request_context,
161 base::WrapUnique<Encryptor>(new SystemEncryptor), this); 161 base::WrapUnique<Encryptor>(new SystemEncryptor), this);
162 } 162 }
163 163
164 void GCMDriverDesktop::IOWorker::OnRegisterFinished( 164 void GCMDriverDesktop::IOWorker::OnRegisterFinished(
165 const linked_ptr<RegistrationInfo>& registration_info, 165 const linked_ptr<RegistrationInfo>& registration_info,
166 const std::string& registration_id, 166 const std::string& registration_id,
167 GCMClient::Result result) { 167 GCMClient::Result result) {
168 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 168 DCHECK(io_thread_->RunsTasksInCurrentSequence());
169 169
170 const GCMRegistrationInfo* gcm_registration_info = 170 const GCMRegistrationInfo* gcm_registration_info =
171 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); 171 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
172 if (gcm_registration_info) { 172 if (gcm_registration_info) {
173 ui_thread_->PostTask( 173 ui_thread_->PostTask(
174 FROM_HERE, 174 FROM_HERE,
175 base::Bind(&GCMDriverDesktop::RegisterFinished, 175 base::Bind(&GCMDriverDesktop::RegisterFinished,
176 service_, 176 service_,
177 gcm_registration_info->app_id, 177 gcm_registration_info->app_id,
178 registration_id, 178 registration_id,
(...skipping 11 matching lines...) Expand all
190 instance_id_token_info->authorized_entity, 190 instance_id_token_info->authorized_entity,
191 instance_id_token_info->scope, 191 instance_id_token_info->scope,
192 registration_id, 192 registration_id,
193 result)); 193 result));
194 } 194 }
195 } 195 }
196 196
197 void GCMDriverDesktop::IOWorker::OnUnregisterFinished( 197 void GCMDriverDesktop::IOWorker::OnUnregisterFinished(
198 const linked_ptr<RegistrationInfo>& registration_info, 198 const linked_ptr<RegistrationInfo>& registration_info,
199 GCMClient::Result result) { 199 GCMClient::Result result) {
200 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 200 DCHECK(io_thread_->RunsTasksInCurrentSequence());
201 201
202 const GCMRegistrationInfo* gcm_registration_info = 202 const GCMRegistrationInfo* gcm_registration_info =
203 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); 203 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
204 if (gcm_registration_info) { 204 if (gcm_registration_info) {
205 ui_thread_->PostTask( 205 ui_thread_->PostTask(
206 FROM_HERE, 206 FROM_HERE,
207 base::Bind(&GCMDriverDesktop::RemoveEncryptionInfoAfterUnregister, 207 base::Bind(&GCMDriverDesktop::RemoveEncryptionInfoAfterUnregister,
208 service_, 208 service_,
209 gcm_registration_info->app_id, 209 gcm_registration_info->app_id,
210 result)); 210 result));
211 } 211 }
212 212
213 const InstanceIDTokenInfo* instance_id_token_info = 213 const InstanceIDTokenInfo* instance_id_token_info =
214 InstanceIDTokenInfo::FromRegistrationInfo(registration_info.get()); 214 InstanceIDTokenInfo::FromRegistrationInfo(registration_info.get());
215 if (instance_id_token_info) { 215 if (instance_id_token_info) {
216 ui_thread_->PostTask( 216 ui_thread_->PostTask(
217 FROM_HERE, 217 FROM_HERE,
218 base::Bind(&GCMDriverDesktop::DeleteTokenFinished, 218 base::Bind(&GCMDriverDesktop::DeleteTokenFinished,
219 service_, 219 service_,
220 instance_id_token_info->app_id, 220 instance_id_token_info->app_id,
221 instance_id_token_info->authorized_entity, 221 instance_id_token_info->authorized_entity,
222 instance_id_token_info->scope, 222 instance_id_token_info->scope,
223 result)); 223 result));
224 } 224 }
225 } 225 }
226 226
227 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, 227 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id,
228 const std::string& message_id, 228 const std::string& message_id,
229 GCMClient::Result result) { 229 GCMClient::Result result) {
230 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 230 DCHECK(io_thread_->RunsTasksInCurrentSequence());
231 231
232 ui_thread_->PostTask( 232 ui_thread_->PostTask(
233 FROM_HERE, 233 FROM_HERE,
234 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, 234 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id,
235 result)); 235 result));
236 } 236 }
237 237
238 void GCMDriverDesktop::IOWorker::OnMessageReceived( 238 void GCMDriverDesktop::IOWorker::OnMessageReceived(
239 const std::string& app_id, 239 const std::string& app_id,
240 const IncomingMessage& message) { 240 const IncomingMessage& message) {
241 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 241 DCHECK(io_thread_->RunsTasksInCurrentSequence());
242 242
243 ui_thread_->PostTask( 243 ui_thread_->PostTask(
244 FROM_HERE, 244 FROM_HERE,
245 base::Bind(&GCMDriverDesktop::MessageReceived, 245 base::Bind(&GCMDriverDesktop::MessageReceived,
246 service_, 246 service_,
247 app_id, 247 app_id,
248 message)); 248 message));
249 } 249 }
250 250
251 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) { 251 void GCMDriverDesktop::IOWorker::OnMessagesDeleted(const std::string& app_id) {
252 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 252 DCHECK(io_thread_->RunsTasksInCurrentSequence());
253 253
254 ui_thread_->PostTask( 254 ui_thread_->PostTask(
255 FROM_HERE, 255 FROM_HERE,
256 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id)); 256 base::Bind(&GCMDriverDesktop::MessagesDeleted, service_, app_id));
257 } 257 }
258 258
259 void GCMDriverDesktop::IOWorker::OnMessageSendError( 259 void GCMDriverDesktop::IOWorker::OnMessageSendError(
260 const std::string& app_id, 260 const std::string& app_id,
261 const GCMClient::SendErrorDetails& send_error_details) { 261 const GCMClient::SendErrorDetails& send_error_details) {
262 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 262 DCHECK(io_thread_->RunsTasksInCurrentSequence());
263 263
264 ui_thread_->PostTask( 264 ui_thread_->PostTask(
265 FROM_HERE, 265 FROM_HERE,
266 base::Bind(&GCMDriverDesktop::MessageSendError, service_, app_id, 266 base::Bind(&GCMDriverDesktop::MessageSendError, service_, app_id,
267 send_error_details)); 267 send_error_details));
268 } 268 }
269 269
270 void GCMDriverDesktop::IOWorker::OnSendAcknowledged( 270 void GCMDriverDesktop::IOWorker::OnSendAcknowledged(
271 const std::string& app_id, 271 const std::string& app_id,
272 const std::string& message_id) { 272 const std::string& message_id) {
273 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 273 DCHECK(io_thread_->RunsTasksInCurrentSequence());
274 274
275 ui_thread_->PostTask( 275 ui_thread_->PostTask(
276 FROM_HERE, 276 FROM_HERE,
277 base::Bind( 277 base::Bind(
278 &GCMDriverDesktop::SendAcknowledged, service_, app_id, message_id)); 278 &GCMDriverDesktop::SendAcknowledged, service_, app_id, message_id));
279 } 279 }
280 280
281 void GCMDriverDesktop::IOWorker::OnGCMReady( 281 void GCMDriverDesktop::IOWorker::OnGCMReady(
282 const std::vector<AccountMapping>& account_mappings, 282 const std::vector<AccountMapping>& account_mappings,
283 const base::Time& last_token_fetch_time) { 283 const base::Time& last_token_fetch_time) {
284 ui_thread_->PostTask(FROM_HERE, 284 ui_thread_->PostTask(FROM_HERE,
285 base::Bind(&GCMDriverDesktop::GCMClientReady, 285 base::Bind(&GCMDriverDesktop::GCMClientReady,
286 service_, 286 service_,
287 account_mappings, 287 account_mappings,
288 last_token_fetch_time)); 288 last_token_fetch_time));
289 } 289 }
290 290
291 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { 291 void GCMDriverDesktop::IOWorker::OnActivityRecorded() {
292 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 292 DCHECK(io_thread_->RunsTasksInCurrentSequence());
293 // When an activity is recorded, get all the stats and refresh the UI of 293 // When an activity is recorded, get all the stats and refresh the UI of
294 // gcm-internals page. 294 // gcm-internals page.
295 GetGCMStatistics(GCMDriver::KEEP_LOGS); 295 GetGCMStatistics(GCMDriver::KEEP_LOGS);
296 } 296 }
297 297
298 void GCMDriverDesktop::IOWorker::OnConnected( 298 void GCMDriverDesktop::IOWorker::OnConnected(
299 const net::IPEndPoint& ip_endpoint) { 299 const net::IPEndPoint& ip_endpoint) {
300 ui_thread_->PostTask(FROM_HERE, 300 ui_thread_->PostTask(FROM_HERE,
301 base::Bind(&GCMDriverDesktop::OnConnected, 301 base::Bind(&GCMDriverDesktop::OnConnected,
302 service_, 302 service_,
303 ip_endpoint)); 303 ip_endpoint));
304 } 304 }
305 305
306 void GCMDriverDesktop::IOWorker::OnDisconnected() { 306 void GCMDriverDesktop::IOWorker::OnDisconnected() {
307 ui_thread_->PostTask(FROM_HERE, 307 ui_thread_->PostTask(FROM_HERE,
308 base::Bind(&GCMDriverDesktop::OnDisconnected, service_)); 308 base::Bind(&GCMDriverDesktop::OnDisconnected, service_));
309 } 309 }
310 310
311 void GCMDriverDesktop::IOWorker::OnStoreReset() { 311 void GCMDriverDesktop::IOWorker::OnStoreReset() {
312 ui_thread_->PostTask(FROM_HERE, 312 ui_thread_->PostTask(FROM_HERE,
313 base::Bind(&GCMDriverDesktop::OnStoreReset, service_)); 313 base::Bind(&GCMDriverDesktop::OnStoreReset, service_));
314 } 314 }
315 315
316 void GCMDriverDesktop::IOWorker::Start( 316 void GCMDriverDesktop::IOWorker::Start(
317 GCMClient::StartMode start_mode, 317 GCMClient::StartMode start_mode,
318 const base::WeakPtr<GCMDriverDesktop>& service) { 318 const base::WeakPtr<GCMDriverDesktop>& service) {
319 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 319 DCHECK(io_thread_->RunsTasksInCurrentSequence());
320 320
321 service_ = service; 321 service_ = service;
322 gcm_client_->Start(start_mode); 322 gcm_client_->Start(start_mode);
323 } 323 }
324 324
325 void GCMDriverDesktop::IOWorker::Stop() { 325 void GCMDriverDesktop::IOWorker::Stop() {
326 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 326 DCHECK(io_thread_->RunsTasksInCurrentSequence());
327 327
328 gcm_client_->Stop(); 328 gcm_client_->Stop();
329 } 329 }
330 330
331 void GCMDriverDesktop::IOWorker::Register( 331 void GCMDriverDesktop::IOWorker::Register(
332 const std::string& app_id, 332 const std::string& app_id,
333 const std::vector<std::string>& sender_ids) { 333 const std::vector<std::string>& sender_ids) {
334 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 334 DCHECK(io_thread_->RunsTasksInCurrentSequence());
335 335
336 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); 336 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
337 gcm_info->app_id = app_id; 337 gcm_info->app_id = app_id;
338 gcm_info->sender_ids = sender_ids; 338 gcm_info->sender_ids = sender_ids;
339 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release())); 339 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release()));
340 } 340 }
341 341
342 bool GCMDriverDesktop::IOWorker::ValidateRegistration( 342 bool GCMDriverDesktop::IOWorker::ValidateRegistration(
343 std::unique_ptr<RegistrationInfo> registration_info, 343 std::unique_ptr<RegistrationInfo> registration_info,
344 const std::string& registration_id) { 344 const std::string& registration_id) {
345 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 345 DCHECK(io_thread_->RunsTasksInCurrentSequence());
346 346
347 return gcm_client_->ValidateRegistration( 347 return gcm_client_->ValidateRegistration(
348 make_linked_ptr(registration_info.release()), registration_id); 348 make_linked_ptr(registration_info.release()), registration_id);
349 } 349 }
350 350
351 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { 351 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) {
352 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 352 DCHECK(io_thread_->RunsTasksInCurrentSequence());
353 353
354 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); 354 std::unique_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
355 gcm_info->app_id = app_id; 355 gcm_info->app_id = app_id;
356 gcm_client_->Unregister( 356 gcm_client_->Unregister(
357 make_linked_ptr<RegistrationInfo>(gcm_info.release())); 357 make_linked_ptr<RegistrationInfo>(gcm_info.release()));
358 } 358 }
359 359
360 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id, 360 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id,
361 const std::string& receiver_id, 361 const std::string& receiver_id,
362 const OutgoingMessage& message) { 362 const OutgoingMessage& message) {
363 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 363 DCHECK(io_thread_->RunsTasksInCurrentSequence());
364 364
365 gcm_client_->Send(app_id, receiver_id, message); 365 gcm_client_->Send(app_id, receiver_id, message);
366 } 366 }
367 367
368 void GCMDriverDesktop::IOWorker::GetGCMStatistics( 368 void GCMDriverDesktop::IOWorker::GetGCMStatistics(
369 ClearActivityLogs clear_logs) { 369 ClearActivityLogs clear_logs) {
370 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 370 DCHECK(io_thread_->RunsTasksInCurrentSequence());
371 gcm::GCMClient::GCMStatistics stats; 371 gcm::GCMClient::GCMStatistics stats;
372 372
373 if (gcm_client_.get()) { 373 if (gcm_client_.get()) {
374 if (clear_logs == GCMDriver::CLEAR_LOGS) 374 if (clear_logs == GCMDriver::CLEAR_LOGS)
375 gcm_client_->ClearActivityLogs(); 375 gcm_client_->ClearActivityLogs();
376 stats = gcm_client_->GetStatistics(); 376 stats = gcm_client_->GetStatistics();
377 } 377 }
378 378
379 ui_thread_->PostTask( 379 ui_thread_->PostTask(
380 FROM_HERE, 380 FROM_HERE,
381 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); 381 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats));
382 } 382 }
383 383
384 void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) { 384 void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) {
385 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 385 DCHECK(io_thread_->RunsTasksInCurrentSequence());
386 gcm::GCMClient::GCMStatistics stats; 386 gcm::GCMClient::GCMStatistics stats;
387 387
388 if (gcm_client_.get()) { 388 if (gcm_client_.get()) {
389 gcm_client_->SetRecording(recording); 389 gcm_client_->SetRecording(recording);
390 stats = gcm_client_->GetStatistics(); 390 stats = gcm_client_->GetStatistics();
391 stats.gcm_client_created = true; 391 stats.gcm_client_created = true;
392 } 392 }
393 393
394 ui_thread_->PostTask( 394 ui_thread_->PostTask(
395 FROM_HERE, 395 FROM_HERE,
396 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); 396 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats));
397 } 397 }
398 398
399 void GCMDriverDesktop::IOWorker::SetAccountTokens( 399 void GCMDriverDesktop::IOWorker::SetAccountTokens(
400 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { 400 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
401 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 401 DCHECK(io_thread_->RunsTasksInCurrentSequence());
402 402
403 if (gcm_client_.get()) 403 if (gcm_client_.get())
404 gcm_client_->SetAccountTokens(account_tokens); 404 gcm_client_->SetAccountTokens(account_tokens);
405 } 405 }
406 406
407 void GCMDriverDesktop::IOWorker::UpdateAccountMapping( 407 void GCMDriverDesktop::IOWorker::UpdateAccountMapping(
408 const AccountMapping& account_mapping) { 408 const AccountMapping& account_mapping) {
409 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 409 DCHECK(io_thread_->RunsTasksInCurrentSequence());
410 410
411 if (gcm_client_.get()) 411 if (gcm_client_.get())
412 gcm_client_->UpdateAccountMapping(account_mapping); 412 gcm_client_->UpdateAccountMapping(account_mapping);
413 } 413 }
414 414
415 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( 415 void GCMDriverDesktop::IOWorker::RemoveAccountMapping(
416 const std::string& account_id) { 416 const std::string& account_id) {
417 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 417 DCHECK(io_thread_->RunsTasksInCurrentSequence());
418 418
419 if (gcm_client_.get()) 419 if (gcm_client_.get())
420 gcm_client_->RemoveAccountMapping(account_id); 420 gcm_client_->RemoveAccountMapping(account_id);
421 } 421 }
422 422
423 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { 423 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) {
424 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 424 DCHECK(io_thread_->RunsTasksInCurrentSequence());
425 425
426 if (gcm_client_.get()) 426 if (gcm_client_.get())
427 gcm_client_->SetLastTokenFetchTime(time); 427 gcm_client_->SetLastTokenFetchTime(time);
428 } 428 }
429 429
430 void GCMDriverDesktop::IOWorker::AddInstanceIDData( 430 void GCMDriverDesktop::IOWorker::AddInstanceIDData(
431 const std::string& app_id, 431 const std::string& app_id,
432 const std::string& instance_id, 432 const std::string& instance_id,
433 const std::string& extra_data) { 433 const std::string& extra_data) {
434 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 434 DCHECK(io_thread_->RunsTasksInCurrentSequence());
435 435
436 if (gcm_client_.get()) 436 if (gcm_client_.get())
437 gcm_client_->AddInstanceIDData(app_id, instance_id, extra_data); 437 gcm_client_->AddInstanceIDData(app_id, instance_id, extra_data);
438 } 438 }
439 439
440 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData( 440 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData(
441 const std::string& app_id) { 441 const std::string& app_id) {
442 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 442 DCHECK(io_thread_->RunsTasksInCurrentSequence());
443 443
444 if (gcm_client_.get()) 444 if (gcm_client_.get())
445 gcm_client_->RemoveInstanceIDData(app_id); 445 gcm_client_->RemoveInstanceIDData(app_id);
446 } 446 }
447 447
448 void GCMDriverDesktop::IOWorker::GetInstanceIDData( 448 void GCMDriverDesktop::IOWorker::GetInstanceIDData(
449 const std::string& app_id) { 449 const std::string& app_id) {
450 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 450 DCHECK(io_thread_->RunsTasksInCurrentSequence());
451 451
452 std::string instance_id; 452 std::string instance_id;
453 std::string extra_data; 453 std::string extra_data;
454 if (gcm_client_.get()) 454 if (gcm_client_.get())
455 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data); 455 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data);
456 456
457 ui_thread_->PostTask( 457 ui_thread_->PostTask(
458 FROM_HERE, 458 FROM_HERE,
459 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, 459 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished,
460 service_, app_id, instance_id, extra_data)); 460 service_, app_id, instance_id, extra_data));
461 } 461 }
462 462
463 void GCMDriverDesktop::IOWorker::GetToken( 463 void GCMDriverDesktop::IOWorker::GetToken(
464 const std::string& app_id, 464 const std::string& app_id,
465 const std::string& authorized_entity, 465 const std::string& authorized_entity,
466 const std::string& scope, 466 const std::string& scope,
467 const std::map<std::string, std::string>& options) { 467 const std::map<std::string, std::string>& options) {
468 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 468 DCHECK(io_thread_->RunsTasksInCurrentSequence());
469 469
470 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( 470 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info(
471 new InstanceIDTokenInfo); 471 new InstanceIDTokenInfo);
472 instance_id_token_info->app_id = app_id; 472 instance_id_token_info->app_id = app_id;
473 instance_id_token_info->authorized_entity = authorized_entity; 473 instance_id_token_info->authorized_entity = authorized_entity;
474 instance_id_token_info->scope = scope; 474 instance_id_token_info->scope = scope;
475 instance_id_token_info->options = options; 475 instance_id_token_info->options = options;
476 gcm_client_->Register( 476 gcm_client_->Register(
477 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); 477 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
478 } 478 }
479 479
480 void GCMDriverDesktop::IOWorker::DeleteToken( 480 void GCMDriverDesktop::IOWorker::DeleteToken(
481 const std::string& app_id, 481 const std::string& app_id,
482 const std::string& authorized_entity, 482 const std::string& authorized_entity,
483 const std::string& scope) { 483 const std::string& scope) {
484 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info( 484 std::unique_ptr<InstanceIDTokenInfo> instance_id_token_info(
485 new InstanceIDTokenInfo); 485 new InstanceIDTokenInfo);
486 instance_id_token_info->app_id = app_id; 486 instance_id_token_info->app_id = app_id;
487 instance_id_token_info->authorized_entity = authorized_entity; 487 instance_id_token_info->authorized_entity = authorized_entity;
488 instance_id_token_info->scope = scope; 488 instance_id_token_info->scope = scope;
489 gcm_client_->Unregister( 489 gcm_client_->Unregister(
490 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); 490 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
491 } 491 }
492 492
493 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { 493 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) {
494 #if defined(OS_CHROMEOS) 494 #if defined(OS_CHROMEOS)
495 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 495 DCHECK(io_thread_->RunsTasksInCurrentSequence());
496 496
497 std::unique_ptr<base::Timer> timer; 497 std::unique_ptr<base::Timer> timer;
498 if (wake) 498 if (wake)
499 timer.reset(new timers::SimpleAlarmTimer()); 499 timer.reset(new timers::SimpleAlarmTimer());
500 else 500 else
501 timer.reset(new base::Timer(true, false)); 501 timer.reset(new base::Timer(true, false));
502 502
503 gcm_client_->UpdateHeartbeatTimer(std::move(timer)); 503 gcm_client_->UpdateHeartbeatTimer(std::move(timer));
504 #endif 504 #endif
505 } 505 }
506 506
507 void GCMDriverDesktop::IOWorker::AddHeartbeatInterval(const std::string& scope, 507 void GCMDriverDesktop::IOWorker::AddHeartbeatInterval(const std::string& scope,
508 int interval_ms) { 508 int interval_ms) {
509 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 509 DCHECK(io_thread_->RunsTasksInCurrentSequence());
510 gcm_client_->AddHeartbeatInterval(scope, interval_ms); 510 gcm_client_->AddHeartbeatInterval(scope, interval_ms);
511 } 511 }
512 512
513 void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval( 513 void GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval(
514 const std::string& scope) { 514 const std::string& scope) {
515 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 515 DCHECK(io_thread_->RunsTasksInCurrentSequence());
516 gcm_client_->RemoveHeartbeatInterval(scope); 516 gcm_client_->RemoveHeartbeatInterval(scope);
517 } 517 }
518 518
519 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure( 519 void GCMDriverDesktop::IOWorker::RecordDecryptionFailure(
520 const std::string& app_id, 520 const std::string& app_id,
521 GCMEncryptionProvider::DecryptionResult result) { 521 GCMEncryptionProvider::DecryptionResult result) {
522 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 522 DCHECK(io_thread_->RunsTasksInCurrentSequence());
523 gcm_client_->RecordDecryptionFailure(app_id, result); 523 gcm_client_->RecordDecryptionFailure(app_id, result);
524 } 524 }
525 525
526 GCMDriverDesktop::GCMDriverDesktop( 526 GCMDriverDesktop::GCMDriverDesktop(
527 std::unique_ptr<GCMClientFactory> gcm_client_factory, 527 std::unique_ptr<GCMClientFactory> gcm_client_factory,
528 const GCMClient::ChromeBuildInfo& chrome_build_info, 528 const GCMClient::ChromeBuildInfo& chrome_build_info,
529 const std::string& channel_status_request_url, 529 const std::string& channel_status_request_url,
530 const std::string& user_agent, 530 const std::string& user_agent,
531 PrefService* prefs, 531 PrefService* prefs,
532 const base::FilePath& store_path, 532 const base::FilePath& store_path,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 void GCMDriverDesktop::ValidateRegistration( 576 void GCMDriverDesktop::ValidateRegistration(
577 const std::string& app_id, 577 const std::string& app_id,
578 const std::vector<std::string>& sender_ids, 578 const std::vector<std::string>& sender_ids,
579 const std::string& registration_id, 579 const std::string& registration_id,
580 const ValidateRegistrationCallback& callback) { 580 const ValidateRegistrationCallback& callback) {
581 DCHECK(!app_id.empty()); 581 DCHECK(!app_id.empty());
582 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); 582 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders);
583 DCHECK(!registration_id.empty()); 583 DCHECK(!registration_id.empty());
584 DCHECK(!callback.is_null()); 584 DCHECK(!callback.is_null());
585 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 585 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
586 586
587 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 587 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
588 if (result != GCMClient::SUCCESS) { 588 if (result != GCMClient::SUCCESS) {
589 // Can't tell whether the registration is valid or not, so don't run the 589 // Can't tell whether the registration is valid or not, so don't run the
590 // callback (let it hang indefinitely). 590 // callback (let it hang indefinitely).
591 return; 591 return;
592 } 592 }
593 593
594 // Only validating current state, so ignore pending register_callbacks_. 594 // Only validating current state, so ignore pending register_callbacks_.
595 595
(...skipping 20 matching lines...) Expand all
616 const ValidateRegistrationCallback& callback) { 616 const ValidateRegistrationCallback& callback) {
617 base::PostTaskAndReplyWithResult( 617 base::PostTaskAndReplyWithResult(
618 io_thread_.get(), FROM_HERE, 618 io_thread_.get(), FROM_HERE,
619 base::Bind(&GCMDriverDesktop::IOWorker::ValidateRegistration, 619 base::Bind(&GCMDriverDesktop::IOWorker::ValidateRegistration,
620 base::Unretained(io_worker_.get()), 620 base::Unretained(io_worker_.get()),
621 base::Passed(&registration_info), registration_id), 621 base::Passed(&registration_info), registration_id),
622 callback); 622 callback);
623 } 623 }
624 624
625 void GCMDriverDesktop::Shutdown() { 625 void GCMDriverDesktop::Shutdown() {
626 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 626 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
627 627
628 Stop(); 628 Stop();
629 GCMDriver::Shutdown(); 629 GCMDriver::Shutdown();
630 630
631 // Dispose the syncer in order to release the reference to 631 // Dispose the syncer in order to release the reference to
632 // URLRequestContextGetter that needs to be done before IOThread gets 632 // URLRequestContextGetter that needs to be done before IOThread gets
633 // deleted. 633 // deleted.
634 gcm_channel_status_syncer_.reset(); 634 gcm_channel_status_syncer_.reset();
635 635
636 io_thread_->DeleteSoon(FROM_HERE, io_worker_.release()); 636 io_thread_->DeleteSoon(FROM_HERE, io_worker_.release());
637 } 637 }
638 638
639 void GCMDriverDesktop::OnSignedIn() { 639 void GCMDriverDesktop::OnSignedIn() {
640 signed_in_ = true; 640 signed_in_ = true;
641 } 641 }
642 642
643 void GCMDriverDesktop::OnSignedOut() { 643 void GCMDriverDesktop::OnSignedOut() {
644 signed_in_ = false; 644 signed_in_ = false;
645 } 645 }
646 646
647 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, 647 void GCMDriverDesktop::AddAppHandler(const std::string& app_id,
648 GCMAppHandler* handler) { 648 GCMAppHandler* handler) {
649 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 649 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
650 GCMDriver::AddAppHandler(app_id, handler); 650 GCMDriver::AddAppHandler(app_id, handler);
651 651
652 // Ensures that the GCM service is started when there is an interest. 652 // Ensures that the GCM service is started when there is an interest.
653 EnsureStarted(GCMClient::DELAYED_START); 653 EnsureStarted(GCMClient::DELAYED_START);
654 } 654 }
655 655
656 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { 656 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) {
657 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 657 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
658 GCMDriver::RemoveAppHandler(app_id); 658 GCMDriver::RemoveAppHandler(app_id);
659 659
660 // Stops the GCM service when no app intends to consume it. Stop function will 660 // Stops the GCM service when no app intends to consume it. Stop function will
661 // remove the last app handler - account mapper. 661 // remove the last app handler - account mapper.
662 if (app_handlers().size() == 1) { 662 if (app_handlers().size() == 1) {
663 Stop(); 663 Stop();
664 gcm_channel_status_syncer_->Stop(); 664 gcm_channel_status_syncer_->Stop();
665 } 665 }
666 } 666 }
667 667
668 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) { 668 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) {
669 connection_observer_list_.AddObserver(observer); 669 connection_observer_list_.AddObserver(observer);
670 } 670 }
671 671
672 void GCMDriverDesktop::RemoveConnectionObserver( 672 void GCMDriverDesktop::RemoveConnectionObserver(
673 GCMConnectionObserver* observer) { 673 GCMConnectionObserver* observer) {
674 connection_observer_list_.RemoveObserver(observer); 674 connection_observer_list_.RemoveObserver(observer);
675 } 675 }
676 676
677 void GCMDriverDesktop::Enable() { 677 void GCMDriverDesktop::Enable() {
678 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 678 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
679 679
680 if (gcm_enabled_) 680 if (gcm_enabled_)
681 return; 681 return;
682 gcm_enabled_ = true; 682 gcm_enabled_ = true;
683 683
684 EnsureStarted(GCMClient::DELAYED_START); 684 EnsureStarted(GCMClient::DELAYED_START);
685 } 685 }
686 686
687 void GCMDriverDesktop::Disable() { 687 void GCMDriverDesktop::Disable() {
688 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 688 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
689 689
690 if (!gcm_enabled_) 690 if (!gcm_enabled_)
691 return; 691 return;
692 gcm_enabled_ = false; 692 gcm_enabled_ = false;
693 693
694 Stop(); 694 Stop();
695 } 695 }
696 696
697 void GCMDriverDesktop::Stop() { 697 void GCMDriverDesktop::Stop() {
698 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 698 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
699 699
700 // No need to stop GCM service if not started yet. 700 // No need to stop GCM service if not started yet.
701 if (!gcm_started_) 701 if (!gcm_started_)
702 return; 702 return;
703 703
704 account_mapper_->ShutdownHandler(); 704 account_mapper_->ShutdownHandler();
705 GCMDriver::RemoveAppHandler(kGCMAccountMapperAppId); 705 GCMDriver::RemoveAppHandler(kGCMAccountMapperAppId);
706 706
707 RemoveCachedData(); 707 RemoveCachedData();
708 708
(...skipping 13 matching lines...) Expand all
722 app_id, 722 app_id,
723 sender_ids)); 723 sender_ids));
724 return; 724 return;
725 } 725 }
726 726
727 DoRegister(app_id, sender_ids); 727 DoRegister(app_id, sender_ids);
728 } 728 }
729 729
730 void GCMDriverDesktop::DoRegister(const std::string& app_id, 730 void GCMDriverDesktop::DoRegister(const std::string& app_id,
731 const std::vector<std::string>& sender_ids) { 731 const std::vector<std::string>& sender_ids) {
732 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 732 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
733 if (!HasRegisterCallback(app_id)) { 733 if (!HasRegisterCallback(app_id)) {
734 // The callback could have been removed when the app is uninstalled. 734 // The callback could have been removed when the app is uninstalled.
735 return; 735 return;
736 } 736 }
737 737
738 io_thread_->PostTask( 738 io_thread_->PostTask(
739 FROM_HERE, 739 FROM_HERE,
740 base::Bind(&GCMDriverDesktop::IOWorker::Register, 740 base::Bind(&GCMDriverDesktop::IOWorker::Register,
741 base::Unretained(io_worker_.get()), 741 base::Unretained(io_worker_.get()),
742 app_id, 742 app_id,
743 sender_ids)); 743 sender_ids));
744 } 744 }
745 745
746 void GCMDriverDesktop::UnregisterImpl(const std::string& app_id) { 746 void GCMDriverDesktop::UnregisterImpl(const std::string& app_id) {
747 // Delay the unregister operation until GCMClient is ready. 747 // Delay the unregister operation until GCMClient is ready.
748 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 748 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
749 delayed_task_controller_->AddTask( 749 delayed_task_controller_->AddTask(
750 base::Bind(&GCMDriverDesktop::DoUnregister, 750 base::Bind(&GCMDriverDesktop::DoUnregister,
751 weak_ptr_factory_.GetWeakPtr(), 751 weak_ptr_factory_.GetWeakPtr(),
752 app_id)); 752 app_id));
753 return; 753 return;
754 } 754 }
755 755
756 DoUnregister(app_id); 756 DoUnregister(app_id);
757 } 757 }
758 758
759 void GCMDriverDesktop::DoUnregister(const std::string& app_id) { 759 void GCMDriverDesktop::DoUnregister(const std::string& app_id) {
760 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 760 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
761 761
762 // Ask the server to unregister it. There could be a small chance that the 762 // Ask the server to unregister it. There could be a small chance that the
763 // unregister request fails. If this occurs, it does not bring any harm since 763 // unregister request fails. If this occurs, it does not bring any harm since
764 // we simply reject the messages/events received from the server. 764 // we simply reject the messages/events received from the server.
765 io_thread_->PostTask( 765 io_thread_->PostTask(
766 FROM_HERE, 766 FROM_HERE,
767 base::Bind(&GCMDriverDesktop::IOWorker::Unregister, 767 base::Bind(&GCMDriverDesktop::IOWorker::Unregister,
768 base::Unretained(io_worker_.get()), 768 base::Unretained(io_worker_.get()),
769 app_id)); 769 app_id));
770 } 770 }
(...skipping 10 matching lines...) Expand all
781 message)); 781 message));
782 return; 782 return;
783 } 783 }
784 784
785 DoSend(app_id, receiver_id, message); 785 DoSend(app_id, receiver_id, message);
786 } 786 }
787 787
788 void GCMDriverDesktop::DoSend(const std::string& app_id, 788 void GCMDriverDesktop::DoSend(const std::string& app_id,
789 const std::string& receiver_id, 789 const std::string& receiver_id,
790 const OutgoingMessage& message) { 790 const OutgoingMessage& message) {
791 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 791 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
792 io_thread_->PostTask( 792 io_thread_->PostTask(
793 FROM_HERE, 793 FROM_HERE,
794 base::Bind(&GCMDriverDesktop::IOWorker::Send, 794 base::Bind(&GCMDriverDesktop::IOWorker::Send,
795 base::Unretained(io_worker_.get()), 795 base::Unretained(io_worker_.get()),
796 app_id, 796 app_id,
797 receiver_id, 797 receiver_id,
798 message)); 798 message));
799 } 799 }
800 800
801 void GCMDriverDesktop::RecordDecryptionFailure( 801 void GCMDriverDesktop::RecordDecryptionFailure(
802 const std::string& app_id, 802 const std::string& app_id,
803 GCMEncryptionProvider::DecryptionResult result) { 803 GCMEncryptionProvider::DecryptionResult result) {
804 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 804 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
805 io_thread_->PostTask( 805 io_thread_->PostTask(
806 FROM_HERE, 806 FROM_HERE,
807 base::Bind(&GCMDriverDesktop::IOWorker::RecordDecryptionFailure, 807 base::Bind(&GCMDriverDesktop::IOWorker::RecordDecryptionFailure,
808 base::Unretained(io_worker_.get()), 808 base::Unretained(io_worker_.get()),
809 app_id, result)); 809 app_id, result));
810 } 810 }
811 811
812 GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const { 812 GCMClient* GCMDriverDesktop::GetGCMClientForTesting() const {
813 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 813 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
814 return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL; 814 return io_worker_ ? io_worker_->gcm_client_for_testing() : NULL;
815 } 815 }
816 816
817 bool GCMDriverDesktop::IsStarted() const { 817 bool GCMDriverDesktop::IsStarted() const {
818 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 818 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
819 return gcm_started_; 819 return gcm_started_;
820 } 820 }
821 821
822 bool GCMDriverDesktop::IsConnected() const { 822 bool GCMDriverDesktop::IsConnected() const {
823 return connected_; 823 return connected_;
824 } 824 }
825 825
826 void GCMDriverDesktop::GetGCMStatistics( 826 void GCMDriverDesktop::GetGCMStatistics(
827 const GetGCMStatisticsCallback& callback, 827 const GetGCMStatisticsCallback& callback,
828 ClearActivityLogs clear_logs) { 828 ClearActivityLogs clear_logs) {
829 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 829 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
830 DCHECK(!callback.is_null()); 830 DCHECK(!callback.is_null());
831 831
832 request_gcm_statistics_callback_ = callback; 832 request_gcm_statistics_callback_ = callback;
833 io_thread_->PostTask( 833 io_thread_->PostTask(
834 FROM_HERE, 834 FROM_HERE,
835 base::Bind(&GCMDriverDesktop::IOWorker::GetGCMStatistics, 835 base::Bind(&GCMDriverDesktop::IOWorker::GetGCMStatistics,
836 base::Unretained(io_worker_.get()), 836 base::Unretained(io_worker_.get()),
837 clear_logs)); 837 clear_logs));
838 } 838 }
839 839
840 void GCMDriverDesktop::SetGCMRecording(const GetGCMStatisticsCallback& callback, 840 void GCMDriverDesktop::SetGCMRecording(const GetGCMStatisticsCallback& callback,
841 bool recording) { 841 bool recording) {
842 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 842 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
843 843
844 request_gcm_statistics_callback_ = callback; 844 request_gcm_statistics_callback_ = callback;
845 io_thread_->PostTask( 845 io_thread_->PostTask(
846 FROM_HERE, 846 FROM_HERE,
847 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording, 847 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording,
848 base::Unretained(io_worker_.get()), 848 base::Unretained(io_worker_.get()),
849 recording)); 849 recording));
850 } 850 }
851 851
852 void GCMDriverDesktop::UpdateAccountMapping( 852 void GCMDriverDesktop::UpdateAccountMapping(
853 const AccountMapping& account_mapping) { 853 const AccountMapping& account_mapping) {
854 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 854 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
855 855
856 io_thread_->PostTask( 856 io_thread_->PostTask(
857 FROM_HERE, 857 FROM_HERE,
858 base::Bind(&GCMDriverDesktop::IOWorker::UpdateAccountMapping, 858 base::Bind(&GCMDriverDesktop::IOWorker::UpdateAccountMapping,
859 base::Unretained(io_worker_.get()), 859 base::Unretained(io_worker_.get()),
860 account_mapping)); 860 account_mapping));
861 } 861 }
862 862
863 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { 863 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) {
864 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 864 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
865 865
866 io_thread_->PostTask( 866 io_thread_->PostTask(
867 FROM_HERE, 867 FROM_HERE,
868 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, 868 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping,
869 base::Unretained(io_worker_.get()), 869 base::Unretained(io_worker_.get()),
870 account_id)); 870 account_id));
871 } 871 }
872 872
873 base::Time GCMDriverDesktop::GetLastTokenFetchTime() { 873 base::Time GCMDriverDesktop::GetLastTokenFetchTime() {
874 return last_token_fetch_time_; 874 return last_token_fetch_time_;
875 } 875 }
876 876
877 void GCMDriverDesktop::SetLastTokenFetchTime(const base::Time& time) { 877 void GCMDriverDesktop::SetLastTokenFetchTime(const base::Time& time) {
878 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 878 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
879 879
880 last_token_fetch_time_ = time; 880 last_token_fetch_time_ = time;
881 881
882 io_thread_->PostTask( 882 io_thread_->PostTask(
883 FROM_HERE, 883 FROM_HERE,
884 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, 884 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime,
885 base::Unretained(io_worker_.get()), 885 base::Unretained(io_worker_.get()),
886 time)); 886 time));
887 } 887 }
888 888
889 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandlerInternal() { 889 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandlerInternal() {
890 return this; 890 return this;
891 } 891 }
892 892
893 void GCMDriverDesktop::GetToken( 893 void GCMDriverDesktop::GetToken(
894 const std::string& app_id, 894 const std::string& app_id,
895 const std::string& authorized_entity, 895 const std::string& authorized_entity,
896 const std::string& scope, 896 const std::string& scope,
897 const std::map<std::string, std::string>& options, 897 const std::map<std::string, std::string>& options,
898 const GetTokenCallback& callback) { 898 const GetTokenCallback& callback) {
899 DCHECK(!app_id.empty()); 899 DCHECK(!app_id.empty());
900 DCHECK(!authorized_entity.empty()); 900 DCHECK(!authorized_entity.empty());
901 DCHECK(!scope.empty()); 901 DCHECK(!scope.empty());
902 DCHECK(!callback.is_null()); 902 DCHECK(!callback.is_null());
903 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 903 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
904 904
905 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 905 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
906 if (result != GCMClient::SUCCESS) { 906 if (result != GCMClient::SUCCESS) {
907 callback.Run(std::string(), result); 907 callback.Run(std::string(), result);
908 return; 908 return;
909 } 909 }
910 910
911 // If previous GetToken operation is still in progress, bail out. 911 // If previous GetToken operation is still in progress, bail out.
912 TokenTuple tuple_key(app_id, authorized_entity, scope); 912 TokenTuple tuple_key(app_id, authorized_entity, scope);
913 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) { 913 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) {
(...skipping 16 matching lines...) Expand all
930 } 930 }
931 931
932 DoGetToken(app_id, authorized_entity, scope, options); 932 DoGetToken(app_id, authorized_entity, scope, options);
933 } 933 }
934 934
935 void GCMDriverDesktop::DoGetToken( 935 void GCMDriverDesktop::DoGetToken(
936 const std::string& app_id, 936 const std::string& app_id,
937 const std::string& authorized_entity, 937 const std::string& authorized_entity,
938 const std::string& scope, 938 const std::string& scope,
939 const std::map<std::string, std::string>& options) { 939 const std::map<std::string, std::string>& options) {
940 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 940 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
941 941
942 TokenTuple tuple_key(app_id, authorized_entity, scope); 942 TokenTuple tuple_key(app_id, authorized_entity, scope);
943 auto callback_iter = get_token_callbacks_.find(tuple_key); 943 auto callback_iter = get_token_callbacks_.find(tuple_key);
944 if (callback_iter == get_token_callbacks_.end()) { 944 if (callback_iter == get_token_callbacks_.end()) {
945 // The callback could have been removed when the app is uninstalled. 945 // The callback could have been removed when the app is uninstalled.
946 return; 946 return;
947 } 947 }
948 948
949 io_thread_->PostTask( 949 io_thread_->PostTask(
950 FROM_HERE, 950 FROM_HERE,
951 base::Bind(&GCMDriverDesktop::IOWorker::GetToken, 951 base::Bind(&GCMDriverDesktop::IOWorker::GetToken,
952 base::Unretained(io_worker_.get()), 952 base::Unretained(io_worker_.get()),
953 app_id, 953 app_id,
954 authorized_entity, 954 authorized_entity,
955 scope, 955 scope,
956 options)); 956 options));
957 } 957 }
958 958
959 void GCMDriverDesktop::ValidateToken(const std::string& app_id, 959 void GCMDriverDesktop::ValidateToken(const std::string& app_id,
960 const std::string& authorized_entity, 960 const std::string& authorized_entity,
961 const std::string& scope, 961 const std::string& scope,
962 const std::string& token, 962 const std::string& token,
963 const ValidateTokenCallback& callback) { 963 const ValidateTokenCallback& callback) {
964 DCHECK(!app_id.empty()); 964 DCHECK(!app_id.empty());
965 DCHECK(!authorized_entity.empty()); 965 DCHECK(!authorized_entity.empty());
966 DCHECK(!scope.empty()); 966 DCHECK(!scope.empty());
967 DCHECK(!token.empty()); 967 DCHECK(!token.empty());
968 DCHECK(!callback.is_null()); 968 DCHECK(!callback.is_null());
969 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 969 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
970 970
971 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 971 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
972 if (result != GCMClient::SUCCESS) { 972 if (result != GCMClient::SUCCESS) {
973 // Can't tell whether the registration is valid or not, so don't run the 973 // Can't tell whether the registration is valid or not, so don't run the
974 // callback (let it hang indefinitely). 974 // callback (let it hang indefinitely).
975 return; 975 return;
976 } 976 }
977 977
978 // Only validating current state, so ignore pending get_token_callbacks_. 978 // Only validating current state, so ignore pending get_token_callbacks_.
979 979
(...skipping 14 matching lines...) Expand all
994 } 994 }
995 995
996 void GCMDriverDesktop::DeleteToken(const std::string& app_id, 996 void GCMDriverDesktop::DeleteToken(const std::string& app_id,
997 const std::string& authorized_entity, 997 const std::string& authorized_entity,
998 const std::string& scope, 998 const std::string& scope,
999 const DeleteTokenCallback& callback) { 999 const DeleteTokenCallback& callback) {
1000 DCHECK(!app_id.empty()); 1000 DCHECK(!app_id.empty());
1001 DCHECK(!authorized_entity.empty()); 1001 DCHECK(!authorized_entity.empty());
1002 DCHECK(!scope.empty()); 1002 DCHECK(!scope.empty());
1003 DCHECK(!callback.is_null()); 1003 DCHECK(!callback.is_null());
1004 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1004 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1005 1005
1006 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 1006 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
1007 if (result != GCMClient::SUCCESS) { 1007 if (result != GCMClient::SUCCESS) {
1008 callback.Run(result); 1008 callback.Run(result);
1009 return; 1009 return;
1010 } 1010 }
1011 1011
1012 // If previous GetToken operation is still in progress, bail out. 1012 // If previous GetToken operation is still in progress, bail out.
1013 TokenTuple tuple_key(app_id, authorized_entity, scope); 1013 TokenTuple tuple_key(app_id, authorized_entity, scope);
1014 if (delete_token_callbacks_.find(tuple_key) != 1014 if (delete_token_callbacks_.find(tuple_key) !=
(...skipping 14 matching lines...) Expand all
1029 scope)); 1029 scope));
1030 return; 1030 return;
1031 } 1031 }
1032 1032
1033 DoDeleteToken(app_id, authorized_entity, scope); 1033 DoDeleteToken(app_id, authorized_entity, scope);
1034 } 1034 }
1035 1035
1036 void GCMDriverDesktop::DoDeleteToken(const std::string& app_id, 1036 void GCMDriverDesktop::DoDeleteToken(const std::string& app_id,
1037 const std::string& authorized_entity, 1037 const std::string& authorized_entity,
1038 const std::string& scope) { 1038 const std::string& scope) {
1039 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1039 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1040 1040
1041 io_thread_->PostTask( 1041 io_thread_->PostTask(
1042 FROM_HERE, 1042 FROM_HERE,
1043 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken, 1043 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken,
1044 base::Unretained(io_worker_.get()), 1044 base::Unretained(io_worker_.get()),
1045 app_id, 1045 app_id,
1046 authorized_entity, 1046 authorized_entity,
1047 scope)); 1047 scope));
1048 } 1048 }
1049 1049
1050 void GCMDriverDesktop::AddInstanceIDData( 1050 void GCMDriverDesktop::AddInstanceIDData(
1051 const std::string& app_id, 1051 const std::string& app_id,
1052 const std::string& instance_id, 1052 const std::string& instance_id,
1053 const std::string& extra_data) { 1053 const std::string& extra_data) {
1054 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1054 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1055 1055
1056 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 1056 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
1057 if (result != GCMClient::SUCCESS) 1057 if (result != GCMClient::SUCCESS)
1058 return; 1058 return;
1059 1059
1060 // Delay the operation until GCMClient is ready. 1060 // Delay the operation until GCMClient is ready.
1061 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 1061 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
1062 delayed_task_controller_->AddTask( 1062 delayed_task_controller_->AddTask(
1063 base::Bind(&GCMDriverDesktop::DoAddInstanceIDData, 1063 base::Bind(&GCMDriverDesktop::DoAddInstanceIDData,
1064 weak_ptr_factory_.GetWeakPtr(), 1064 weak_ptr_factory_.GetWeakPtr(),
(...skipping 13 matching lines...) Expand all
1078 io_thread_->PostTask( 1078 io_thread_->PostTask(
1079 FROM_HERE, 1079 FROM_HERE,
1080 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData, 1080 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData,
1081 base::Unretained(io_worker_.get()), 1081 base::Unretained(io_worker_.get()),
1082 app_id, 1082 app_id,
1083 instance_id, 1083 instance_id,
1084 extra_data)); 1084 extra_data));
1085 } 1085 }
1086 1086
1087 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { 1087 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) {
1088 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1088 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1089 1089
1090 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 1090 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
1091 if (result != GCMClient::SUCCESS) 1091 if (result != GCMClient::SUCCESS)
1092 return; 1092 return;
1093 1093
1094 // Delay the operation until GCMClient is ready. 1094 // Delay the operation until GCMClient is ready.
1095 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 1095 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
1096 delayed_task_controller_->AddTask( 1096 delayed_task_controller_->AddTask(
1097 base::Bind(&GCMDriverDesktop::DoRemoveInstanceIDData, 1097 base::Bind(&GCMDriverDesktop::DoRemoveInstanceIDData,
1098 weak_ptr_factory_.GetWeakPtr(), 1098 weak_ptr_factory_.GetWeakPtr(),
1099 app_id)); 1099 app_id));
1100 return; 1100 return;
1101 } 1101 }
1102 1102
1103 DoRemoveInstanceIDData(app_id); 1103 DoRemoveInstanceIDData(app_id);
1104 } 1104 }
1105 1105
1106 void GCMDriverDesktop::DoRemoveInstanceIDData(const std::string& app_id) { 1106 void GCMDriverDesktop::DoRemoveInstanceIDData(const std::string& app_id) {
1107 io_thread_->PostTask( 1107 io_thread_->PostTask(
1108 FROM_HERE, 1108 FROM_HERE,
1109 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData, 1109 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData,
1110 base::Unretained(io_worker_.get()), 1110 base::Unretained(io_worker_.get()),
1111 app_id)); 1111 app_id));
1112 } 1112 }
1113 1113
1114 void GCMDriverDesktop::GetInstanceIDData( 1114 void GCMDriverDesktop::GetInstanceIDData(
1115 const std::string& app_id, 1115 const std::string& app_id,
1116 const GetInstanceIDDataCallback& callback) { 1116 const GetInstanceIDDataCallback& callback) {
1117 DCHECK(!get_instance_id_data_callbacks_.count(app_id)); 1117 DCHECK(!get_instance_id_data_callbacks_.count(app_id));
1118 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1118 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1119 1119
1120 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); 1120 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
1121 if (result != GCMClient::SUCCESS) { 1121 if (result != GCMClient::SUCCESS) {
1122 base::ThreadTaskRunnerHandle::Get()->PostTask( 1122 base::ThreadTaskRunnerHandle::Get()->PostTask(
1123 FROM_HERE, base::Bind(callback, std::string(), std::string())); 1123 FROM_HERE, base::Bind(callback, std::string(), std::string()));
1124 return; 1124 return;
1125 } 1125 }
1126 1126
1127 get_instance_id_data_callbacks_[app_id] = callback; 1127 get_instance_id_data_callbacks_[app_id] = callback;
1128 1128
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 // The callback could have been removed when the app is uninstalled. 1182 // The callback could have been removed when the app is uninstalled.
1183 return; 1183 return;
1184 } 1184 }
1185 1185
1186 DeleteTokenCallback callback = callback_iter->second; 1186 DeleteTokenCallback callback = callback_iter->second;
1187 delete_token_callbacks_.erase(callback_iter); 1187 delete_token_callbacks_.erase(callback_iter);
1188 callback.Run(result); 1188 callback.Run(result);
1189 } 1189 }
1190 1190
1191 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { 1191 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) {
1192 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1192 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1193 1193
1194 wake_from_suspend_enabled_ = wake; 1194 wake_from_suspend_enabled_ = wake;
1195 1195
1196 // The GCM service has not been initialized. 1196 // The GCM service has not been initialized.
1197 if (!delayed_task_controller_) 1197 if (!delayed_task_controller_)
1198 return; 1198 return;
1199 1199
1200 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 1200 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
1201 // The GCM service was initialized but has not started yet. 1201 // The GCM service was initialized but has not started yet.
1202 delayed_task_controller_->AddTask( 1202 delayed_task_controller_->AddTask(
1203 base::Bind(&GCMDriverDesktop::WakeFromSuspendForHeartbeat, 1203 base::Bind(&GCMDriverDesktop::WakeFromSuspendForHeartbeat,
1204 weak_ptr_factory_.GetWeakPtr(), 1204 weak_ptr_factory_.GetWeakPtr(),
1205 wake_from_suspend_enabled_)); 1205 wake_from_suspend_enabled_));
1206 return; 1206 return;
1207 } 1207 }
1208 1208
1209 // The GCMClient is ready so we can go ahead and post this task to the 1209 // The GCMClient is ready so we can go ahead and post this task to the
1210 // IOWorker. 1210 // IOWorker.
1211 io_thread_->PostTask( 1211 io_thread_->PostTask(
1212 FROM_HERE, 1212 FROM_HERE,
1213 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat, 1213 base::Bind(&GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat,
1214 base::Unretained(io_worker_.get()), 1214 base::Unretained(io_worker_.get()),
1215 wake_from_suspend_enabled_)); 1215 wake_from_suspend_enabled_));
1216 } 1216 }
1217 1217
1218 void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope, 1218 void GCMDriverDesktop::AddHeartbeatInterval(const std::string& scope,
1219 int interval_ms) { 1219 int interval_ms) {
1220 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1220 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1221 1221
1222 // The GCM service has not been initialized. 1222 // The GCM service has not been initialized.
1223 if (!delayed_task_controller_) 1223 if (!delayed_task_controller_)
1224 return; 1224 return;
1225 1225
1226 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 1226 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
1227 // The GCM service was initialized but has not started yet. 1227 // The GCM service was initialized but has not started yet.
1228 delayed_task_controller_->AddTask( 1228 delayed_task_controller_->AddTask(
1229 base::Bind(&GCMDriverDesktop::AddHeartbeatInterval, 1229 base::Bind(&GCMDriverDesktop::AddHeartbeatInterval,
1230 weak_ptr_factory_.GetWeakPtr(), scope, interval_ms)); 1230 weak_ptr_factory_.GetWeakPtr(), scope, interval_ms));
1231 return; 1231 return;
1232 } 1232 }
1233 1233
1234 io_thread_->PostTask( 1234 io_thread_->PostTask(
1235 FROM_HERE, 1235 FROM_HERE,
1236 base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval, 1236 base::Bind(&GCMDriverDesktop::IOWorker::AddHeartbeatInterval,
1237 base::Unretained(io_worker_.get()), scope, interval_ms)); 1237 base::Unretained(io_worker_.get()), scope, interval_ms));
1238 } 1238 }
1239 1239
1240 void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) { 1240 void GCMDriverDesktop::RemoveHeartbeatInterval(const std::string& scope) {
1241 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1241 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1242 1242
1243 // The GCM service has not been initialized. 1243 // The GCM service has not been initialized.
1244 if (!delayed_task_controller_) 1244 if (!delayed_task_controller_)
1245 return; 1245 return;
1246 1246
1247 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 1247 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
1248 // The GCM service was initialized but has not started yet. 1248 // The GCM service was initialized but has not started yet.
1249 delayed_task_controller_->AddTask( 1249 delayed_task_controller_->AddTask(
1250 base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval, 1250 base::Bind(&GCMDriverDesktop::RemoveHeartbeatInterval,
1251 weak_ptr_factory_.GetWeakPtr(), scope)); 1251 weak_ptr_factory_.GetWeakPtr(), scope));
1252 return; 1252 return;
1253 } 1253 }
1254 1254
1255 io_thread_->PostTask( 1255 io_thread_->PostTask(
1256 FROM_HERE, 1256 FROM_HERE,
1257 base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval, 1257 base::Bind(&GCMDriverDesktop::IOWorker::RemoveHeartbeatInterval,
1258 base::Unretained(io_worker_.get()), scope)); 1258 base::Unretained(io_worker_.get()), scope));
1259 } 1259 }
1260 1260
1261 void GCMDriverDesktop::SetAccountTokens( 1261 void GCMDriverDesktop::SetAccountTokens(
1262 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { 1262 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
1263 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1263 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1264 1264
1265 account_mapper_->SetAccountTokens(account_tokens); 1265 account_mapper_->SetAccountTokens(account_tokens);
1266 1266
1267 io_thread_->PostTask( 1267 io_thread_->PostTask(
1268 FROM_HERE, 1268 FROM_HERE,
1269 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, 1269 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens,
1270 base::Unretained(io_worker_.get()), 1270 base::Unretained(io_worker_.get()),
1271 account_tokens)); 1271 account_tokens));
1272 } 1272 }
1273 1273
1274 GCMClient::Result GCMDriverDesktop::EnsureStarted( 1274 GCMClient::Result GCMDriverDesktop::EnsureStarted(
1275 GCMClient::StartMode start_mode) { 1275 GCMClient::StartMode start_mode) {
1276 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1276 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1277 1277
1278 if (gcm_started_) 1278 if (gcm_started_)
1279 return GCMClient::SUCCESS; 1279 return GCMClient::SUCCESS;
1280 1280
1281 // Have any app requested the service? 1281 // Have any app requested the service?
1282 if (app_handlers().empty()) 1282 if (app_handlers().empty())
1283 return GCMClient::UNKNOWN_ERROR; 1283 return GCMClient::UNKNOWN_ERROR;
1284 1284
1285 // Polling for channel status should be invoked when GCM is being requested, 1285 // Polling for channel status should be invoked when GCM is being requested,
1286 // no matter whether GCM is enabled or nor. 1286 // no matter whether GCM is enabled or nor.
(...skipping 11 matching lines...) Expand all
1298 FROM_HERE, 1298 FROM_HERE,
1299 base::Bind(&GCMDriverDesktop::IOWorker::Start, 1299 base::Bind(&GCMDriverDesktop::IOWorker::Start,
1300 base::Unretained(io_worker_.get()), 1300 base::Unretained(io_worker_.get()),
1301 start_mode, 1301 start_mode,
1302 weak_ptr_factory_.GetWeakPtr())); 1302 weak_ptr_factory_.GetWeakPtr()));
1303 1303
1304 return GCMClient::SUCCESS; 1304 return GCMClient::SUCCESS;
1305 } 1305 }
1306 1306
1307 void GCMDriverDesktop::RemoveCachedData() { 1307 void GCMDriverDesktop::RemoveCachedData() {
1308 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1308 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1309 // Remove all the queued tasks since they no longer make sense after 1309 // Remove all the queued tasks since they no longer make sense after
1310 // GCM service is stopped. 1310 // GCM service is stopped.
1311 weak_ptr_factory_.InvalidateWeakPtrs(); 1311 weak_ptr_factory_.InvalidateWeakPtrs();
1312 1312
1313 gcm_started_ = false; 1313 gcm_started_ = false;
1314 delayed_task_controller_.reset(); 1314 delayed_task_controller_.reset();
1315 ClearCallbacks(); 1315 ClearCallbacks();
1316 } 1316 }
1317 1317
1318 void GCMDriverDesktop::MessageReceived(const std::string& app_id, 1318 void GCMDriverDesktop::MessageReceived(const std::string& app_id,
1319 const IncomingMessage& message) { 1319 const IncomingMessage& message) {
1320 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1320 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1321 1321
1322 // Drop the event if the service has been stopped. 1322 // Drop the event if the service has been stopped.
1323 if (!gcm_started_) 1323 if (!gcm_started_)
1324 return; 1324 return;
1325 1325
1326 DispatchMessage(app_id, message); 1326 DispatchMessage(app_id, message);
1327 } 1327 }
1328 1328
1329 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) { 1329 void GCMDriverDesktop::MessagesDeleted(const std::string& app_id) {
1330 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1330 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1331 1331
1332 // Drop the event if the service has been stopped. 1332 // Drop the event if the service has been stopped.
1333 if (!gcm_started_) 1333 if (!gcm_started_)
1334 return; 1334 return;
1335 1335
1336 GCMAppHandler* handler = GetAppHandler(app_id); 1336 GCMAppHandler* handler = GetAppHandler(app_id);
1337 if (handler) 1337 if (handler)
1338 handler->OnMessagesDeleted(app_id); 1338 handler->OnMessagesDeleted(app_id);
1339 } 1339 }
1340 1340
1341 void GCMDriverDesktop::MessageSendError( 1341 void GCMDriverDesktop::MessageSendError(
1342 const std::string& app_id, 1342 const std::string& app_id,
1343 const GCMClient::SendErrorDetails& send_error_details) { 1343 const GCMClient::SendErrorDetails& send_error_details) {
1344 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1344 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1345 1345
1346 // Drop the event if the service has been stopped. 1346 // Drop the event if the service has been stopped.
1347 if (!gcm_started_) 1347 if (!gcm_started_)
1348 return; 1348 return;
1349 1349
1350 GCMAppHandler* handler = GetAppHandler(app_id); 1350 GCMAppHandler* handler = GetAppHandler(app_id);
1351 if (handler) 1351 if (handler)
1352 handler->OnSendError(app_id, send_error_details); 1352 handler->OnSendError(app_id, send_error_details);
1353 } 1353 }
1354 1354
1355 void GCMDriverDesktop::SendAcknowledged(const std::string& app_id, 1355 void GCMDriverDesktop::SendAcknowledged(const std::string& app_id,
1356 const std::string& message_id) { 1356 const std::string& message_id) {
1357 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1357 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1358 1358
1359 // Drop the event if the service has been stopped. 1359 // Drop the event if the service has been stopped.
1360 if (!gcm_started_) 1360 if (!gcm_started_)
1361 return; 1361 return;
1362 1362
1363 GCMAppHandler* handler = GetAppHandler(app_id); 1363 GCMAppHandler* handler = GetAppHandler(app_id);
1364 if (handler) 1364 if (handler)
1365 handler->OnSendAcknowledged(app_id, message_id); 1365 handler->OnSendAcknowledged(app_id, message_id);
1366 } 1366 }
1367 1367
1368 void GCMDriverDesktop::GCMClientReady( 1368 void GCMDriverDesktop::GCMClientReady(
1369 const std::vector<AccountMapping>& account_mappings, 1369 const std::vector<AccountMapping>& account_mappings,
1370 const base::Time& last_token_fetch_time) { 1370 const base::Time& last_token_fetch_time) {
1371 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1371 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1372 1372
1373 UMA_HISTOGRAM_BOOLEAN("GCM.UserSignedIn", signed_in_); 1373 UMA_HISTOGRAM_BOOLEAN("GCM.UserSignedIn", signed_in_);
1374 1374
1375 gcm_started_ = true; 1375 gcm_started_ = true;
1376 if (wake_from_suspend_enabled_) 1376 if (wake_from_suspend_enabled_)
1377 WakeFromSuspendForHeartbeat(wake_from_suspend_enabled_); 1377 WakeFromSuspendForHeartbeat(wake_from_suspend_enabled_);
1378 1378
1379 last_token_fetch_time_ = last_token_fetch_time; 1379 last_token_fetch_time_ = last_token_fetch_time;
1380 1380
1381 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get()); 1381 GCMDriver::AddAppHandler(kGCMAccountMapperAppId, account_mapper_.get());
1382 account_mapper_->Initialize(account_mappings, 1382 account_mapper_->Initialize(account_mappings,
1383 base::Bind(&GCMDriverDesktop::MessageReceived, 1383 base::Bind(&GCMDriverDesktop::MessageReceived,
1384 weak_ptr_factory_.GetWeakPtr())); 1384 weak_ptr_factory_.GetWeakPtr()));
1385 1385
1386 delayed_task_controller_->SetReady(); 1386 delayed_task_controller_->SetReady();
1387 } 1387 }
1388 1388
1389 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { 1389 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) {
1390 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1390 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1391 1391
1392 connected_ = true; 1392 connected_ = true;
1393 1393
1394 // Drop the event if the service has been stopped. 1394 // Drop the event if the service has been stopped.
1395 if (!gcm_started_) 1395 if (!gcm_started_)
1396 return; 1396 return;
1397 1397
1398 for (GCMConnectionObserver& observer : connection_observer_list_) 1398 for (GCMConnectionObserver& observer : connection_observer_list_)
1399 observer.OnConnected(ip_endpoint); 1399 observer.OnConnected(ip_endpoint);
1400 } 1400 }
1401 1401
1402 void GCMDriverDesktop::OnDisconnected() { 1402 void GCMDriverDesktop::OnDisconnected() {
1403 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1403 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1404 1404
1405 connected_ = false; 1405 connected_ = false;
1406 1406
1407 // Drop the event if the service has been stopped. 1407 // Drop the event if the service has been stopped.
1408 if (!gcm_started_) 1408 if (!gcm_started_)
1409 return; 1409 return;
1410 1410
1411 for (GCMConnectionObserver& observer : connection_observer_list_) 1411 for (GCMConnectionObserver& observer : connection_observer_list_)
1412 observer.OnDisconnected(); 1412 observer.OnDisconnected();
1413 } 1413 }
1414 1414
1415 void GCMDriverDesktop::OnStoreReset() { 1415 void GCMDriverDesktop::OnStoreReset() {
1416 // Defensive copy in case OnStoreReset calls Add/RemoveAppHandler. 1416 // Defensive copy in case OnStoreReset calls Add/RemoveAppHandler.
1417 std::vector<GCMAppHandler*> app_handler_values; 1417 std::vector<GCMAppHandler*> app_handler_values;
1418 for (const auto& key_value : app_handlers()) 1418 for (const auto& key_value : app_handlers())
1419 app_handler_values.push_back(key_value.second); 1419 app_handler_values.push_back(key_value.second);
1420 for (GCMAppHandler* app_handler : app_handler_values) { 1420 for (GCMAppHandler* app_handler : app_handler_values) {
1421 app_handler->OnStoreReset(); 1421 app_handler->OnStoreReset();
1422 // app_handler might now have been deleted. 1422 // app_handler might now have been deleted.
1423 } 1423 }
1424 } 1424 }
1425 1425
1426 void GCMDriverDesktop::GetGCMStatisticsFinished( 1426 void GCMDriverDesktop::GetGCMStatisticsFinished(
1427 const GCMClient::GCMStatistics& stats) { 1427 const GCMClient::GCMStatistics& stats) {
1428 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1428 DCHECK(ui_thread_->RunsTasksInCurrentSequence());
1429 1429
1430 // request_gcm_statistics_callback_ could be null when an activity, i.e. 1430 // request_gcm_statistics_callback_ could be null when an activity, i.e.
1431 // network activity, is triggered while gcm-intenals page is not open. 1431 // network activity, is triggered while gcm-intenals page is not open.
1432 if (!request_gcm_statistics_callback_.is_null()) 1432 if (!request_gcm_statistics_callback_.is_null())
1433 request_gcm_statistics_callback_.Run(stats); 1433 request_gcm_statistics_callback_.Run(stats);
1434 } 1434 }
1435 1435
1436 bool GCMDriverDesktop::TokenTupleComparer::operator()( 1436 bool GCMDriverDesktop::TokenTupleComparer::operator()(
1437 const TokenTuple& a, const TokenTuple& b) const { 1437 const TokenTuple& a, const TokenTuple& b) const {
1438 if (std::get<0>(a) < std::get<0>(b)) 1438 if (std::get<0>(a) < std::get<0>(b))
1439 return true; 1439 return true;
1440 if (std::get<0>(a) > std::get<0>(b)) 1440 if (std::get<0>(a) > std::get<0>(b))
1441 return false; 1441 return false;
1442 1442
1443 if (std::get<1>(a) < std::get<1>(b)) 1443 if (std::get<1>(a) < std::get<1>(b))
1444 return true; 1444 return true;
1445 if (std::get<1>(a) > std::get<1>(b)) 1445 if (std::get<1>(a) > std::get<1>(b))
1446 return false; 1446 return false;
1447 1447
1448 return std::get<2>(a) < std::get<2>(b); 1448 return std::get<2>(a) < std::get<2>(b);
1449 } 1449 }
1450 1450
1451 } // namespace gcm 1451 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/fake_gcm_client.cc ('k') | components/history/core/browser/top_sites_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698