OLD | NEW |
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 // Ensures that the GCM service is started when there is an interest. | 421 // Ensures that the GCM service is started when there is an interest. |
422 EnsureStarted(); | 422 EnsureStarted(); |
423 } | 423 } |
424 | 424 |
425 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { | 425 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { |
426 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 426 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
427 GCMDriver::RemoveAppHandler(app_id); | 427 GCMDriver::RemoveAppHandler(app_id); |
428 | 428 |
429 // Stops the GCM service when no app intends to consume it. | 429 // Stops the GCM service when no app intends to consume it. |
430 if (app_handlers().empty()) | 430 if (app_handlers().empty()) { |
431 Stop(); | 431 Stop(); |
| 432 gcm_channel_status_syncer_->Stop(); |
| 433 } |
432 } | 434 } |
433 | 435 |
434 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) { | 436 void GCMDriverDesktop::AddConnectionObserver(GCMConnectionObserver* observer) { |
435 connection_observer_list_.AddObserver(observer); | 437 connection_observer_list_.AddObserver(observer); |
436 } | 438 } |
437 | 439 |
438 void GCMDriverDesktop::RemoveConnectionObserver( | 440 void GCMDriverDesktop::RemoveConnectionObserver( |
439 GCMConnectionObserver* observer) { | 441 GCMConnectionObserver* observer) { |
440 connection_observer_list_.RemoveObserver(observer); | 442 connection_observer_list_.RemoveObserver(observer); |
441 } | 443 } |
(...skipping 18 matching lines...) Expand all Loading... |
460 Stop(); | 462 Stop(); |
461 } | 463 } |
462 | 464 |
463 void GCMDriverDesktop::Stop() { | 465 void GCMDriverDesktop::Stop() { |
464 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 466 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
465 | 467 |
466 // No need to stop GCM service if not started yet. | 468 // No need to stop GCM service if not started yet. |
467 if (!gcm_started_) | 469 if (!gcm_started_) |
468 return; | 470 return; |
469 | 471 |
470 gcm_channel_status_syncer_->Stop(); | |
471 | |
472 RemoveCachedData(); | 472 RemoveCachedData(); |
473 | 473 |
474 io_thread_->PostTask( | 474 io_thread_->PostTask( |
475 FROM_HERE, | 475 FROM_HERE, |
476 base::Bind(&GCMDriverDesktop::IOWorker::Stop, | 476 base::Bind(&GCMDriverDesktop::IOWorker::Stop, |
477 base::Unretained(io_worker_.get()))); | 477 base::Unretained(io_worker_.get()))); |
478 } | 478 } |
479 | 479 |
480 void GCMDriverDesktop::RegisterImpl( | 480 void GCMDriverDesktop::RegisterImpl( |
481 const std::string& app_id, | 481 const std::string& app_id, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 base::Unretained(io_worker_.get()), | 634 base::Unretained(io_worker_.get()), |
635 account_tokens)); | 635 account_tokens)); |
636 } | 636 } |
637 | 637 |
638 GCMClient::Result GCMDriverDesktop::EnsureStarted() { | 638 GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
639 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 639 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
640 | 640 |
641 if (gcm_started_) | 641 if (gcm_started_) |
642 return GCMClient::SUCCESS; | 642 return GCMClient::SUCCESS; |
643 | 643 |
644 if (!gcm_enabled_) | 644 if (!gcm_enabled_) { |
| 645 // Poll for channel status in order to find out when it is re-enabled when |
| 646 // GCM is currently disabled. |
| 647 if (GCMDriver::IsAllowedForAllUsers()) |
| 648 gcm_channel_status_syncer_->EnsureStarted(); |
| 649 |
645 return GCMClient::GCM_DISABLED; | 650 return GCMClient::GCM_DISABLED; |
| 651 } |
646 | 652 |
647 // Have any app requested the service? | 653 // Have any app requested the service? |
648 if (app_handlers().empty()) | 654 if (app_handlers().empty()) |
649 return GCMClient::UNKNOWN_ERROR; | 655 return GCMClient::UNKNOWN_ERROR; |
650 | 656 |
651 // TODO(jianli): To be removed when sign-in enforcement is dropped. | 657 // TODO(jianli): To be removed when sign-in enforcement is dropped. |
652 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) | 658 if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers()) |
653 return GCMClient::NOT_SIGNED_IN; | 659 return GCMClient::NOT_SIGNED_IN; |
654 | 660 |
655 DCHECK(!delayed_task_controller_); | 661 DCHECK(!delayed_task_controller_); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 | 776 |
771 // Normally request_gcm_statistics_callback_ would not be null. | 777 // Normally request_gcm_statistics_callback_ would not be null. |
772 if (!request_gcm_statistics_callback_.is_null()) | 778 if (!request_gcm_statistics_callback_.is_null()) |
773 request_gcm_statistics_callback_.Run(stats); | 779 request_gcm_statistics_callback_.Run(stats); |
774 else | 780 else |
775 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 781 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
776 } | 782 } |
777 | 783 |
778 } // namespace gcm | 784 } // namespace gcm |
779 | 785 |
OLD | NEW |