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

Side by Side Diff: chrome/browser/services/gcm/gcm_driver.cc

Issue 296053011: Start and stop the GCM service on demand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 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 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 "chrome/browser/services/gcm/gcm_driver.h" 5 #include "chrome/browser/services/gcm/gcm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 468
469 // Ensures that the GCM service is started when there is an interest. 469 // Ensures that the GCM service is started when there is an interest.
470 EnsureStarted(); 470 EnsureStarted();
471 } 471 }
472 472
473 void GCMDriver::RemoveAppHandler(const std::string& app_id) { 473 void GCMDriver::RemoveAppHandler(const std::string& app_id) {
474 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 474 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
475 DCHECK(!app_id.empty()); 475 DCHECK(!app_id.empty());
476 476
477 app_handlers_.erase(app_id); 477 app_handlers_.erase(app_id);
478
479 // Stops the GCM service when no app intends to consume it.
480 if (app_handlers_.empty())
481 Stop();
478 } 482 }
479 483
480 void GCMDriver::Register(const std::string& app_id, 484 void GCMDriver::Register(const std::string& app_id,
481 const std::vector<std::string>& sender_ids, 485 const std::vector<std::string>& sender_ids,
482 const RegisterCallback& callback) { 486 const RegisterCallback& callback) {
483 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 487 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
484 DCHECK(!app_id.empty()); 488 DCHECK(!app_id.empty());
485 DCHECK(!sender_ids.empty()); 489 DCHECK(!sender_ids.empty());
486 DCHECK(!callback.is_null()); 490 DCHECK(!callback.is_null());
487 491
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 void GCMDriver::OnActiveAccountLogout() { 678 void GCMDriver::OnActiveAccountLogout() {
675 CheckOut(); 679 CheckOut();
676 } 680 }
677 681
678 GCMClient::Result GCMDriver::EnsureStarted() { 682 GCMClient::Result GCMDriver::EnsureStarted() {
679 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 683 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
680 684
681 if (!gcm_enabled_) 685 if (!gcm_enabled_)
682 return GCMClient::GCM_DISABLED; 686 return GCMClient::GCM_DISABLED;
683 687
688 // Have any app requested the service?
689 if (app_handlers_.empty())
690 return GCMClient::UNKNOWN_ERROR;
691
684 // Is the user signed in? 692 // Is the user signed in?
685 const std::string account_id = identity_provider_->GetActiveAccountId(); 693 const std::string account_id = identity_provider_->GetActiveAccountId();
686 if (account_id.empty()) 694 if (account_id.empty())
687 return GCMClient::NOT_SIGNED_IN; 695 return GCMClient::NOT_SIGNED_IN;
688 696
689 // CheckIn could be called more than once when: 697 // CheckIn could be called more than once when:
690 // 1) The password changes. 698 // 1) The password changes.
691 // 2) Register/send function calls it to ensure CheckIn is done. 699 // 2) Register/send function calls it to ensure CheckIn is done.
692 if (account_id_ == account_id) 700 if (account_id_ == account_id)
693 return GCMClient::SUCCESS; 701 return GCMClient::SUCCESS;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 859 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
852 } 860 }
853 861
854 std::string GCMDriver::SignedInUserName() const { 862 std::string GCMDriver::SignedInUserName() const {
855 if (IsStarted()) 863 if (IsStarted())
856 return identity_provider_->GetActiveUsername(); 864 return identity_provider_->GetActiveUsername();
857 return std::string(); 865 return std::string();
858 } 866 }
859 867
860 } // namespace gcm 868 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/fake_gcm_app_handler.cc ('k') | chrome/browser/services/gcm/gcm_driver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698