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/ui/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" | 30 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
31 #include "chrome/browser/ui/tab_dialogs.h" | 31 #include "chrome/browser/ui/tab_dialogs.h" |
32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
34 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
35 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
36 #include "components/browser_sync/profile_sync_service.h" | 36 #include "components/browser_sync/profile_sync_service.h" |
37 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
38 #include "components/signin/core/browser/signin_manager.h" | 38 #include "components/signin/core/browser/signin_manager.h" |
39 #include "components/signin/core/browser/signin_metrics.h" | 39 #include "components/signin/core/browser/signin_metrics.h" |
| 40 #include "components/signin/core/common/profile_management_switches.h" |
40 #include "components/sync/base/sync_prefs.h" | 41 #include "components/sync/base/sync_prefs.h" |
41 #include "net/base/url_util.h" | 42 #include "net/base/url_util.h" |
42 #include "net/url_request/url_request_context_getter.h" | 43 #include "net/url_request/url_request_context_getter.h" |
43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
44 | 45 |
45 using browser_sync::ProfileSyncService; | 46 using browser_sync::ProfileSyncService; |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
49 // UMA histogram for tracking what users do when presented with the signin | 50 // UMA histogram for tracking what users do when presented with the signin |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 current_url_(current_url), | 92 current_url_(current_url), |
92 continue_url_(continue_url), | 93 continue_url_(continue_url), |
93 sync_setup_completed_callback_(sync_setup_completed_callback), | 94 sync_setup_completed_callback_(sync_setup_completed_callback), |
94 first_account_added_to_cookie_(false), | 95 first_account_added_to_cookie_(false), |
95 weak_pointer_factory_(this) { | 96 weak_pointer_factory_(this) { |
96 DCHECK(profile); | 97 DCHECK(profile); |
97 DCHECK(web_contents || continue_url.is_empty()); | 98 DCHECK(web_contents || continue_url.is_empty()); |
98 BrowserList::AddObserver(this); | 99 BrowserList::AddObserver(this); |
99 Initialize(profile, browser); | 100 Initialize(profile, browser); |
100 | 101 |
| 102 DCHECK(!refresh_token.empty() || switches::IsAccountConsistencyDiceEnabled()); |
101 SigninManagerFactory::GetForProfile(profile_)->StartSignInWithRefreshToken( | 103 SigninManagerFactory::GetForProfile(profile_)->StartSignInWithRefreshToken( |
102 refresh_token, gaia_id, email, password, | 104 refresh_token, gaia_id, email, password, |
103 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, | 105 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, |
104 weak_pointer_factory_.GetWeakPtr(), profile_mode)); | 106 weak_pointer_factory_.GetWeakPtr(), profile_mode)); |
105 } | 107 } |
106 | 108 |
107 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { | 109 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { |
108 if (browser == browser_) | 110 if (browser == browser_) |
109 browser_ = nullptr; | 111 browser_ = nullptr; |
110 } | 112 } |
(...skipping 23 matching lines...) Expand all Loading... |
134 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle(); | 136 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle(); |
135 | 137 |
136 // Make sure the syncing is requested, otherwise the SigninManager | 138 // Make sure the syncing is requested, otherwise the SigninManager |
137 // will not be able to complete successfully. | 139 // will not be able to complete successfully. |
138 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); | 140 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); |
139 sync_prefs.SetSyncRequested(true); | 141 sync_prefs.SetSyncRequested(true); |
140 } | 142 } |
141 | 143 |
142 void OneClickSigninSyncStarter::ConfirmSignin(ProfileMode profile_mode, | 144 void OneClickSigninSyncStarter::ConfirmSignin(ProfileMode profile_mode, |
143 const std::string& oauth_token) { | 145 const std::string& oauth_token) { |
144 DCHECK(!oauth_token.empty()); | |
145 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 146 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
146 if (signin->IsAuthenticated()) { | 147 if (signin->IsAuthenticated()) { |
147 // The user is already signed in - just tell SigninManager to continue | 148 // The user is already signed in - just tell SigninManager to continue |
148 // with its re-auth flow. | 149 // with its re-auth flow. |
149 DCHECK_EQ(CURRENT_PROFILE, profile_mode); | 150 DCHECK_EQ(CURRENT_PROFILE, profile_mode); |
150 signin->CompletePendingSignin(); | 151 signin->CompletePendingSignin(); |
151 return; | 152 return; |
152 } | 153 } |
153 | 154 |
154 switch (profile_mode) { | 155 switch (profile_mode) { |
155 case CURRENT_PROFILE: { | 156 case CURRENT_PROFILE: { |
156 // If this is a new signin (no account authenticated yet) try loading | 157 // If this is a new signin (no account authenticated yet) try loading |
157 // policy for this user now, before any signed in services are | 158 // policy for this user now, before any signed in services are |
158 // initialized. | 159 // initialized. |
159 policy::UserPolicySigninService* policy_service = | 160 policy::UserPolicySigninService* policy_service = |
160 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 161 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
161 policy_service->RegisterForPolicy( | 162 if (oauth_token.empty()) { |
162 signin->GetUsernameForAuthInProgress(), oauth_token, | 163 DCHECK(switches::IsAccountConsistencyDiceEnabled()); |
163 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, | 164 policy_service->RegisterForPolicyWithAccountId( |
164 weak_pointer_factory_.GetWeakPtr())); | 165 signin->GetUsernameForAuthInProgress(), |
| 166 signin->GetAccountIdForAuthInProgress(), |
| 167 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, |
| 168 weak_pointer_factory_.GetWeakPtr())); |
| 169 } else { |
| 170 policy_service->RegisterForPolicyWithLoginToken( |
| 171 signin->GetUsernameForAuthInProgress(), oauth_token, |
| 172 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, |
| 173 weak_pointer_factory_.GetWeakPtr())); |
| 174 } |
165 break; | 175 break; |
166 } | 176 } |
167 case NEW_PROFILE: | 177 case NEW_PROFILE: |
168 // If this is a new signin (no account authenticated yet) in a new | 178 // If this is a new signin (no account authenticated yet) in a new |
169 // profile, then just create the new signed-in profile and skip loading | 179 // profile, then just create the new signed-in profile and skip loading |
170 // the policy as there is no need to ask the user again if they should be | 180 // the policy as there is no need to ask the user again if they should be |
171 // signed in to a new profile. Note that in this case the policy will be | 181 // signed in to a new profile. Note that in this case the policy will be |
172 // applied after the new profile is signed in. | 182 // applied after the new profile is signed in. |
173 CreateNewSignedInProfile(); | 183 CreateNewSignedInProfile(); |
174 break; | 184 break; |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 ProfileSyncService* service = nullptr; | 539 ProfileSyncService* service = nullptr; |
530 if (profile_->IsSyncAllowed()) | 540 if (profile_->IsSyncAllowed()) |
531 service = ProfileSyncServiceFactory::GetForProfile(profile_); | 541 service = ProfileSyncServiceFactory::GetForProfile(profile_); |
532 return service; | 542 return service; |
533 } | 543 } |
534 | 544 |
535 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 545 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
536 sync_blocker_.reset(); | 546 sync_blocker_.reset(); |
537 } | 547 } |
538 | 548 |
OLD | NEW |