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

Side by Side Diff: chrome/browser/signin/signin_tracker.cc

Issue 110373007: Delay loading the NTP after sign in until MergeSession has been performed in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years 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) 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/account_reconcilor_factory.h"
10 #include "chrome/browser/signin/google_auto_login_helper.h"
9 #include "chrome/browser/signin/profile_oauth2_token_service.h" 11 #include "chrome/browser/signin/profile_oauth2_token_service.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager.h" 13 #include "chrome/browser/signin/signin_manager.h"
12 #include "chrome/browser/signin/signin_manager_factory.h" 14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/common/profile_management_switches.h"
13 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
15 #include "google_apis/gaia/gaia_constants.h" 18 #include "google_apis/gaia/gaia_constants.h"
16 19
17 SigninTracker::SigninTracker(Profile* profile, Observer* observer) 20 SigninTracker::SigninTracker(Profile* profile, Observer* observer)
18 : profile_(profile), observer_(observer) { 21 : profile_(profile), observer_(observer) {
19 DCHECK(profile_); 22 DCHECK(profile_);
20 Initialize(); 23 Initialize();
21 } 24 }
22 25
23 SigninTracker::~SigninTracker() { 26 SigninTracker::~SigninTracker() {
24 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 27 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
25 RemoveObserver(this); 28 RemoveObserver(this);
29
30 if (merge_session_helper_)
31 merge_session_helper_->RemoveObserver(this);
32
33 if (switches::IsEnableInlineSignin() && switches::IsNewProfileManagement()) {
34 AccountReconcilorFactory::GetForProfile(profile_)->
35 RemoveMergeSessionObserver(this);
36 }
26 } 37 }
27 38
28 void SigninTracker::Initialize() { 39 void SigninTracker::Initialize() {
29 DCHECK(observer_); 40 DCHECK(observer_);
30 41
31 // Register for notifications from the SigninManager. 42 // Register for notifications from the SigninManager.
32 registrar_.Add(this, 43 registrar_.Add(this,
33 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, 44 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
34 content::Source<Profile>(profile_)); 45 content::Source<Profile>(profile_));
35 46
36 OAuth2TokenService* token_service = 47 OAuth2TokenService* token_service =
37 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 48 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
38 token_service->AddObserver(this); 49 token_service->AddObserver(this);
39 } 50 }
40 51
41 void SigninTracker::Observe(int type, 52 void SigninTracker::Observe(int type,
42 const content::NotificationSource& source, 53 const content::NotificationSource& source,
43 const content::NotificationDetails& details) { 54 const content::NotificationDetails& details) {
44 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, type); 55 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, type);
45 56
46 // We should not get more than one of these notifications. 57 // We should not get more than one of these notifications.
47 const GoogleServiceAuthError& error = 58 const GoogleServiceAuthError& error =
48 *(content::Details<const GoogleServiceAuthError>(details).ptr()); 59 *(content::Details<const GoogleServiceAuthError>(details).ptr());
49 observer_->SigninFailed(error); 60 observer_->SigninFailed(error);
50 } 61 }
51 62
52 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { 63 void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) {
53 // TODO: when OAuth2TokenService handles multi-login, this should check 64 // TODO: when OAuth2TokenService handles multi-login, this should check
54 // that |account_id| is the primary account before signalling success. 65 // that |account_id| is the primary account before signalling success.
66 if (switches::IsEnableInlineSignin()) {
67 if (switches::IsNewProfileManagement()) {
68 AccountReconcilorFactory::GetForProfile(profile_)->
69 AddMergeSessionObserver(this);
70 } else {
71 merge_session_helper_.reset(new GoogleAutoLoginHelper(profile_, this));
guohui 2013/12/20 16:11:09 It looks wierd to me to create a GoogleAutoLoginHe
Roger Tawa OOO till Jul 10th 2013/12/20 20:02:01 Agreed, does not make sense to do this in the trac
72 merge_session_helper_->LogIn(account_id);
73 }
74 }
75
55 observer_->SigninSuccess(); 76 observer_->SigninSuccess();
56 } 77 }
57 78
58 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) { 79 void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id) {
59 NOTREACHED(); 80 NOTREACHED();
60 } 81 }
82
83 void SigninTracker::MergeSessionCompleted(
84 const std::string& account_id,
85 const GoogleServiceAuthError& error) {
86 observer_->MergeSessionComplete(error);
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698