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

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

Issue 618003002: [GCM] Handling connection events in GCMAccountTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to Jian Li's patch and addressing unit tests failures Created 6 years, 2 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 const scoped_refptr<net::URLRequestContextGetter>& request_context, 340 const scoped_refptr<net::URLRequestContextGetter>& request_context,
341 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 341 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
342 const scoped_refptr<base::SequencedTaskRunner>& io_thread, 342 const scoped_refptr<base::SequencedTaskRunner>& io_thread,
343 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) 343 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
344 : gcm_channel_status_syncer_( 344 : gcm_channel_status_syncer_(
345 new GCMChannelStatusSyncer(this, prefs, request_context)), 345 new GCMChannelStatusSyncer(this, prefs, request_context)),
346 signed_in_(false), 346 signed_in_(false),
347 gcm_started_(false), 347 gcm_started_(false),
348 gcm_enabled_(true), 348 gcm_enabled_(true),
349 connected_(false), 349 connected_(false),
350 account_mapper_(new GCMAccountMapper(this)),
350 ui_thread_(ui_thread), 351 ui_thread_(ui_thread),
351 io_thread_(io_thread), 352 io_thread_(io_thread),
352 weak_ptr_factory_(this) { 353 weak_ptr_factory_(this) {
353 gcm_enabled_ = gcm_channel_status_syncer_->gcm_enabled(); 354 gcm_enabled_ = gcm_channel_status_syncer_->gcm_enabled();
354 355
355 // Create and initialize the GCMClient. Note that this does not initiate the 356 // Create and initialize the GCMClient. Note that this does not initiate the
356 // GCM check-in. 357 // GCM check-in.
357 io_worker_.reset(new IOWorker(ui_thread, io_thread)); 358 io_worker_.reset(new IOWorker(ui_thread, io_thread));
358 io_thread_->PostTask( 359 io_thread_->PostTask(
359 FROM_HERE, 360 FROM_HERE,
(...skipping 24 matching lines...) Expand all
384 void GCMDriverDesktop::OnSignedIn() { 385 void GCMDriverDesktop::OnSignedIn() {
385 signed_in_ = true; 386 signed_in_ = true;
386 EnsureStarted(); 387 EnsureStarted();
387 } 388 }
388 389
389 void GCMDriverDesktop::OnSignedOut() { 390 void GCMDriverDesktop::OnSignedOut() {
390 signed_in_ = false; 391 signed_in_ = false;
391 392
392 // When sign-in enforcement is not dropped, we will stop the GCM connection 393 // When sign-in enforcement is not dropped, we will stop the GCM connection
393 // when the user signs out. 394 // when the user signs out.
394 if (!GCMDriver::IsAllowedForAllUsers()) 395 if (!GCMDriver::IsAllowedForAllUsers()) {
395 Stop(); 396 Stop();
397 }
396 } 398 }
397 399
398 void GCMDriverDesktop::Purge() { 400 void GCMDriverDesktop::Purge() {
399 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 401 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
400 402
401 RemoveCachedData(); 403 RemoveCachedData();
402 404
403 io_thread_->PostTask(FROM_HERE, 405 io_thread_->PostTask(FROM_HERE,
404 base::Bind(&GCMDriverDesktop::IOWorker::CheckOut, 406 base::Bind(&GCMDriverDesktop::IOWorker::CheckOut,
405 base::Unretained(io_worker_.get()))); 407 base::Unretained(io_worker_.get())));
406 } 408 }
407 409
408 void GCMDriverDesktop::AddAppHandler(const std::string& app_id, 410 void GCMDriverDesktop::AddAppHandler(const std::string& app_id,
409 GCMAppHandler* handler) { 411 GCMAppHandler* handler) {
410 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 412 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
411 GCMDriver::AddAppHandler(app_id, handler); 413 GCMDriver::AddAppHandler(app_id, handler);
412 414
413 // Ensures that the GCM service is started when there is an interest. 415 // Ensures that the GCM service is started when there is an interest.
414 EnsureStarted(); 416 EnsureStarted();
415 } 417 }
416 418
417 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { 419 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) {
418 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 420 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
419 GCMDriver::RemoveAppHandler(app_id); 421 GCMDriver::RemoveAppHandler(app_id);
420 422
421 // Stops the GCM service when no app intends to consume it. 423 // Stops the GCM service when no app intends to consume it. Stop function will
422 if (app_handlers().empty()) 424 // remove the last app handler - account mapper.
425 if (app_handlers().size() == 1) {
423 Stop(); 426 Stop();
427 }
424 } 428 }
425 429
426 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) { 430 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) {
427 connection_observer_list_.AddObserver(observer); 431 connection_observer_list_.AddObserver(observer);
428 } 432 }
429 433
430 void GCMDriverDesktop::RemoveConnectionObserver( 434 void GCMDriverDesktop::RemoveConnectionObserver(
431 GCMConnectionObserver* observer) { 435 GCMConnectionObserver* observer) {
432 connection_observer_list_.RemoveObserver(observer); 436 connection_observer_list_.RemoveObserver(observer);
433 } 437 }
(...skipping 20 matching lines...) Expand all
454 458
455 void GCMDriverDesktop::Stop() { 459 void GCMDriverDesktop::Stop() {
456 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 460 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
457 461
458 // No need to stop GCM service if not started yet. 462 // No need to stop GCM service if not started yet.
459 if (!gcm_started_) 463 if (!gcm_started_)
460 return; 464 return;
461 465
462 gcm_channel_status_syncer_->Stop(); 466 gcm_channel_status_syncer_->Stop();
463 467
468 account_mapper_->ShutdownHandler();
469 GCMDriver::RemoveAppHandler(kGCMAccountMapperAppId);
470
464 RemoveCachedData(); 471 RemoveCachedData();
465 472
466 io_thread_->PostTask( 473 io_thread_->PostTask(
467 FROM_HERE, 474 FROM_HERE,
468 base::Bind(&GCMDriverDesktop::IOWorker::Stop, 475 base::Bind(&GCMDriverDesktop::IOWorker::Stop,
469 base::Unretained(io_worker_.get()))); 476 base::Unretained(io_worker_.get())));
470 } 477 }
471 478
472 void GCMDriverDesktop::RegisterImpl( 479 void GCMDriverDesktop::RegisterImpl(
473 const std::string& app_id, 480 const std::string& app_id,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 FROM_HERE, 620 FROM_HERE,
614 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, 621 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping,
615 base::Unretained(io_worker_.get()), 622 base::Unretained(io_worker_.get()),
616 account_id)); 623 account_id));
617 } 624 }
618 625
619 void GCMDriverDesktop::SetAccountTokens( 626 void GCMDriverDesktop::SetAccountTokens(
620 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { 627 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
621 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 628 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
622 629
630 account_mapper_->SetAccountTokens(account_tokens);
631
623 io_thread_->PostTask( 632 io_thread_->PostTask(
624 FROM_HERE, 633 FROM_HERE,
625 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, 634 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens,
626 base::Unretained(io_worker_.get()), 635 base::Unretained(io_worker_.get()),
627 account_tokens)); 636 account_tokens));
628 } 637 }
629 638
630 GCMClient::Result GCMDriverDesktop::EnsureStarted() { 639 GCMClient::Result GCMDriverDesktop::EnsureStarted() {
631 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 640 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
632 641
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 if (!gcm_started_) 728 if (!gcm_started_)
720 return; 729 return;
721 730
722 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); 731 GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id);
723 } 732 }
724 733
725 void GCMDriverDesktop::GCMClientReady( 734 void GCMDriverDesktop::GCMClientReady(
726 const std::vector<AccountMapping>& account_mappings) { 735 const std::vector<AccountMapping>& account_mappings) {
727 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 736 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
728 737
738 account_mapper_->Initialize(account_mappings);
739
729 delayed_task_controller_->SetReady(); 740 delayed_task_controller_->SetReady();
730 } 741 }
731 742
732 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) { 743 void GCMDriverDesktop::OnConnected(const net::IPEndPoint& ip_endpoint) {
733 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 744 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
734 745
735 connected_ = true; 746 connected_ = true;
736 747
737 // Drop the event if the service has been stopped. 748 // Drop the event if the service has been stopped.
738 if (!gcm_started_) 749 if (!gcm_started_)
(...skipping 23 matching lines...) Expand all
762 773
763 // Normally request_gcm_statistics_callback_ would not be null. 774 // Normally request_gcm_statistics_callback_ would not be null.
764 if (!request_gcm_statistics_callback_.is_null()) 775 if (!request_gcm_statistics_callback_.is_null())
765 request_gcm_statistics_callback_.Run(stats); 776 request_gcm_statistics_callback_.Run(stats);
766 else 777 else
767 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 778 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
768 } 779 }
769 780
770 } // namespace gcm 781 } // namespace gcm
771 782
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698