| 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" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/google_auto_login_helper.h" |
| 9 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 10 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 11 #include "chrome/browser/signin/signin_manager.h" | 12 #include "chrome/browser/signin/signin_manager.h" |
| 12 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
| 13 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 14 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 15 #include "google_apis/gaia/gaia_constants.h" | 16 #include "google_apis/gaia/gaia_constants.h" |
| 16 | 17 |
| 17 SigninTracker::SigninTracker(Profile* profile, Observer* observer) | 18 SigninTracker::SigninTracker(Profile* profile, Observer* observer) |
| 18 : profile_(profile), observer_(observer) { | 19 : profile_(profile), observer_(observer) { |
| 19 DCHECK(profile_); | 20 DCHECK(profile_); |
| 20 Initialize(); | 21 Initialize(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 SigninTracker::~SigninTracker() { | 24 SigninTracker::~SigninTracker() { |
| 24 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 25 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 25 RemoveObserver(this); | 26 RemoveObserver(this); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void SigninTracker::Initialize() { | 29 void SigninTracker::Initialize() { |
| 29 DCHECK(observer_); | 30 DCHECK(observer_); |
| 30 | 31 |
| 31 // Register for notifications from the SigninManager. | 32 // Register for notifications from the SigninManager and sign in helper. |
| 32 registrar_.Add(this, | 33 registrar_.Add(this, |
| 33 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 34 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| 34 content::Source<Profile>(profile_)); | 35 content::Source<Profile>(profile_)); |
| 36 registrar_.Add(this, |
| 37 chrome::NOTIFICATION_MERGE_SESSION_COMPLETE, |
| 38 content::Source<Profile>(profile_)); |
| 35 | 39 |
| 36 OAuth2TokenService* token_service = | 40 OAuth2TokenService* token_service = |
| 37 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 41 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 38 token_service->AddObserver(this); | 42 token_service->AddObserver(this); |
| 39 } | 43 } |
| 40 | 44 |
| 41 void SigninTracker::Observe(int type, | 45 void SigninTracker::Observe(int type, |
| 42 const content::NotificationSource& source, | 46 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) { | 47 const content::NotificationDetails& details) { |
| 44 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, type); | 48 switch (type) { |
| 45 | 49 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
| 46 // We should not get more than one of these notifications. | 50 // We should not get more than one of these notifications. |
| 47 const GoogleServiceAuthError& error = | 51 const GoogleServiceAuthError& error = |
| 48 *(content::Details<const GoogleServiceAuthError>(details).ptr()); | 52 *(content::Details<const GoogleServiceAuthError>(details).ptr()); |
| 49 observer_->SigninFailed(error); | 53 observer_->SigninFailed(error); |
| 54 break; |
| 55 } |
| 56 case chrome::NOTIFICATION_MERGE_SESSION_COMPLETE: { |
| 57 const GoogleAutoLoginHelper::MergeSessionDetails* merge_details = |
| 58 content::Details<const GoogleAutoLoginHelper::MergeSessionDetails>( |
| 59 details).ptr(); |
| 60 observer_->MergeSessionComplete(merge_details->error); |
| 61 break; |
| 62 } |
| 63 default: |
| 64 NOTREACHED() << "Type: " << type; |
| 65 break; |
| 66 } |
| 50 } | 67 } |
| 51 | 68 |
| 52 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { | 69 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { |
| 53 // TODO: when OAuth2TokenService handles multi-login, this should check | 70 // TODO: when OAuth2TokenService handles multi-login, this should check |
| 54 // that |account_id| is the primary account before signalling success. | 71 // that |account_id| is the primary account before signalling success. |
| 55 observer_->SigninSuccess(); | 72 observer_->SigninSuccess(); |
| 56 } | 73 } |
| 57 | 74 |
| 58 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) { | 75 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) { |
| 59 NOTREACHED(); | 76 NOTREACHED(); |
| 60 } | 77 } |
| OLD | NEW |