| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/signin/signin_tracker.h" | 5 #include "chrome/browser/signin/signin_tracker.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/account_reconcilor_factory.h" | 8 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 10 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" |
| 12 #include "chrome/common/profile_management_switches.h" | 12 #include "chrome/common/profile_management_switches.h" |
| 13 #include "content/public/browser/notification_details.h" | |
| 14 #include "content/public/browser/notification_source.h" | |
| 15 #include "google_apis/gaia/gaia_constants.h" | 13 #include "google_apis/gaia/gaia_constants.h" |
| 16 | 14 |
| 17 #if !defined(OS_CHROMEOS) | 15 #if !defined(OS_CHROMEOS) |
| 18 #include "chrome/browser/signin/signin_manager.h" | 16 #include "chrome/browser/signin/signin_manager.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 20 #endif | 17 #endif |
| 21 | 18 |
| 22 SigninTracker::SigninTracker(Profile* profile, Observer* observer) | 19 SigninTracker::SigninTracker(Profile* profile, Observer* observer) |
| 23 : profile_(profile), observer_(observer) { | 20 : profile_(profile), observer_(observer) { |
| 24 DCHECK(profile_); | 21 DCHECK(profile_); |
| 25 Initialize(); | 22 Initialize(); |
| 26 } | 23 } |
| 27 | 24 |
| 28 SigninTracker::~SigninTracker() { | 25 SigninTracker::~SigninTracker() { |
| 26 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 29 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 27 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 30 RemoveObserver(this); | 28 RemoveObserver(this); |
| 31 | 29 |
| 32 if (!switches::IsEnableWebBasedSignin()) { | 30 if (!switches::IsEnableWebBasedSignin()) { |
| 33 if (switches::IsNewProfileManagement()) { | 31 if (switches::IsNewProfileManagement()) { |
| 34 AccountReconcilorFactory::GetForProfile(profile_)-> | 32 AccountReconcilorFactory::GetForProfile(profile_)-> |
| 35 RemoveMergeSessionObserver(this); | 33 RemoveMergeSessionObserver(this); |
| 36 #if !defined(OS_CHROMEOS) | 34 #if !defined(OS_CHROMEOS) |
| 37 } else { | 35 } else { |
| 38 SigninManagerFactory::GetForProfile(profile_)-> | 36 SigninManagerFactory::GetForProfile(profile_)-> |
| 39 RemoveMergeSessionObserver(this); | 37 RemoveMergeSessionObserver(this); |
| 40 #endif | 38 #endif |
| 41 } | 39 } |
| 42 } | 40 } |
| 43 } | 41 } |
| 44 | 42 |
| 45 void SigninTracker::Initialize() { | 43 void SigninTracker::Initialize() { |
| 46 DCHECK(observer_); | 44 DCHECK(observer_); |
| 47 | 45 |
| 48 // Register for notifications from the SigninManager. | 46 SigninManagerBase* signin_manager = |
| 49 registrar_.Add(this, | 47 SigninManagerFactory::GetForProfile(profile_); |
| 50 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 48 signin_manager->AddObserver(this); |
| 51 content::Source<Profile>(profile_)); | |
| 52 | |
| 53 OAuth2TokenService* token_service = | 49 OAuth2TokenService* token_service = |
| 54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 50 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 55 token_service->AddObserver(this); | 51 token_service->AddObserver(this); |
| 56 } | 52 } |
| 57 | 53 |
| 58 void SigninTracker::Observe(int type, | 54 void SigninTracker::GoogleSigninFailed(const GoogleServiceAuthError& error) { |
| 59 const content::NotificationSource& source, | |
| 60 const content::NotificationDetails& details) { | |
| 61 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, type); | |
| 62 | |
| 63 // We should not get more than one of these notifications. | |
| 64 const GoogleServiceAuthError& error = | |
| 65 *(content::Details<const GoogleServiceAuthError>(details).ptr()); | |
| 66 observer_->SigninFailed(error); | 55 observer_->SigninFailed(error); |
| 67 } | 56 } |
| 68 | 57 |
| 69 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { | 58 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { |
| 70 // TODO: when OAuth2TokenService handles multi-login, this should check | 59 // TODO: when OAuth2TokenService handles multi-login, this should check |
| 71 // that |account_id| is the primary account before signalling success. | 60 // that |account_id| is the primary account before signalling success. |
| 72 if (!switches::IsEnableWebBasedSignin()) { | 61 if (!switches::IsEnableWebBasedSignin()) { |
| 73 if (switches::IsNewProfileManagement()) { | 62 if (switches::IsNewProfileManagement()) { |
| 74 AccountReconcilorFactory::GetForProfile(profile_)-> | 63 AccountReconcilorFactory::GetForProfile(profile_)-> |
| 75 AddMergeSessionObserver(this); | 64 AddMergeSessionObserver(this); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 | 75 |
| 87 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) { | 76 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) { |
| 88 NOTREACHED(); | 77 NOTREACHED(); |
| 89 } | 78 } |
| 90 | 79 |
| 91 void SigninTracker::MergeSessionCompleted( | 80 void SigninTracker::MergeSessionCompleted( |
| 92 const std::string& account_id, | 81 const std::string& account_id, |
| 93 const GoogleServiceAuthError& error) { | 82 const GoogleServiceAuthError& error) { |
| 94 observer_->MergeSessionComplete(error); | 83 observer_->MergeSessionComplete(error); |
| 95 } | 84 } |
| OLD | NEW |