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

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: 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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 // Ensures that the GCM service is started when there is an interest. 483 // Ensures that the GCM service is started when there is an interest.
484 EnsureStarted(); 484 EnsureStarted();
485 } 485 }
486 486
487 void GCMDriver::RemoveAppHandler(const std::string& app_id) { 487 void GCMDriver::RemoveAppHandler(const std::string& app_id) {
488 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 488 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
489 DCHECK(!app_id.empty()); 489 DCHECK(!app_id.empty());
490 490
491 app_handlers_.erase(app_id); 491 app_handlers_.erase(app_id);
492
493 // Stops the GCM service when no app intends to consume it.
494 if (app_handlers_.empty())
495 Stop();
492 } 496 }
493 497
494 void GCMDriver::Register(const std::string& app_id, 498 void GCMDriver::Register(const std::string& app_id,
495 const std::vector<std::string>& sender_ids, 499 const std::vector<std::string>& sender_ids,
496 const RegisterCallback& callback) { 500 const RegisterCallback& callback) {
497 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 501 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
498 DCHECK(!app_id.empty()); 502 DCHECK(!app_id.empty());
499 DCHECK(!sender_ids.empty()); 503 DCHECK(!sender_ids.empty());
500 DCHECK(!callback.is_null()); 504 DCHECK(!callback.is_null());
501 505
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 void GCMDriver::OnActiveAccountLogout() { 697 void GCMDriver::OnActiveAccountLogout() {
694 CheckOut(); 698 CheckOut();
695 } 699 }
696 700
697 GCMClient::Result GCMDriver::EnsureStarted() { 701 GCMClient::Result GCMDriver::EnsureStarted() {
698 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 702 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
699 703
700 if (!gcm_enabled_) 704 if (!gcm_enabled_)
701 return GCMClient::GCM_DISABLED; 705 return GCMClient::GCM_DISABLED;
702 706
707 // Has any app requested the service?
Nicolas Zea 2014/05/22 17:06:31 nit: has -> Have
jianli 2014/05/22 18:09:26 Done.
708 if (app_handlers_.empty())
709 return GCMClient::UNKNOWN_ERROR;
710
703 // Is the user signed in? 711 // Is the user signed in?
704 const std::string account_id = identity_provider_->GetActiveAccountId(); 712 const std::string account_id = identity_provider_->GetActiveAccountId();
705 if (account_id.empty()) 713 if (account_id.empty())
706 return GCMClient::NOT_SIGNED_IN; 714 return GCMClient::NOT_SIGNED_IN;
707 715
708 // CheckIn could be called more than once when: 716 // CheckIn could be called more than once when:
709 // 1) The password changes. 717 // 1) The password changes.
710 // 2) Register/send function calls it to ensure CheckIn is done. 718 // 2) Register/send function calls it to ensure CheckIn is done.
711 if (account_id_ == account_id) 719 if (account_id_ == account_id)
712 return GCMClient::SUCCESS; 720 return GCMClient::SUCCESS;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 880 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
873 } 881 }
874 882
875 std::string GCMDriver::SignedInUserName() const { 883 std::string GCMDriver::SignedInUserName() const {
876 if (IsStarted()) 884 if (IsStarted())
877 return identity_provider_->GetActiveUsername(); 885 return identity_provider_->GetActiveUsername();
878 return std::string(); 886 return std::string();
879 } 887 }
880 888
881 } // namespace gcm 889 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698