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

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

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add API tests Created 6 years, 9 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_profile_service.h" 5 #include "chrome/browser/services/gcm/gcm_profile_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/services/gcm/gcm_app_handler.h" 19 #include "chrome/browser/services/gcm/gcm_app_handler.h"
20 #include "chrome/browser/services/gcm/gcm_client_factory.h" 20 #include "chrome/browser/services/gcm/gcm_client_factory.h"
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 #include "chrome/browser/signin/signin_manager.h" 22 #include "chrome/browser/signin/signin_manager.h"
23 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
28 #include "components/signin/core/browser/profile_oauth2_token_service.h" 27 #include "components/signin/core/browser/profile_oauth2_token_service.h"
29 #include "components/user_prefs/pref_registry_syncable.h" 28 #include "components/user_prefs/pref_registry_syncable.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
33 #include "google_apis/gcm/protocol/android_checkin.pb.h" 32 #include "google_apis/gcm/protocol/android_checkin.pb.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 GCMProfileService::~GCMProfileService() { 441 GCMProfileService::~GCMProfileService() {
443 } 442 }
444 443
445 void GCMProfileService::Initialize( 444 void GCMProfileService::Initialize(
446 scoped_ptr<GCMClientFactory> gcm_client_factory) { 445 scoped_ptr<GCMClientFactory> gcm_client_factory) {
447 registrar_.Add(this, 446 registrar_.Add(this,
448 chrome::NOTIFICATION_PROFILE_DESTROYED, 447 chrome::NOTIFICATION_PROFILE_DESTROYED,
449 content::Source<Profile>(profile_)); 448 content::Source<Profile>(profile_));
450 449
451 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); 450 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
451 SigninManagerFactory::GetInstance()->AddObserver(this);
452 452
453 // Get the list of available accounts. 453 // Get the list of available accounts.
454 std::vector<std::string> account_ids; 454 std::vector<std::string> account_ids;
455 #if !defined(OS_ANDROID) 455 #if !defined(OS_ANDROID)
456 account_ids = 456 account_ids =
457 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts(); 457 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts();
458 #endif 458 #endif
459 459
460 // Create and initialize the GCMClient. Note that this does not initiate the 460 // Create and initialize the GCMClient. Note that this does not initiate the
461 // GCM check-in. 461 // GCM check-in.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 base::Bind(&GCMProfileService::IOWorker::Stop, io_worker_)); 499 base::Bind(&GCMProfileService::IOWorker::Stop, io_worker_));
500 } 500 }
501 501
502 void GCMProfileService::Shutdown() { 502 void GCMProfileService::Shutdown() {
503 for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin(); 503 for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin();
504 iter != app_handlers_.end(); ++iter) { 504 iter != app_handlers_.end(); ++iter) {
505 iter->second->ShutdownHandler(); 505 iter->second->ShutdownHandler();
506 } 506 }
507 app_handlers_.clear(); 507 app_handlers_.clear();
508 508
509 SigninManagerFactory::GetInstance()->RemoveObserver(this);
509 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); 510 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
510 } 511 }
511 512
512 void GCMProfileService::AddAppHandler(const std::string& app_id, 513 void GCMProfileService::AddAppHandler(const std::string& app_id,
513 GCMAppHandler* handler) { 514 GCMAppHandler* handler) {
514 DCHECK(!app_id.empty()); 515 DCHECK(!app_id.empty());
515 DCHECK(handler); 516 DCHECK(handler);
516 DCHECK(app_handlers_.find(app_id) == app_handlers_.end()); 517 DCHECK(app_handlers_.find(app_id) == app_handlers_.end());
517 518
518 app_handlers_[app_id] = handler; 519 app_handlers_[app_id] = handler;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 void GCMProfileService::GoogleSigninSucceeded(const std::string& username, 716 void GCMProfileService::GoogleSigninSucceeded(const std::string& username,
716 const std::string& password) { 717 const std::string& password) {
717 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED) 718 if (GetGCMEnabledState(profile_) == ALWAYS_ENABLED)
718 EnsureLoaded(); 719 EnsureLoaded();
719 } 720 }
720 721
721 void GCMProfileService::GoogleSignedOut(const std::string& username) { 722 void GCMProfileService::GoogleSignedOut(const std::string& username) {
722 CheckOut(); 723 CheckOut();
723 } 724 }
724 725
726 void GCMProfileService::SigninManagerCreated(SigninManagerBase* manager) {
727 manager->AddObserver(this);
728 }
729
730 void GCMProfileService::SigninManagerShutdown(SigninManagerBase* manager) {
731 manager->RemoveObserver(this);
732 }
733
725 void GCMProfileService::EnsureLoaded() { 734 void GCMProfileService::EnsureLoaded() {
726 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_); 735 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_);
727 if (!manager) 736 if (!manager)
728 return; 737 return;
729 std::string username = manager->GetAuthenticatedUsername(); 738 std::string username = manager->GetAuthenticatedUsername();
730 if (username.empty()) 739 if (username.empty())
731 return; 740 return;
732 741
733 // CheckIn could be called more than once when: 742 // CheckIn could be called more than once when:
734 // 1) The password changes. 743 // 1) The password changes.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 } 911 }
903 912
904 void GCMProfileService::RequestGCMStatisticsFinished( 913 void GCMProfileService::RequestGCMStatisticsFinished(
905 GCMClient::GCMStatistics stats) { 914 GCMClient::GCMStatistics stats) {
906 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 915 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
907 916
908 request_gcm_statistics_callback_.Run(stats); 917 request_gcm_statistics_callback_.Run(stats);
909 } 918 }
910 919
911 } // namespace gcm 920 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698