| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/signin/inline_login_handler_impl.h" | 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | 67 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, |
| 68 signin_metrics::HISTOGRAM_MAX); | 68 signin_metrics::HISTOGRAM_MAX); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Returns true if |profile| is a system profile or created from one. | 71 // Returns true if |profile| is a system profile or created from one. |
| 72 bool IsSystemProfile(Profile* profile) { | 72 bool IsSystemProfile(Profile* profile) { |
| 73 return profile->GetOriginalProfile()->IsSystemProfile(); | 73 return profile->GetOriginalProfile()->IsSystemProfile(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void RedirectToNtpOrAppsPage(content::WebContents* contents, | 76 void RedirectToNtpOrAppsPage(content::WebContents* contents, |
| 77 signin_metrics::Source source) { | 77 signin_metrics::AccessPoint access_point) { |
| 78 // Do nothing if a navigation is pending, since this call can be triggered | 78 // Do nothing if a navigation is pending, since this call can be triggered |
| 79 // from DidStartLoading. This avoids deleting the pending entry while we are | 79 // from DidStartLoading. This avoids deleting the pending entry while we are |
| 80 // still navigating to it. See crbug/346632. | 80 // still navigating to it. See crbug/346632. |
| 81 if (contents->GetController().GetPendingEntry()) | 81 if (contents->GetController().GetPendingEntry()) |
| 82 return; | 82 return; |
| 83 | 83 |
| 84 VLOG(1) << "RedirectToNtpOrAppsPage"; | 84 VLOG(1) << "RedirectToNtpOrAppsPage"; |
| 85 // Redirect to NTP/Apps page and display a confirmation bubble | 85 // Redirect to NTP/Apps page and display a confirmation bubble |
| 86 GURL url(source == signin_metrics::SOURCE_APPS_PAGE_LINK ? | 86 GURL url(access_point == signin_metrics::ACCESS_POINT_APPS_PAGE_LINK |
| 87 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | 87 ? chrome::kChromeUIAppsURL |
| 88 : chrome::kChromeUINewTabURL); |
| 88 content::OpenURLParams params(url, | 89 content::OpenURLParams params(url, |
| 89 content::Referrer(), | 90 content::Referrer(), |
| 90 CURRENT_TAB, | 91 CURRENT_TAB, |
| 91 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 92 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 92 false); | 93 false); |
| 93 contents->OpenURL(params); | 94 contents->OpenURL(params); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void RedirectToNtpOrAppsPageIfNecessary(content::WebContents* contents, | 97 void RedirectToNtpOrAppsPageIfNecessary( |
| 97 signin_metrics::Source source) { | 98 content::WebContents* contents, |
| 98 if (source != signin_metrics::SOURCE_SETTINGS) | 99 signin_metrics::AccessPoint access_point) { |
| 99 RedirectToNtpOrAppsPage(contents, source); | 100 if (access_point != signin_metrics::ACCESS_POINT_SETTINGS) |
| 101 RedirectToNtpOrAppsPage(contents, access_point); |
| 100 } | 102 } |
| 101 | 103 |
| 102 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { | 104 class ConfirmEmailDialogDelegate : public TabModalConfirmDialogDelegate { |
| 103 public: | 105 public: |
| 104 // Callback indicating action performed by the user. | 106 // Callback indicating action performed by the user. |
| 105 typedef base::Callback<void(InlineSigninHelper::Action)> Callback; | 107 typedef base::Callback<void(InlineSigninHelper::Action)> Callback; |
| 106 | 108 |
| 107 // Ask the user for confirmation before starting to sync. | 109 // Ask the user for confirmation before starting to sync. |
| 108 static void AskForConfirmation(content::WebContents* contents, | 110 static void AskForConfirmation(content::WebContents* contents, |
| 109 const std::string& last_email, | 111 const std::string& last_email, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 267 |
| 266 AboutSigninInternals* about_signin_internals = | 268 AboutSigninInternals* about_signin_internals = |
| 267 AboutSigninInternalsFactory::GetForProfile(profile_); | 269 AboutSigninInternalsFactory::GetForProfile(profile_); |
| 268 about_signin_internals->OnRefreshTokenReceived("Successful"); | 270 about_signin_internals->OnRefreshTokenReceived("Successful"); |
| 269 | 271 |
| 270 // Prime the account tracker with this combination of gaia id/display email. | 272 // Prime the account tracker with this combination of gaia id/display email. |
| 271 std::string account_id = | 273 std::string account_id = |
| 272 AccountTrackerServiceFactory::GetForProfile(profile_) | 274 AccountTrackerServiceFactory::GetForProfile(profile_) |
| 273 ->SeedAccountInfo(gaia_id_, email_); | 275 ->SeedAccountInfo(gaia_id_, email_); |
| 274 | 276 |
| 275 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url_); | 277 signin_metrics::AccessPoint access_point = |
| 278 signin::GetAccessPointForPromoURL(current_url_); |
| 279 signin_metrics::Reason reason = |
| 280 signin::GetSigninReasonForPromoURL(current_url_); |
| 276 | 281 |
| 277 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_); | 282 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile_); |
| 278 std::string primary_email = | 283 std::string primary_email = |
| 279 signin_manager->GetAuthenticatedAccountInfo().email; | 284 signin_manager->GetAuthenticatedAccountInfo().email; |
| 280 if (gaia::AreEmailsSame(email_, primary_email) && | 285 if (gaia::AreEmailsSame(email_, primary_email) && |
| 281 source == signin_metrics::SOURCE_REAUTH && | 286 (reason == signin_metrics::REASON_REAUTHENTICATION || |
| 282 switches::IsNewProfileManagement() && | 287 reason == signin_metrics::REASON_UNLOCK) && |
| 283 !password_.empty() && | 288 switches::IsNewProfileManagement() && !password_.empty() && |
| 284 profiles::IsLockAvailable(profile_)) { | 289 profiles::IsLockAvailable(profile_)) { |
| 285 LocalAuth::SetLocalAuthCredentials(profile_, password_); | 290 LocalAuth::SetLocalAuthCredentials(profile_, password_); |
| 286 } | 291 } |
| 287 | 292 |
| 288 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || | 293 if (reason == signin_metrics::REASON_REAUTHENTICATION || |
| 289 source == signin_metrics::SOURCE_REAUTH) { | 294 reason == signin_metrics::REASON_UNLOCK || |
| 295 reason == signin_metrics::REASON_ADD_SECONDARY_ACCOUNT) { |
| 290 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> | 296 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 291 UpdateCredentials(account_id, result.refresh_token); | 297 UpdateCredentials(account_id, result.refresh_token); |
| 292 | 298 |
| 293 if (signin::IsAutoCloseEnabledInURL(current_url_)) { | 299 if (signin::IsAutoCloseEnabledInURL(current_url_)) { |
| 294 // Close the gaia sign in tab via a task to make sure we aren't in the | 300 // Close the gaia sign in tab via a task to make sure we aren't in the |
| 295 // middle of any webui handler code. | 301 // middle of any webui handler code. |
| 296 base::ThreadTaskRunnerHandle::Get()->PostTask( | 302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 297 FROM_HERE, | 303 FROM_HERE, |
| 298 base::Bind(&InlineLoginHandlerImpl::CloseTab, handler_, | 304 base::Bind(&InlineLoginHandlerImpl::CloseTab, handler_, |
| 299 signin::ShouldShowAccountManagement(current_url_))); | 305 signin::ShouldShowAccountManagement(current_url_))); |
| 300 } | 306 } |
| 301 | 307 |
| 302 if (source == signin_metrics::SOURCE_REAUTH) | 308 if (reason == signin_metrics::REASON_REAUTHENTICATION || |
| 309 reason == signin_metrics::REASON_UNLOCK) { |
| 303 signin_manager->MergeSigninCredentialIntoCookieJar(); | 310 signin_manager->MergeSigninCredentialIntoCookieJar(); |
| 311 } |
| 304 } else { | 312 } else { |
| 305 ProfileSyncService* sync_service = | 313 ProfileSyncService* sync_service = |
| 306 ProfileSyncServiceFactory::GetForProfile(profile_); | 314 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 307 SigninErrorController* error_controller = | 315 SigninErrorController* error_controller = |
| 308 SigninErrorControllerFactory::GetForProfile(profile_); | 316 SigninErrorControllerFactory::GetForProfile(profile_); |
| 309 | 317 |
| 310 OneClickSigninSyncStarter::StartSyncMode start_mode = | 318 OneClickSigninSyncStarter::StartSyncMode start_mode = |
| 311 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST; | 319 OneClickSigninSyncStarter::CONFIRM_SYNC_SETTINGS_FIRST; |
| 312 if (source == signin_metrics::SOURCE_SETTINGS || choose_what_to_sync_) { | 320 if (access_point == signin_metrics::ACCESS_POINT_SETTINGS || |
| 321 choose_what_to_sync_) { |
| 313 bool show_settings_without_configure = | 322 bool show_settings_without_configure = |
| 314 error_controller->HasError() && | 323 error_controller->HasError() && |
| 315 sync_service && | 324 sync_service && |
| 316 sync_service->HasSyncSetupCompleted(); | 325 sync_service->HasSyncSetupCompleted(); |
| 317 start_mode = show_settings_without_configure ? | 326 start_mode = show_settings_without_configure ? |
| 318 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : | 327 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : |
| 319 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST; | 328 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST; |
| 320 } | 329 } |
| 321 | 330 |
| 322 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = | 331 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required = |
| 323 confirm_untrusted_signin_ ? | 332 confirm_untrusted_signin_ ? |
| 324 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN : | 333 OneClickSigninSyncStarter::CONFIRM_UNTRUSTED_SIGNIN : |
| 325 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; | 334 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN; |
| 326 | 335 |
| 327 bool start_signin = !HandleCrossAccountError(result.refresh_token, source, | 336 bool start_signin = !HandleCrossAccountError( |
| 328 confirmation_required, start_mode); | 337 result.refresh_token, confirmation_required, start_mode); |
| 329 if (start_signin) { | 338 if (start_signin) { |
| 330 CreateSyncStarter(browser, | 339 CreateSyncStarter(browser, contents, current_url_, |
| 331 contents, | |
| 332 signin::GetNextPageURLForPromoURL(current_url_), | 340 signin::GetNextPageURLForPromoURL(current_url_), |
| 333 result.refresh_token, | 341 result.refresh_token, start_mode, |
| 334 start_mode, | |
| 335 confirmation_required); | 342 confirmation_required); |
| 336 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 343 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 337 } | 344 } |
| 338 } | 345 } |
| 339 } | 346 } |
| 340 | 347 |
| 341 void InlineSigninHelper::CreateSyncStarter( | 348 void InlineSigninHelper::CreateSyncStarter( |
| 342 Browser* browser, | 349 Browser* browser, |
| 343 content::WebContents* contents, | 350 content::WebContents* contents, |
| 344 const GURL& url, | 351 const GURL& current_url, |
| 352 const GURL& continue_url, |
| 345 const std::string& refresh_token, | 353 const std::string& refresh_token, |
| 346 OneClickSigninSyncStarter::StartSyncMode start_mode, | 354 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 347 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required) { | 355 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required) { |
| 348 // OneClickSigninSyncStarter will delete itself once the job is done. | 356 // OneClickSigninSyncStarter will delete itself once the job is done. |
| 349 new OneClickSigninSyncStarter( | 357 new OneClickSigninSyncStarter( |
| 350 profile_, browser, | 358 profile_, browser, gaia_id_, email_, password_, refresh_token, start_mode, |
| 351 gaia_id_, email_, password_, refresh_token, | 359 contents, confirmation_required, current_url, continue_url, |
| 352 start_mode, | |
| 353 contents, | |
| 354 confirmation_required, | |
| 355 url, | |
| 356 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); | 360 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); |
| 357 } | 361 } |
| 358 | 362 |
| 359 bool InlineSigninHelper::HandleCrossAccountError( | 363 bool InlineSigninHelper::HandleCrossAccountError( |
| 360 const std::string& refresh_token, | 364 const std::string& refresh_token, |
| 361 signin_metrics::Source source, | |
| 362 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | 365 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 363 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 366 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 364 std::string last_email = | 367 std::string last_email = |
| 365 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 368 profile_->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 366 | 369 |
| 367 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) | 370 if (last_email.empty() || gaia::AreEmailsSame(last_email, email_)) |
| 368 return false; | 371 return false; |
| 369 | 372 |
| 370 Browser* browser = chrome::FindLastActiveWithProfile( | 373 Browser* browser = chrome::FindLastActiveWithProfile( |
| 371 profile_, chrome::GetActiveDesktop()); | 374 profile_, chrome::GetActiveDesktop()); |
| 372 content::WebContents* web_contents = | 375 content::WebContents* web_contents = |
| 373 browser->tab_strip_model()->GetActiveWebContents(); | 376 browser->tab_strip_model()->GetActiveWebContents(); |
| 374 | 377 |
| 375 ConfirmEmailDialogDelegate::AskForConfirmation( | 378 ConfirmEmailDialogDelegate::AskForConfirmation( |
| 376 web_contents, | 379 web_contents, |
| 377 last_email, | 380 last_email, |
| 378 email_, | 381 email_, |
| 379 base::Bind(&InlineSigninHelper::ConfirmEmailAction, | 382 base::Bind(&InlineSigninHelper::ConfirmEmailAction, |
| 380 base::Unretained(this), | 383 base::Unretained(this), |
| 381 web_contents, | 384 web_contents, |
| 382 refresh_token, | 385 refresh_token, |
| 383 source, | |
| 384 confirmation_required, | 386 confirmation_required, |
| 385 start_mode)); | 387 start_mode)); |
| 386 return true; | 388 return true; |
| 387 } | 389 } |
| 388 | 390 |
| 389 void InlineSigninHelper::ConfirmEmailAction( | 391 void InlineSigninHelper::ConfirmEmailAction( |
| 390 content::WebContents* web_contents, | 392 content::WebContents* web_contents, |
| 391 const std::string& refresh_token, | 393 const std::string& refresh_token, |
| 392 signin_metrics::Source source, | |
| 393 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, | 394 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, |
| 394 OneClickSigninSyncStarter::StartSyncMode start_mode, | 395 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 395 InlineSigninHelper::Action action) { | 396 InlineSigninHelper::Action action) { |
| 396 Browser* browser = chrome::FindLastActiveWithProfile( | 397 Browser* browser = chrome::FindLastActiveWithProfile( |
| 397 profile_, chrome::GetActiveDesktop()); | 398 profile_, chrome::GetActiveDesktop()); |
| 398 switch (action) { | 399 switch (action) { |
| 399 case InlineSigninHelper::CREATE_NEW_USER: | 400 case InlineSigninHelper::CREATE_NEW_USER: |
| 400 if (handler_) { | 401 if (handler_) { |
| 401 handler_->SyncStarterCallback( | 402 handler_->SyncStarterCallback( |
| 402 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 403 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 403 } | 404 } |
| 404 chrome::ShowSettingsSubPage(browser, | 405 chrome::ShowSettingsSubPage(browser, |
| 405 std::string(chrome::kCreateProfileSubPage)); | 406 std::string(chrome::kCreateProfileSubPage)); |
| 406 break; | 407 break; |
| 407 case InlineSigninHelper::START_SYNC: | 408 case InlineSigninHelper::START_SYNC: |
| 408 CreateSyncStarter(browser, web_contents, GURL(), refresh_token, | 409 CreateSyncStarter(browser, web_contents, current_url_, GURL(), |
| 409 start_mode, confirmation_required); | 410 refresh_token, start_mode, confirmation_required); |
| 410 break; | 411 break; |
| 411 case InlineSigninHelper::CLOSE: | 412 case InlineSigninHelper::CLOSE: |
| 412 if (handler_) { | 413 if (handler_) { |
| 413 handler_->SyncStarterCallback( | 414 handler_->SyncStarterCallback( |
| 414 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); | 415 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); |
| 415 } | 416 } |
| 416 break; | 417 break; |
| 417 default: | 418 default: |
| 418 DCHECK(false) << "Invalid action"; | 419 DCHECK(false) << "Invalid action"; |
| 419 } | 420 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 params.SetString("service", "chromiumsync"); | 553 params.SetString("service", "chromiumsync"); |
| 553 | 554 |
| 554 // If this was called from the user manager to reauthenticate the profile, | 555 // If this was called from the user manager to reauthenticate the profile, |
| 555 // make sure the webui is aware. | 556 // make sure the webui is aware. |
| 556 Profile* profile = Profile::FromWebUI(web_ui()); | 557 Profile* profile = Profile::FromWebUI(web_ui()); |
| 557 if (IsSystemProfile(profile)) | 558 if (IsSystemProfile(profile)) |
| 558 params.SetBoolean("dontResizeNonEmbeddedPages", true); | 559 params.SetBoolean("dontResizeNonEmbeddedPages", true); |
| 559 | 560 |
| 560 content::WebContents* contents = web_ui()->GetWebContents(); | 561 content::WebContents* contents = web_ui()->GetWebContents(); |
| 561 const GURL& current_url = contents->GetURL(); | 562 const GURL& current_url = contents->GetURL(); |
| 562 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | 563 signin_metrics::Reason reason = |
| 564 signin::GetSigninReasonForPromoURL(current_url); |
| 563 | 565 |
| 564 std::string is_constrained; | 566 std::string is_constrained; |
| 565 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); | 567 net::GetValueForKeyInQuery(current_url, "constrained", &is_constrained); |
| 566 | 568 |
| 567 // Use new embedded flow if in constrained window. | 569 // Use new embedded flow if in constrained window. |
| 568 if (is_constrained == "1") { | 570 if (is_constrained == "1") { |
| 569 const bool is_new_gaia_flow = switches::UsePasswordSeparatedSigninFlow(); | 571 const bool is_new_gaia_flow = switches::UsePasswordSeparatedSigninFlow(); |
| 570 const GURL& url = is_new_gaia_flow | 572 const GURL& url = is_new_gaia_flow |
| 571 ? GaiaUrls::GetInstance()->embedded_signin_url() | 573 ? GaiaUrls::GetInstance()->embedded_signin_url() |
| 572 : GaiaUrls::GetInstance()->password_combined_embedded_signin_url(); | 574 : GaiaUrls::GetInstance()->password_combined_embedded_signin_url(); |
| 573 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow); | 575 params.SetBoolean("isNewGaiaFlow", is_new_gaia_flow); |
| 574 params.SetString("clientId", | 576 params.SetString("clientId", |
| 575 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); | 577 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); |
| 576 params.SetString("gaiaPath", url.path().substr(1)); | 578 params.SetString("gaiaPath", url.path().substr(1)); |
| 577 | 579 |
| 578 std::string flow; | 580 std::string flow; |
| 579 switch (source) { | 581 switch (reason) { |
| 580 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: | 582 case signin_metrics::REASON_ADD_SECONDARY_ACCOUNT: |
| 581 flow = "addaccount"; | 583 flow = "addaccount"; |
| 582 break; | 584 break; |
| 583 case signin_metrics::SOURCE_REAUTH: | 585 case signin_metrics::REASON_REAUTHENTICATION: |
| 586 case signin_metrics::REASON_UNLOCK: |
| 584 flow = "reauth"; | 587 flow = "reauth"; |
| 585 break; | 588 break; |
| 586 default: | 589 default: |
| 587 flow = "signin"; | 590 flow = "signin"; |
| 588 break; | 591 break; |
| 589 } | 592 } |
| 590 params.SetString("flow", flow); | 593 params.SetString("flow", flow); |
| 591 } | 594 } |
| 592 | 595 |
| 593 content::WebContentsObserver::Observe(contents); | 596 content::WebContentsObserver::Observe(contents); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 if (!gaia::AreEmailsSame(params.email, default_email)) { | 735 if (!gaia::AreEmailsSame(params.email, default_email)) { |
| 733 if (params.handler) { | 736 if (params.handler) { |
| 734 params.handler->HandleLoginError( | 737 params.handler->HandleLoginError( |
| 735 l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, | 738 l10n_util::GetStringFUTF8(IDS_SYNC_WRONG_EMAIL, |
| 736 base::UTF8ToUTF16(default_email))); | 739 base::UTF8ToUTF16(default_email))); |
| 737 } | 740 } |
| 738 return; | 741 return; |
| 739 } | 742 } |
| 740 } | 743 } |
| 741 | 744 |
| 742 signin_metrics::Source source = signin::GetSourceForPromoURL(params.url); | 745 signin_metrics::AccessPoint access_point = |
| 746 signin::GetAccessPointForPromoURL(params.url); |
| 747 signin_metrics::Reason reason = |
| 748 signin::GetSigninReasonForPromoURL(params.url); |
| 743 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); | 749 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); |
| 744 bool switch_to_advanced = | 750 bool switch_to_advanced = |
| 745 params.choose_what_to_sync && (source != signin_metrics::SOURCE_SETTINGS); | 751 params.choose_what_to_sync && |
| 752 (access_point != signin_metrics::ACCESS_POINT_SETTINGS); |
| 746 LogHistogramValue( | 753 LogHistogramValue( |
| 747 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : | 754 switch_to_advanced ? signin_metrics::HISTOGRAM_WITH_ADVANCED : |
| 748 signin_metrics::HISTOGRAM_WITH_DEFAULTS); | 755 signin_metrics::HISTOGRAM_WITH_DEFAULTS); |
| 749 | 756 |
| 750 CanOfferFor can_offer_for = CAN_OFFER_FOR_ALL; | 757 CanOfferFor can_offer_for = CAN_OFFER_FOR_ALL; |
| 751 switch (source) { | 758 switch (reason) { |
| 752 case signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT: | 759 case signin_metrics::REASON_ADD_SECONDARY_ACCOUNT: |
| 753 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; | 760 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
| 754 break; | 761 break; |
| 755 case signin_metrics::SOURCE_REAUTH: { | 762 case signin_metrics::REASON_REAUTHENTICATION: |
| 763 case signin_metrics::REASON_UNLOCK: { |
| 756 std::string primary_username = | 764 std::string primary_username = |
| 757 SigninManagerFactory::GetForProfile(profile) | 765 SigninManagerFactory::GetForProfile(profile) |
| 758 ->GetAuthenticatedAccountInfo() | 766 ->GetAuthenticatedAccountInfo() |
| 759 .email; | 767 .email; |
| 760 if (!gaia::AreEmailsSame(default_email, primary_username)) | 768 if (!gaia::AreEmailsSame(default_email, primary_username)) |
| 761 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; | 769 can_offer_for = CAN_OFFER_FOR_SECONDARY_ACCOUNT; |
| 762 break; | 770 break; |
| 763 } | 771 } |
| 764 default: | 772 default: |
| 765 // No need to change |can_offer_for|. | 773 // No need to change |can_offer_for|. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 content::WebContents* contents = web_ui()->GetWebContents(); | 849 content::WebContents* contents = web_ui()->GetWebContents(); |
| 842 | 850 |
| 843 if (contents->GetController().GetPendingEntry()) { | 851 if (contents->GetController().GetPendingEntry()) { |
| 844 // Do nothing if a navigation is pending, since this call can be triggered | 852 // Do nothing if a navigation is pending, since this call can be triggered |
| 845 // from DidStartLoading. This avoids deleting the pending entry while we are | 853 // from DidStartLoading. This avoids deleting the pending entry while we are |
| 846 // still navigating to it. See crbug/346632. | 854 // still navigating to it. See crbug/346632. |
| 847 return; | 855 return; |
| 848 } | 856 } |
| 849 | 857 |
| 850 const GURL& current_url = contents->GetLastCommittedURL(); | 858 const GURL& current_url = contents->GetLastCommittedURL(); |
| 851 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); | 859 signin_metrics::AccessPoint access_point = |
| 860 signin::GetAccessPointForPromoURL(current_url); |
| 852 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); | 861 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); |
| 853 | 862 |
| 854 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { | 863 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { |
| 855 RedirectToNtpOrAppsPage(contents, source); | 864 RedirectToNtpOrAppsPage(contents, access_point); |
| 856 } else if (auto_close) { | 865 } else if (auto_close) { |
| 857 base::ThreadTaskRunnerHandle::Get()->PostTask( | 866 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 858 FROM_HERE, | 867 FROM_HERE, |
| 859 base::Bind(&InlineLoginHandlerImpl::CloseTab, | 868 base::Bind(&InlineLoginHandlerImpl::CloseTab, |
| 860 weak_factory_.GetWeakPtr(), | 869 weak_factory_.GetWeakPtr(), |
| 861 signin::ShouldShowAccountManagement(current_url))); | 870 signin::ShouldShowAccountManagement(current_url))); |
| 862 } else { | 871 } else { |
| 863 RedirectToNtpOrAppsPageIfNecessary(contents, source); | 872 RedirectToNtpOrAppsPageIfNecessary(contents, access_point); |
| 864 } | 873 } |
| 865 } | 874 } |
| 866 | 875 |
| 867 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { | 876 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { |
| 868 content::WebContents* tab = web_ui()->GetWebContents(); | 877 content::WebContents* tab = web_ui()->GetWebContents(); |
| 869 Browser* browser = chrome::FindBrowserWithWebContents(tab); | 878 Browser* browser = chrome::FindBrowserWithWebContents(tab); |
| 870 if (browser) { | 879 if (browser) { |
| 871 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 880 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| 872 if (tab_strip_model) { | 881 if (tab_strip_model) { |
| 873 int index = tab_strip_model->GetIndexOfWebContents(tab); | 882 int index = tab_strip_model->GetIndexOfWebContents(tab); |
| 874 if (index != TabStripModel::kNoTab) { | 883 if (index != TabStripModel::kNoTab) { |
| 875 tab_strip_model->ExecuteContextMenuCommand( | 884 tab_strip_model->ExecuteContextMenuCommand( |
| 876 index, TabStripModel::CommandCloseTab); | 885 index, TabStripModel::CommandCloseTab); |
| 877 } | 886 } |
| 878 } | 887 } |
| 879 | 888 |
| 880 if (show_account_management) { | 889 if (show_account_management) { |
| 881 browser->window()->ShowAvatarBubbleFromAvatarButton( | 890 browser->window()->ShowAvatarBubbleFromAvatarButton( |
| 882 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, | 891 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, |
| 883 signin::ManageAccountsParams()); | 892 signin::ManageAccountsParams(), |
| 893 signin_metrics::ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN); |
| 884 } | 894 } |
| 885 } | 895 } |
| 886 } | 896 } |
| OLD | NEW |