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

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

Issue 285623002: Rename GCMClient::Load to GCMClient::Start (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch 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_service.h" 5 #include "chrome/browser/services/gcm/gcm_service.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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; 147 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE;
148 virtual void OnGCMReady() OVERRIDE; 148 virtual void OnGCMReady() OVERRIDE;
149 virtual void OnActivityRecorded() OVERRIDE; 149 virtual void OnActivityRecorded() OVERRIDE;
150 150
151 // Called on IO thread. 151 // Called on IO thread.
152 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory, 152 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory,
153 const base::FilePath& store_path, 153 const base::FilePath& store_path,
154 const std::vector<std::string>& account_ids, 154 const std::vector<std::string>& account_ids,
155 const scoped_refptr<net::URLRequestContextGetter>& 155 const scoped_refptr<net::URLRequestContextGetter>&
156 url_request_context_getter); 156 url_request_context_getter);
157 void Load(const base::WeakPtr<GCMService>& service); 157 void Start(const base::WeakPtr<GCMService>& service);
158 void Stop(); 158 void Stop();
159 void CheckOut(); 159 void CheckOut();
160 void Register(const std::string& app_id, 160 void Register(const std::string& app_id,
161 const std::vector<std::string>& sender_ids); 161 const std::vector<std::string>& sender_ids);
162 void Unregister(const std::string& app_id); 162 void Unregister(const std::string& app_id);
163 void Send(const std::string& app_id, 163 void Send(const std::string& app_id,
164 const std::string& receiver_id, 164 const std::string& receiver_id,
165 const GCMClient::OutgoingMessage& message); 165 const GCMClient::OutgoingMessage& message);
166 void GetGCMStatistics(bool clear_logs); 166 void GetGCMStatistics(bool clear_logs);
167 void SetGCMRecording(bool recording); 167 void SetGCMRecording(bool recording);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 service_)); 297 service_));
298 } 298 }
299 299
300 void GCMService::IOWorker::OnActivityRecorded() { 300 void GCMService::IOWorker::OnActivityRecorded() {
301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
302 // When an activity is recorded, get all the stats and refresh the UI of 302 // When an activity is recorded, get all the stats and refresh the UI of
303 // gcm-internals page. 303 // gcm-internals page.
304 GetGCMStatistics(false); 304 GetGCMStatistics(false);
305 } 305 }
306 306
307 void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) { 307 void GCMService::IOWorker::Start(const base::WeakPtr<GCMService>& service) {
308 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 308 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
309 309
310 service_ = service; 310 service_ = service;
311 gcm_client_->Load(); 311 gcm_client_->Start();
312 } 312 }
313 313
314 void GCMService::IOWorker::Stop() { 314 void GCMService::IOWorker::Stop() {
315 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 315 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
316 316
317 gcm_client_->Stop(); 317 gcm_client_->Stop();
318 } 318 }
319 319
320 void GCMService::IOWorker::CheckOut() { 320 void GCMService::IOWorker::CheckOut() {
321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 content::BrowserThread::PostTask( 403 content::BrowserThread::PostTask(
404 content::BrowserThread::IO, 404 content::BrowserThread::IO,
405 FROM_HERE, 405 FROM_HERE,
406 base::Bind(&GCMService::IOWorker::Initialize, 406 base::Bind(&GCMService::IOWorker::Initialize,
407 base::Unretained(io_worker_.get()), 407 base::Unretained(io_worker_.get()),
408 base::Passed(&gcm_client_factory), 408 base::Passed(&gcm_client_factory),
409 GetStorePath(), 409 GetStorePath(),
410 account_ids, 410 account_ids,
411 GetURLRequestContextGetter())); 411 GetURLRequestContextGetter()));
412 412
413 // Load from the GCM store and initiate the GCM check-in if the rollout signal 413 // Start the GCM service if the rollout signal indicates yes.
414 // indicates yes.
415 if (ShouldStartAutomatically()) 414 if (ShouldStartAutomatically())
416 EnsureLoaded(); 415 EnsureStarted();
417 416
418 identity_provider_->AddObserver(this); 417 identity_provider_->AddObserver(this);
419 } 418 }
420 419
421 void GCMService::Start() { 420 void GCMService::Start() {
422 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 421 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
423 422
424 EnsureLoaded(); 423 EnsureStarted();
425 } 424 }
426 425
427 void GCMService::Stop() { 426 void GCMService::Stop() {
428 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 427 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
429 428
430 // No need to stop GCM service if not started yet. 429 // No need to stop GCM service if not started yet.
431 if (account_id_.empty()) 430 if (account_id_.empty())
432 return; 431 return;
433 432
434 RemoveCachedData(); 433 RemoveCachedData();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 content::BrowserThread::PostTask( 659 content::BrowserThread::PostTask(
661 content::BrowserThread::IO, 660 content::BrowserThread::IO,
662 FROM_HERE, 661 FROM_HERE,
663 base::Bind(&GCMService::IOWorker::SetGCMRecording, 662 base::Bind(&GCMService::IOWorker::SetGCMRecording,
664 base::Unretained(io_worker_.get()), 663 base::Unretained(io_worker_.get()),
665 recording)); 664 recording));
666 } 665 }
667 666
668 void GCMService::OnActiveAccountLogin() { 667 void GCMService::OnActiveAccountLogin() {
669 if (ShouldStartAutomatically()) 668 if (ShouldStartAutomatically())
670 EnsureLoaded(); 669 EnsureStarted();
671 } 670 }
672 671
673 void GCMService::OnActiveAccountLogout() { 672 void GCMService::OnActiveAccountLogout() {
674 CheckOut(); 673 CheckOut();
675 } 674 }
676 675
677 void GCMService::EnsureLoaded() { 676 void GCMService::EnsureStarted() {
678 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 677 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
679 const std::string account_id = identity_provider_->GetActiveAccountId(); 678 const std::string account_id = identity_provider_->GetActiveAccountId();
680 if (account_id.empty()) 679 if (account_id.empty())
681 return; 680 return;
682 681
683 // CheckIn could be called more than once when: 682 // CheckIn could be called more than once when:
684 // 1) The password changes. 683 // 1) The password changes.
685 // 2) Register/send function calls it to ensure CheckIn is done. 684 // 2) Register/send function calls it to ensure CheckIn is done.
686 if (account_id_ == account_id) 685 if (account_id_ == account_id)
687 return; 686 return;
688 account_id_ = account_id; 687 account_id_ = account_id;
689 688
690 DCHECK(!delayed_task_controller_); 689 DCHECK(!delayed_task_controller_);
691 delayed_task_controller_.reset(new DelayedTaskController); 690 delayed_task_controller_.reset(new DelayedTaskController);
692 691
693 // This will load the data from the gcm store and trigger the check-in if
694 // the persisted check-in info is not found.
695 // Note that we need to pass weak pointer again since the existing weak 692 // Note that we need to pass weak pointer again since the existing weak
696 // pointer in IOWorker might have been invalidated when check-out occurs. 693 // pointer in IOWorker might have been invalidated when check-out occurs.
697 content::BrowserThread::PostTask( 694 content::BrowserThread::PostTask(
698 content::BrowserThread::IO, 695 content::BrowserThread::IO,
699 FROM_HERE, 696 FROM_HERE,
700 base::Bind(&GCMService::IOWorker::Load, 697 base::Bind(&GCMService::IOWorker::Start,
701 base::Unretained(io_worker_.get()), 698 base::Unretained(io_worker_.get()),
702 weak_ptr_factory_.GetWeakPtr())); 699 weak_ptr_factory_.GetWeakPtr()));
703 } 700 }
704 701
705 void GCMService::RemoveCachedData() { 702 void GCMService::RemoveCachedData() {
706 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 703 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
707 // Remove all the queued tasks since they no longer make sense after 704 // Remove all the queued tasks since they no longer make sense after
708 // GCM service is stopped. 705 // GCM service is stopped.
709 weak_ptr_factory_.InvalidateWeakPtrs(); 706 weak_ptr_factory_.InvalidateWeakPtrs();
710 707
(...skipping 15 matching lines...) Expand all
726 723
727 content::BrowserThread::PostTask( 724 content::BrowserThread::PostTask(
728 content::BrowserThread::IO, 725 content::BrowserThread::IO,
729 FROM_HERE, 726 FROM_HERE,
730 base::Bind(&GCMService::IOWorker::CheckOut, 727 base::Bind(&GCMService::IOWorker::CheckOut,
731 base::Unretained(io_worker_.get()))); 728 base::Unretained(io_worker_.get())));
732 } 729 }
733 730
734 GCMClient::Result GCMService::EnsureAppReady(const std::string& app_id) { 731 GCMClient::Result GCMService::EnsureAppReady(const std::string& app_id) {
735 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 732 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
736 // Ensure that check-in has been done.
737 EnsureLoaded();
738 733
739 // If the service was not started, bail out. 734 // Starts the service if not yet.
735 EnsureStarted();
736
737 // If the service cannot be started, bail out.
740 if (account_id_.empty()) 738 if (account_id_.empty())
741 return GCMClient::NOT_SIGNED_IN; 739 return GCMClient::NOT_SIGNED_IN;
742 740
743 return GCMClient::SUCCESS; 741 return GCMClient::SUCCESS;
744 } 742 }
745 743
746 bool GCMService::IsAsyncOperationPending(const std::string& app_id) const { 744 bool GCMService::IsAsyncOperationPending(const std::string& app_id) const {
747 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 745 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
748 return register_callbacks_.find(app_id) != register_callbacks_.end() || 746 return register_callbacks_.find(app_id) != register_callbacks_.end() ||
749 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); 747 unregister_callbacks_.find(app_id) != unregister_callbacks_.end();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 852 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
855 853
856 // Normally request_gcm_statistics_callback_ would not be null. 854 // Normally request_gcm_statistics_callback_ would not be null.
857 if (!request_gcm_statistics_callback_.is_null()) 855 if (!request_gcm_statistics_callback_.is_null())
858 request_gcm_statistics_callback_.Run(stats); 856 request_gcm_statistics_callback_.Run(stats);
859 else 857 else
860 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 858 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
861 } 859 }
862 860
863 } // namespace gcm 861 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_service.h ('k') | chrome/browser/services/gcm/gcm_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698