| 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.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const std::string& email, | 77 const std::string& email, |
| 78 const std::string& password, | 78 const std::string& password, |
| 79 const std::string& refresh_token, | 79 const std::string& refresh_token, |
| 80 StartSyncMode start_mode, | 80 StartSyncMode start_mode, |
| 81 content::WebContents* web_contents, | 81 content::WebContents* web_contents, |
| 82 ConfirmationRequired confirmation_required, | 82 ConfirmationRequired confirmation_required, |
| 83 const GURL& current_url, | 83 const GURL& current_url, |
| 84 const GURL& continue_url, | 84 const GURL& continue_url, |
| 85 Callback sync_setup_completed_callback) | 85 Callback sync_setup_completed_callback) |
| 86 : content::WebContentsObserver(web_contents), | 86 : content::WebContentsObserver(web_contents), |
| 87 profile_(NULL), | 87 profile_(nullptr), |
| 88 start_mode_(start_mode), | 88 start_mode_(start_mode), |
| 89 confirmation_required_(confirmation_required), | 89 confirmation_required_(confirmation_required), |
| 90 current_url_(current_url), | 90 current_url_(current_url), |
| 91 continue_url_(continue_url), | 91 continue_url_(continue_url), |
| 92 sync_setup_completed_callback_(sync_setup_completed_callback), | 92 sync_setup_completed_callback_(sync_setup_completed_callback), |
| 93 first_account_added_to_cookie_(false), | 93 first_account_added_to_cookie_(false), |
| 94 weak_pointer_factory_(this) { | 94 weak_pointer_factory_(this) { |
| 95 DCHECK(profile); | 95 DCHECK(profile); |
| 96 DCHECK(web_contents || continue_url.is_empty()); | 96 DCHECK(web_contents || continue_url.is_empty()); |
| 97 BrowserList::AddObserver(this); | 97 BrowserList::AddObserver(this); |
| 98 Initialize(profile, browser); | 98 Initialize(profile, browser); |
| 99 | 99 |
| 100 // Policy is enabled, so pass in a callback to do extra policy-related UI | 100 // Policy is enabled, so pass in a callback to do extra policy-related UI |
| 101 // before signin completes. | 101 // before signin completes. |
| 102 SigninManagerFactory::GetForProfile(profile_)-> | 102 SigninManagerFactory::GetForProfile(profile_)-> |
| 103 StartSignInWithRefreshToken( | 103 StartSignInWithRefreshToken( |
| 104 refresh_token, gaia_id, email, password, | 104 refresh_token, gaia_id, email, password, |
| 105 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, | 105 base::Bind(&OneClickSigninSyncStarter::ConfirmSignin, |
| 106 weak_pointer_factory_.GetWeakPtr())); | 106 weak_pointer_factory_.GetWeakPtr())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { | 109 void OneClickSigninSyncStarter::OnBrowserRemoved(Browser* browser) { |
| 110 if (browser == browser_) | 110 if (browser == browser_) |
| 111 browser_ = NULL; | 111 browser_ = nullptr; |
| 112 } | 112 } |
| 113 | 113 |
| 114 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { | 114 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { |
| 115 BrowserList::RemoveObserver(this); | 115 BrowserList::RemoveObserver(this); |
| 116 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | 116 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { | 119 void OneClickSigninSyncStarter::Initialize(Profile* profile, Browser* browser) { |
| 120 DCHECK(profile); | 120 DCHECK(profile); |
| 121 | 121 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 : sync_starter_(sync_starter) { | 167 : sync_starter_(sync_starter) { |
| 168 } | 168 } |
| 169 | 169 |
| 170 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { | 170 OneClickSigninSyncStarter::SigninDialogDelegate::~SigninDialogDelegate() { |
| 171 } | 171 } |
| 172 | 172 |
| 173 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { | 173 void OneClickSigninSyncStarter::SigninDialogDelegate::OnCancelSignin() { |
| 174 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); | 174 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); |
| 175 content::RecordAction( | 175 content::RecordAction( |
| 176 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); | 176 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_Cancel")); |
| 177 if (sync_starter_ != NULL) | 177 if (sync_starter_) |
| 178 sync_starter_->CancelSigninAndDelete(); | 178 sync_starter_->CancelSigninAndDelete(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { | 181 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { |
| 182 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); | 182 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); |
| 183 content::RecordAction( | 183 content::RecordAction( |
| 184 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_ImportData")); | 184 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_ImportData")); |
| 185 | 185 |
| 186 if (sync_starter_ != NULL) | 186 if (sync_starter_) |
| 187 sync_starter_->LoadPolicyWithCachedCredentials(); | 187 sync_starter_->LoadPolicyWithCachedCredentials(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { | 190 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { |
| 191 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); | 191 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); |
| 192 content::RecordAction( | 192 content::RecordAction( |
| 193 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_DontImportData")); | 193 base::UserMetricsAction("Signin_EnterpriseAccountPrompt_DontImportData")); |
| 194 | 194 |
| 195 if (sync_starter_ != NULL) | 195 if (sync_starter_) |
| 196 sync_starter_->CreateNewSignedInProfile(); | 196 sync_starter_->CreateNewSignedInProfile(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void OneClickSigninSyncStarter::OnRegisteredForPolicy( | 199 void OneClickSigninSyncStarter::OnRegisteredForPolicy( |
| 200 const std::string& dm_token, const std::string& client_id) { | 200 const std::string& dm_token, const std::string& client_id) { |
| 201 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 201 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 202 // If there's no token for the user (policy registration did not succeed) just | 202 // If there's no token for the user (policy registration did not succeed) just |
| 203 // finish signing in. | 203 // finish signing in. |
| 204 if (dm_token.empty()) { | 204 if (dm_token.empty()) { |
| 205 DVLOG(1) << "Policy registration failed"; | 205 DVLOG(1) << "Policy registration failed"; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); | 299 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); |
| 300 DCHECK(!old_signin_manager->IsAuthenticated()); | 300 DCHECK(!old_signin_manager->IsAuthenticated()); |
| 301 DCHECK(!new_signin_manager->IsAuthenticated()); | 301 DCHECK(!new_signin_manager->IsAuthenticated()); |
| 302 DCHECK(!dm_token_.empty()); | 302 DCHECK(!dm_token_.empty()); |
| 303 DCHECK(!client_id_.empty()); | 303 DCHECK(!client_id_.empty()); |
| 304 | 304 |
| 305 // Copy credentials from the old profile to the just-created profile, | 305 // Copy credentials from the old profile to the just-created profile, |
| 306 // and switch over to tracking that profile. | 306 // and switch over to tracking that profile. |
| 307 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); | 307 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); |
| 308 FinishProfileSyncServiceSetup(); | 308 FinishProfileSyncServiceSetup(); |
| 309 Initialize(new_profile, NULL); | 309 Initialize(new_profile, nullptr); |
| 310 DCHECK_EQ(profile_, new_profile); | 310 DCHECK_EQ(profile_, new_profile); |
| 311 | 311 |
| 312 // We've transferred our credentials to the new profile - notify that | 312 // We've transferred our credentials to the new profile - notify that |
| 313 // the signin for the original profile was cancelled (must do this after | 313 // the signin for the original profile was cancelled (must do this after |
| 314 // we have called Initialize() with the new profile, as otherwise this | 314 // we have called Initialize() with the new profile, as otherwise this |
| 315 // object will get freed when the signin on the old profile is cancelled. | 315 // object will get freed when the signin on the old profile is cancelled. |
| 316 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS, | 316 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS, |
| 317 signin_metrics::SignoutDelete::IGNORE_METRIC); | 317 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 318 | 318 |
| 319 // Load policy for the just-created profile - once policy has finished | 319 // Load policy for the just-created profile - once policy has finished |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 chrome::ShowSettings(browser_); | 601 chrome::ShowSettings(browser_); |
| 602 else if (!continue_url_.is_empty()) | 602 else if (!continue_url_.is_empty()) |
| 603 LoadContinueUrl(); | 603 LoadContinueUrl(); |
| 604 else | 604 else |
| 605 ShowSettingsPageInWebContents(web_contents(), std::string()); | 605 ShowSettingsPageInWebContents(web_contents(), std::string()); |
| 606 } | 606 } |
| 607 } | 607 } |
| 608 } | 608 } |
| 609 | 609 |
| 610 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { | 610 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { |
| 611 ProfileSyncService* service = NULL; | 611 ProfileSyncService* service = nullptr; |
| 612 if (profile_->IsSyncAllowed()) | 612 if (profile_->IsSyncAllowed()) |
| 613 service = ProfileSyncServiceFactory::GetForProfile(profile_); | 613 service = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 614 return service; | 614 return service; |
| 615 } | 615 } |
| 616 | 616 |
| 617 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 617 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
| 618 sync_blocker_.reset(); | 618 sync_blocker_.reset(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( | 621 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 643 false /* user_gesture */); | 643 false /* user_gesture */); |
| 644 } | 644 } |
| 645 | 645 |
| 646 void OneClickSigninSyncStarter::LoadContinueUrl() { | 646 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 647 web_contents()->GetController().LoadURL( | 647 web_contents()->GetController().LoadURL( |
| 648 continue_url_, | 648 continue_url_, |
| 649 content::Referrer(), | 649 content::Referrer(), |
| 650 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 650 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 651 std::string()); | 651 std::string()); |
| 652 } | 652 } |
| OLD | NEW |