Chromium Code Reviews| 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_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 // Add a specific email to the list of emails rejected for one-click | 84 // Add a specific email to the list of emails rejected for one-click |
| 85 // sign-in, for this profile. | 85 // sign-in, for this profile. |
| 86 void AddEmailToOneClickRejectedList(Profile* profile, | 86 void AddEmailToOneClickRejectedList(Profile* profile, |
| 87 const std::string& email) { | 87 const std::string& email) { |
| 88 PrefService* pref_service = profile->GetPrefs(); | 88 PrefService* pref_service = profile->GetPrefs(); |
| 89 ListPrefUpdate updater(pref_service, | 89 ListPrefUpdate updater(pref_service, |
| 90 prefs::kReverseAutologinRejectedEmailList); | 90 prefs::kReverseAutologinRejectedEmailList); |
| 91 updater->AppendIfNotPresent(new base::StringValue(email)); | 91 updater->AppendIfNotPresent(new base::StringValue(email)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void LogHistogramValue(SyncPromoUI::Source source, int action) { | |
| 95 switch (source) { | |
| 96 case SyncPromoUI::SOURCE_START_PAGE: | |
| 97 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, | |
| 98 one_click_signin::HISTOGRAM_MAX); | |
| 99 break; | |
| 100 case SyncPromoUI::SOURCE_NTP_LINK: | |
| 101 UMA_HISTOGRAM_ENUMERATION("Signin.NTPLinkActions", action, | |
| 102 one_click_signin::HISTOGRAM_MAX); | |
| 103 break; | |
| 104 case SyncPromoUI::SOURCE_MENU: | |
| 105 UMA_HISTOGRAM_ENUMERATION("Signin.MenuActions", action, | |
| 106 one_click_signin::HISTOGRAM_MAX); | |
| 107 break; | |
| 108 case SyncPromoUI::SOURCE_SETTINGS: | |
| 109 UMA_HISTOGRAM_ENUMERATION("Signin.SettingsActions", action, | |
| 110 one_click_signin::HISTOGRAM_MAX); | |
| 111 break; | |
| 112 case SyncPromoUI::SOURCE_EXTENSION_INSTALL_BUBBLE: | |
| 113 UMA_HISTOGRAM_ENUMERATION("Signin.ExtensionInstallBubbleActions", action, | |
| 114 one_click_signin::HISTOGRAM_MAX); | |
| 115 break; | |
| 116 case SyncPromoUI::SOURCE_WEBSTORE_INSTALL: | |
| 117 UMA_HISTOGRAM_ENUMERATION("Signin.WebstoreInstallActions", action, | |
| 118 one_click_signin::HISTOGRAM_MAX); | |
| 119 break; | |
| 120 case SyncPromoUI::SOURCE_APP_LAUNCHER: | |
| 121 UMA_HISTOGRAM_ENUMERATION("Signin.AppLauncherActions", action, | |
| 122 one_click_signin::HISTOGRAM_MAX); | |
| 123 break; | |
| 124 default: | |
| 125 NOTREACHED() << "Invalid Source"; | |
| 126 return; | |
| 127 } | |
| 128 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | |
| 129 one_click_signin::HISTOGRAM_MAX); | |
| 130 } | |
| 131 | |
| 132 void LogOneClickHistogramValue(int action) { | |
| 133 UMA_HISTOGRAM_ENUMERATION("Signin.OneClickActions", action, | |
| 134 one_click_signin::HISTOGRAM_MAX); | |
| 135 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | |
| 136 one_click_signin::HISTOGRAM_MAX); | |
| 137 } | |
| 138 | |
| 94 // Arguments used with StartSync function. base::Bind() cannot support too | 139 // Arguments used with StartSync function. base::Bind() cannot support too |
| 95 // many args for performance reasons, so they are packaged up into a struct. | 140 // many args for performance reasons, so they are packaged up into a struct. |
| 96 struct StartSyncArgs { | 141 struct StartSyncArgs { |
| 97 StartSyncArgs(Profile* profile, | 142 StartSyncArgs(Profile* profile, |
| 98 Browser* browser, | 143 Browser* browser, |
| 99 OneClickSigninHelper::AutoAccept auto_accept, | 144 OneClickSigninHelper::AutoAccept auto_accept, |
| 100 const std::string& session_index, | 145 const std::string& session_index, |
| 101 const std::string& email, | 146 const std::string& email, |
| 102 const std::string& password, | 147 const std::string& password, |
| 103 bool force_same_tab_navigation) | 148 bool force_same_tab_navigation, |
| 149 SyncPromoUI::Source source) | |
| 104 : profile(profile), | 150 : profile(profile), |
| 105 browser(browser), | 151 browser(browser), |
| 106 auto_accept(auto_accept), | 152 auto_accept(auto_accept), |
| 107 session_index(session_index), | 153 session_index(session_index), |
| 108 email(email), | 154 email(email), |
| 109 password(password), | 155 password(password), |
| 110 force_same_tab_navigation(force_same_tab_navigation) { | 156 force_same_tab_navigation(force_same_tab_navigation), |
| 157 source(source) { | |
| 111 } | 158 } |
| 112 | 159 |
| 113 Profile* profile; | 160 Profile* profile; |
| 114 Browser* browser; | 161 Browser* browser; |
| 115 OneClickSigninHelper::AutoAccept auto_accept; | 162 OneClickSigninHelper::AutoAccept auto_accept; |
| 116 std::string session_index; | 163 std::string session_index; |
| 117 std::string email; | 164 std::string email; |
| 118 std::string password; | 165 std::string password; |
| 119 bool force_same_tab_navigation; | 166 bool force_same_tab_navigation; |
| 167 SyncPromoUI::Source source; | |
|
Roger Tawa OOO till Jul 10th
2013/02/28 20:23:54
Is this extra member needed? It does not seem use
jwd
2013/02/28 20:45:38
Done.
| |
| 120 }; | 168 }; |
| 121 | 169 |
| 122 // Start syncing with the given user information. | 170 // Start syncing with the given user information. |
| 123 void StartSync(const StartSyncArgs& args, | 171 void StartSync(const StartSyncArgs& args, |
| 124 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 172 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 125 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { | 173 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { |
| 126 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 174 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_UNDO); |
| 127 one_click_signin::HISTOGRAM_UNDO, | |
| 128 one_click_signin::HISTOGRAM_MAX); | |
| 129 return; | 175 return; |
| 130 } | 176 } |
| 131 // The starter deletes itself once its done. | 177 // The starter deletes itself once its done. |
| 132 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, | 178 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, |
| 133 args.email, args.password, start_mode, | 179 args.email, args.password, start_mode, |
| 134 args.force_same_tab_navigation); | 180 args.force_same_tab_navigation); |
| 135 | 181 |
| 136 int action = one_click_signin::HISTOGRAM_MAX; | 182 int action = one_click_signin::HISTOGRAM_MAX; |
| 137 switch (args.auto_accept) { | 183 switch (args.auto_accept) { |
| 138 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: | 184 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 151 one_click_signin::HISTOGRAM_WITH_ADVANCED; | 197 one_click_signin::HISTOGRAM_WITH_ADVANCED; |
| 152 break; | 198 break; |
| 153 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: | 199 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: |
| 154 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 200 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 155 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 201 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
| 156 break; | 202 break; |
| 157 default: | 203 default: |
| 158 NOTREACHED() << "Invalid auto_accept: " << args.auto_accept; | 204 NOTREACHED() << "Invalid auto_accept: " << args.auto_accept; |
| 159 break; | 205 break; |
| 160 } | 206 } |
| 161 | 207 LogOneClickHistogramValue(action); |
| 162 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | |
| 163 one_click_signin::HISTOGRAM_MAX); | |
| 164 } | 208 } |
| 165 | 209 |
| 166 void StartExplicitSync(const StartSyncArgs& args, | 210 void StartExplicitSync(const StartSyncArgs& args, |
| 167 content::WebContents* contents, | 211 content::WebContents* contents, |
| 168 OneClickSigninSyncStarter::StartSyncMode start_mode, | 212 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 169 int button) { | 213 int button) { |
| 170 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) { | 214 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) { |
| 171 contents->GetController().LoadURL( | 215 contents->GetController().LoadURL( |
| 172 GURL(chrome::kChromeUINewTabURL), content::Referrer(), | 216 GURL(chrome::kChromeUINewTabURL), content::Referrer(), |
| 173 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 217 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 content::WebContents* contents, | 364 content::WebContents* contents, |
| 321 const std::string& last_email, | 365 const std::string& last_email, |
| 322 const std::string& email, | 366 const std::string& email, |
| 323 Callback callback) | 367 Callback callback) |
| 324 : TabModalConfirmDialogDelegate(contents), | 368 : TabModalConfirmDialogDelegate(contents), |
| 325 last_email_(last_email), | 369 last_email_(last_email), |
| 326 email_(email), | 370 email_(email), |
| 327 callback_(callback) { | 371 callback_(callback) { |
| 328 } | 372 } |
| 329 | 373 |
| 374 // Tells when we are in the process of showing either the signin to chrome page | |
| 375 // or the one click sign in to chrome page. | |
| 376 bool AreWeShowingSignin(GURL url, SyncPromoUI::Source source, | |
| 377 std::string email) { | |
| 378 GURL::Replacements replacements; | |
| 379 replacements.ClearQuery(); | |
| 380 GURL clean_login_url = | |
| 381 GURL(GaiaUrls::GetInstance()->service_login_url()).ReplaceComponents( | |
| 382 replacements); | |
| 383 | |
| 384 return (url.ReplaceComponents(replacements) == clean_login_url && | |
| 385 source != SyncPromoUI::SOURCE_UNKNOWN) || !email.empty(); | |
| 386 } | |
| 387 | |
| 330 } // namespace | 388 } // namespace |
| 331 | 389 |
| 332 // The infobar asking the user if they want to use one-click sign in. | 390 // The infobar asking the user if they want to use one-click sign in. |
| 333 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid | 391 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid |
| 334 // of this infobar. | 392 // of this infobar. |
| 335 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { | 393 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { |
| 336 public: | 394 public: |
| 337 // Creates a one click signin delegate and adds it to |infobar_service|. | 395 // Creates a one click signin delegate and adds it to |infobar_service|. |
| 338 static void Create(InfoBarService* infobar_service, | 396 static void Create(InfoBarService* infobar_service, |
| 339 const std::string& session_index, | 397 const std::string& session_index, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 // this profile. | 504 // this profile. |
| 447 SigninManager::DisableOneClickSignIn(profile); | 505 SigninManager::DisableOneClickSignIn(profile); |
| 448 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 506 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 449 chrome::FindBrowserWithWebContents(web_contents)->window()-> | 507 chrome::FindBrowserWithWebContents(web_contents)->window()-> |
| 450 ShowOneClickSigninBubble( | 508 ShowOneClickSigninBubble( |
| 451 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 509 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 452 base::Bind(&StartSync, | 510 base::Bind(&StartSync, |
| 453 StartSyncArgs(profile, browser, | 511 StartSyncArgs(profile, browser, |
| 454 OneClickSigninHelper::AUTO_ACCEPT_NONE, | 512 OneClickSigninHelper::AUTO_ACCEPT_NONE, |
| 455 session_index_, email_, password_, | 513 session_index_, email_, password_, |
| 456 false /* force_same_tab_navigation */))); | 514 false /* force_same_tab_navigation */, |
| 515 SyncPromoUI::SOURCE_UNKNOWN))); | |
| 457 button_pressed_ = true; | 516 button_pressed_ = true; |
| 458 return true; | 517 return true; |
| 459 } | 518 } |
| 460 | 519 |
| 461 bool OneClickInfoBarDelegateImpl::Cancel() { | 520 bool OneClickInfoBarDelegateImpl::Cancel() { |
| 462 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( | 521 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( |
| 463 owner()->GetWebContents()->GetBrowserContext()), email_); | 522 owner()->GetWebContents()->GetBrowserContext()), email_); |
| 464 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 523 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 465 button_pressed_ = true; | 524 button_pressed_ = true; |
| 466 return true; | 525 return true; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 495 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); | 554 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); |
| 496 } | 555 } |
| 497 | 556 |
| 498 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { | 557 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { |
| 499 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 558 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 500 one_click_signin::HISTOGRAM_MAX); | 559 one_click_signin::HISTOGRAM_MAX); |
| 501 } | 560 } |
| 502 | 561 |
| 503 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 562 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
| 504 : content::WebContentsObserver(web_contents), | 563 : content::WebContentsObserver(web_contents), |
| 564 showing_signin_(false), | |
| 505 auto_accept_(AUTO_ACCEPT_NONE), | 565 auto_accept_(AUTO_ACCEPT_NONE), |
| 506 source_(SyncPromoUI::SOURCE_UNKNOWN) { | 566 source_(SyncPromoUI::SOURCE_UNKNOWN), |
| 567 switched_to_advanced_(false) { | |
| 507 } | 568 } |
| 508 | 569 |
| 509 OneClickSigninHelper::~OneClickSigninHelper() { | 570 OneClickSigninHelper::~OneClickSigninHelper() { |
| 510 content::WebContents* contents = web_contents(); | 571 content::WebContents* contents = web_contents(); |
| 511 if (contents) { | 572 if (contents) { |
| 512 Profile* profile = | 573 Profile* profile = |
| 513 Profile::FromBrowserContext(contents->GetBrowserContext()); | 574 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 514 ProfileSyncService* sync_service = | 575 ProfileSyncService* sync_service = |
| 515 ProfileSyncServiceFactory::GetForProfile(profile); | 576 ProfileSyncServiceFactory::GetForProfile(profile); |
| 516 if (sync_service && sync_service->HasObserver(this)) | 577 if (sync_service && sync_service->HasObserver(this)) |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, | 894 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
| 834 route_id); | 895 route_id); |
| 835 | 896 |
| 836 // TODO(mathp): The appearance of this infobar should be tested using a | 897 // TODO(mathp): The appearance of this infobar should be tested using a |
| 837 // browser_test. | 898 // browser_test. |
| 838 OneClickSigninHelper* helper = | 899 OneClickSigninHelper* helper = |
| 839 OneClickSigninHelper::FromWebContents(web_contents); | 900 OneClickSigninHelper::FromWebContents(web_contents); |
| 840 if (!helper) | 901 if (!helper) |
| 841 return; | 902 return; |
| 842 | 903 |
| 843 // Save the email in the one-click signin manager. The manager may | |
| 844 // not exist if the contents is incognito or if the profile is already | |
| 845 // connected to a Google account. | |
| 846 if (!session_index.empty()) | |
| 847 helper->session_index_ = session_index; | |
| 848 | |
| 849 if (!email.empty()) | |
| 850 helper->email_ = email; | |
| 851 | |
| 852 if (auto_accept != AUTO_ACCEPT_NONE) { | 904 if (auto_accept != AUTO_ACCEPT_NONE) { |
| 853 helper->auto_accept_ = auto_accept; | 905 helper->auto_accept_ = auto_accept; |
| 854 helper->source_ = source; | 906 helper->source_ = source; |
| 855 } | 907 } |
| 856 | 908 |
| 857 CanOfferFor can_offer_for = | 909 CanOfferFor can_offer_for = |
| 858 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 910 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
| 859 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 911 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
| 860 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 912 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
| 861 std::string error_message; | 913 std::string error_message; |
| 862 | 914 |
| 863 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 915 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
| 864 &error_message)) { | 916 &error_message)) { |
| 865 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 917 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
| 866 if (helper && helper->error_message_.empty() && !error_message.empty()) | 918 if (helper && helper->error_message_.empty() && !error_message.empty()) |
| 867 helper->error_message_ = error_message; | 919 helper->error_message_ = error_message; |
| 868 | 920 |
| 869 return; | 921 return; |
| 870 } | 922 } |
| 871 | 923 |
| 924 // Save the email in the one-click signin manager. The manager may | |
| 925 // not exist if the contents is incognito or if the profile is already | |
| 926 // connected to a Google account. | |
| 927 if (!session_index.empty()) | |
| 928 helper->session_index_ = session_index; | |
| 929 | |
| 930 if (!email.empty()) | |
| 931 helper->email_ = email; | |
| 932 | |
| 872 if (continue_url.is_valid()) | 933 if (continue_url.is_valid()) |
| 873 helper->continue_url_ = continue_url; | 934 helper->continue_url_ = continue_url; |
| 874 } | 935 } |
| 875 | 936 |
| 876 void OneClickSigninHelper::RedirectToNTP(bool show_bubble) { | 937 void OneClickSigninHelper::RedirectToNTP(bool show_bubble) { |
| 877 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; | 938 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; |
| 878 | 939 |
| 879 // Redirect to NTP with sign in bubble visible. | 940 // Redirect to NTP with sign in bubble visible. |
| 880 content::WebContents* contents = web_contents(); | 941 content::WebContents* contents = web_contents(); |
| 881 Profile* profile = | 942 Profile* profile = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 909 | 970 |
| 910 content::WebContents* contents = web_contents(); | 971 content::WebContents* contents = web_contents(); |
| 911 contents->GetController().LoadURL(page, | 972 contents->GetController().LoadURL(page, |
| 912 content::Referrer(), | 973 content::Referrer(), |
| 913 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 974 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 914 std::string()); | 975 std::string()); |
| 915 } | 976 } |
| 916 | 977 |
| 917 void OneClickSigninHelper::CleanTransientState() { | 978 void OneClickSigninHelper::CleanTransientState() { |
| 918 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 979 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
| 980 showing_signin_ = false; | |
| 919 email_.clear(); | 981 email_.clear(); |
| 920 password_.clear(); | 982 password_.clear(); |
| 921 auto_accept_ = AUTO_ACCEPT_NONE; | 983 auto_accept_ = AUTO_ACCEPT_NONE; |
| 922 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 984 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
| 985 switched_to_advanced_ = false; | |
| 923 continue_url_ = GURL(); | 986 continue_url_ = GURL(); |
| 924 | 987 |
| 925 // Post to IO thread to clear pending email. | 988 // Post to IO thread to clear pending email. |
| 926 Profile* profile = | 989 Profile* profile = |
| 927 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 990 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 928 content::BrowserThread::PostTask( | 991 content::BrowserThread::PostTask( |
| 929 content::BrowserThread::IO, FROM_HERE, | 992 content::BrowserThread::IO, FROM_HERE, |
| 930 base::Bind(&ClearPendingEmailOnIOThread, | 993 base::Bind(&ClearPendingEmailOnIOThread, |
| 931 base::Unretained(profile->GetResourceContext()))); | 994 base::Unretained(profile->GetResourceContext()))); |
| 932 } | 995 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 1029 |
| 967 // If an error has already occured during the sign in flow, make sure to | 1030 // If an error has already occured during the sign in flow, make sure to |
| 968 // display it to the user and abort the process. Do this only for | 1031 // display it to the user and abort the process. Do this only for |
| 969 // explicit sign ins. | 1032 // explicit sign ins. |
| 970 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1033 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
| 971 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1034 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
| 972 RedirectToNTP(true); | 1035 RedirectToNTP(true); |
| 973 return; | 1036 return; |
| 974 } | 1037 } |
| 975 | 1038 |
| 1039 if (AreWeShowingSignin(url, source_, email_)) { | |
| 1040 if (!showing_signin_) { | |
| 1041 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) | |
| 1042 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); | |
| 1043 else | |
| 1044 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); | |
| 1045 } | |
| 1046 showing_signin_ = true; | |
| 1047 } | |
| 1048 | |
| 976 // When Gaia finally redirects to the continue URL, Gaia will add some | 1049 // When Gaia finally redirects to the continue URL, Gaia will add some |
| 977 // extra query parameters. So ignore the parameters when checking to see | 1050 // extra query parameters. So ignore the parameters when checking to see |
| 978 // if the user has continued. | 1051 // if the user has continued. |
| 979 GURL::Replacements replacements; | 1052 GURL::Replacements replacements; |
| 980 replacements.ClearQuery(); | 1053 replacements.ClearQuery(); |
| 981 const bool continue_url_match_accept = ( | 1054 const bool continue_url_match_accept = ( |
| 982 auto_accept_ == AUTO_ACCEPT_EXPLICIT && | 1055 auto_accept_ == AUTO_ACCEPT_EXPLICIT && |
| 983 continue_url_.is_valid() && | 1056 continue_url_.is_valid() && |
| 984 url.ReplaceComponents(replacements) == | 1057 url.ReplaceComponents(replacements) == |
| 985 continue_url_.ReplaceComponents(replacements)); | 1058 continue_url_.ReplaceComponents(replacements)); |
| 986 | 1059 |
| 987 // If there is no valid email or password yet, there is nothing to do. | 1060 // If there is no valid email or password yet, there is nothing to do. |
| 988 if (email_.empty() || password_.empty()) { | 1061 if (email_.empty() || password_.empty()) { |
| 1062 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; | |
| 989 if (continue_url_match_accept) | 1063 if (continue_url_match_accept) |
| 990 RedirectToSignin(); | 1064 RedirectToSignin(); |
| 991 std::string unused_value; | 1065 std::string unused_value; |
| 992 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) | 1066 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) |
| 993 RedirectToNTP(false); | 1067 RedirectToNTP(false); |
| 994 return; | 1068 return; |
| 995 } | 1069 } |
| 996 | 1070 |
| 997 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have | 1071 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have |
| 998 // the option of checking the the box "Let me choose what to sync". When the | 1072 // the option of checking the the box "Let me choose what to sync". When the |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 // source of the continue URL. Make one last check of the current URL | 1106 // source of the continue URL. Make one last check of the current URL |
| 1033 // to see if there is a valid source. If so, it overrides the | 1107 // to see if there is a valid source. If so, it overrides the |
| 1034 // current source. | 1108 // current source. |
| 1035 // | 1109 // |
| 1036 // If the source was changed to SOURCE_SETTINGS, we want | 1110 // If the source was changed to SOURCE_SETTINGS, we want |
| 1037 // OneClickSigninSyncStarter to reuse the current tab to display the | 1111 // OneClickSigninSyncStarter to reuse the current tab to display the |
| 1038 // advanced configuration. | 1112 // advanced configuration. |
| 1039 SyncPromoUI::Source source = | 1113 SyncPromoUI::Source source = |
| 1040 SyncPromoUI::GetSourceForSyncPromoURL(url); | 1114 SyncPromoUI::GetSourceForSyncPromoURL(url); |
| 1041 if (source != source_) { | 1115 if (source != source_) { |
| 1116 advanced_source_ = source_; | |
| 1042 source_ = source; | 1117 source_ = source; |
| 1043 force_same_tab_navigation = source_ == SyncPromoUI::SOURCE_SETTINGS; | 1118 force_same_tab_navigation = source == SyncPromoUI::SOURCE_SETTINGS; |
| 1119 switched_to_advanced_ = source == SyncPromoUI::SOURCE_SETTINGS; | |
| 1044 } | 1120 } |
| 1045 } | 1121 } |
| 1046 } | 1122 } |
| 1047 | 1123 |
| 1048 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1124 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 1049 Profile* profile = | 1125 Profile* profile = |
| 1050 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1126 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 1051 | 1127 |
| 1052 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." | 1128 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
| 1053 << " auto_accept=" << auto_accept_ | 1129 << " auto_accept=" << auto_accept_ |
| 1054 << " source=" << source_; | 1130 << " source=" << source_; |
| 1055 | 1131 |
| 1056 BrowserWindow::OneClickSigninBubbleType bubble_type; | 1132 BrowserWindow::OneClickSigninBubbleType bubble_type; |
| 1057 if (base::FieldTrialList::FindFullName(kSignInToChromeDialogFieldTrialName) == | 1133 if (base::FieldTrialList::FindFullName(kSignInToChromeDialogFieldTrialName) == |
| 1058 kSignInConfirmBubbleGroupName) | 1134 kSignInConfirmBubbleGroupName) |
| 1059 bubble_type = BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE; | 1135 bubble_type = BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE; |
| 1060 else | 1136 else |
| 1061 bubble_type = BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG; | 1137 bubble_type = BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG; |
| 1062 | 1138 |
| 1063 switch (auto_accept_) { | 1139 switch (auto_accept_) { |
| 1064 case AUTO_ACCEPT_NONE: | 1140 case AUTO_ACCEPT_NONE: |
| 1065 if (SyncPromoUI::UseWebBasedSigninFlow()) { | 1141 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 1066 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 1142 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_DISMISSED); |
| 1067 one_click_signin::HISTOGRAM_DISMISSED, | |
| 1068 one_click_signin::HISTOGRAM_MAX); | |
| 1069 } else { | 1143 } else { |
| 1070 OneClickInfoBarDelegateImpl::Create( | 1144 OneClickInfoBarDelegateImpl::Create( |
| 1071 InfoBarService::FromWebContents(contents), session_index_, email_, | 1145 InfoBarService::FromWebContents(contents), session_index_, email_, |
| 1072 password_); | 1146 password_); |
| 1073 } | 1147 } |
| 1074 break; | 1148 break; |
| 1075 case AUTO_ACCEPT_ACCEPTED: | 1149 case AUTO_ACCEPT_ACCEPTED: |
| 1150 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | |
| 1151 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_DEFAULTS); | |
| 1076 SigninManager::DisableOneClickSignIn(profile); | 1152 SigninManager::DisableOneClickSignIn(profile); |
| 1077 browser->window()->ShowOneClickSigninBubble( | 1153 browser->window()->ShowOneClickSigninBubble( |
| 1078 bubble_type, | 1154 bubble_type, |
| 1079 base::Bind(&StartSync, | 1155 base::Bind(&StartSync, |
| 1080 StartSyncArgs(profile, browser, auto_accept_, | 1156 StartSyncArgs(profile, browser, auto_accept_, |
| 1081 session_index_, email_, password_, | 1157 session_index_, email_, password_, |
| 1082 false /* force_same_tab_navigation */))); | 1158 false /* force_same_tab_navigation */, |
| 1159 source_))); | |
| 1083 break; | 1160 break; |
| 1084 case AUTO_ACCEPT_CONFIGURE: | 1161 case AUTO_ACCEPT_CONFIGURE: |
| 1162 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_ACCEPTED); | |
| 1163 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_WITH_ADVANCED); | |
| 1085 SigninManager::DisableOneClickSignIn(profile); | 1164 SigninManager::DisableOneClickSignIn(profile); |
| 1086 StartSync( | 1165 StartSync( |
| 1087 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1166 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, |
| 1088 password_, false /* force_same_tab_navigation */), | 1167 password_, false /* force_same_tab_navigation */, |
| 1168 source_), | |
| 1089 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1169 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 1090 break; | 1170 break; |
| 1091 case AUTO_ACCEPT_EXPLICIT: { | 1171 case AUTO_ACCEPT_EXPLICIT: { |
| 1172 if (switched_to_advanced_) { | |
| 1173 LogHistogramValue(advanced_source_, | |
| 1174 one_click_signin::HISTOGRAM_WITH_ADVANCED); | |
| 1175 LogHistogramValue(advanced_source_, | |
| 1176 one_click_signin::HISTOGRAM_ACCEPTED); | |
| 1177 } else { | |
| 1178 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); | |
| 1179 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); | |
| 1180 } | |
| 1092 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1181 OneClickSigninSyncStarter::StartSyncMode start_mode = |
| 1093 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 1182 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
| 1094 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1183 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
| 1095 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1184 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
| 1096 | 1185 |
| 1097 // If the new email address is different from the email address that | 1186 // If the new email address is different from the email address that |
| 1098 // just signed in, show a confirmation dialog. | 1187 // just signed in, show a confirmation dialog. |
| 1099 std::string last_email = | 1188 std::string last_email = |
| 1100 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1189 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 1101 if (!last_email.empty() && last_email != email_) { | 1190 if (!last_email.empty() && last_email != email_) { |
| 1102 ConfirmEmailDialogDelegate::AskForConfirmation( | 1191 ConfirmEmailDialogDelegate::AskForConfirmation( |
| 1103 contents, | 1192 contents, |
| 1104 last_email, | 1193 last_email, |
| 1105 email_, | 1194 email_, |
| 1106 base::Bind( | 1195 base::Bind( |
| 1107 &StartExplicitSync, | 1196 &StartExplicitSync, |
| 1108 StartSyncArgs(profile, browser, auto_accept_, | 1197 StartSyncArgs(profile, browser, auto_accept_, |
| 1109 session_index_, email_, password_, | 1198 session_index_, email_, password_, |
| 1110 force_same_tab_navigation), | 1199 force_same_tab_navigation, |
| 1200 source_), | |
| 1111 contents, | 1201 contents, |
| 1112 start_mode)); | 1202 start_mode)); |
| 1113 } else { | 1203 } else { |
| 1114 StartExplicitSync( | 1204 StartExplicitSync( |
| 1115 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1205 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
| 1116 email_, password_, force_same_tab_navigation), | 1206 email_, password_, force_same_tab_navigation, |
| 1207 source_), | |
| 1117 contents, | 1208 contents, |
| 1118 start_mode, | 1209 start_mode, |
| 1119 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | 1210 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); |
| 1120 } | 1211 } |
| 1121 | 1212 |
| 1122 if (source_ == SyncPromoUI::SOURCE_SETTINGS && | 1213 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
| 1123 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1214 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
| 1124 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1215 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
| 1125 redirect_url_ = continue_url_; | 1216 redirect_url_ = continue_url_; |
| 1126 ProfileSyncService* sync_service = | 1217 ProfileSyncService* sync_service = |
| 1127 ProfileSyncServiceFactory::GetForProfile(profile); | 1218 ProfileSyncServiceFactory::GetForProfile(profile); |
| 1128 if (sync_service) | 1219 if (sync_service) |
| 1129 sync_service->AddObserver(this); | 1220 sync_service->AddObserver(this); |
| 1130 } | 1221 } |
| 1131 | 1222 |
| 1132 // If this explicit sign in is not from settings page/webstore, show the | 1223 // If this explicit sign in is not from settings page/webstore, show the |
| 1133 // NTP after sign in completes. In the case of the settings page, it will | 1224 // NTP after sign in completes. In the case of the settings page, it will |
| 1134 // get closed by SyncSetupHandler. In the case of webstore, it will | 1225 // get closed by SyncSetupHandler. In the case of webstore, it will |
| 1135 // redirect back to webstore. | 1226 // redirect back to webstore. |
| 1136 if (source_ != SyncPromoUI::SOURCE_SETTINGS && | 1227 if (source_ != SyncPromoUI::SOURCE_SETTINGS && |
| 1137 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1228 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
| 1138 signin_tracker_.reset(new SigninTracker(profile, this)); | 1229 signin_tracker_.reset(new SigninTracker(profile, this)); |
| 1139 RedirectToNTP(true); | 1230 RedirectToNTP(true); |
| 1140 } | 1231 } |
| 1141 break; | 1232 break; |
| 1142 } | 1233 } |
| 1143 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: | 1234 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: |
| 1144 AddEmailToOneClickRejectedList(profile, email_); | 1235 AddEmailToOneClickRejectedList(profile, email_); |
| 1145 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 1236 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); |
| 1146 one_click_signin::HISTOGRAM_REJECTED, | |
| 1147 one_click_signin::HISTOGRAM_MAX); | |
| 1148 break; | 1237 break; |
| 1149 default: | 1238 default: |
| 1150 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 1239 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
| 1151 break; | 1240 break; |
| 1152 } | 1241 } |
| 1153 | 1242 |
| 1154 CleanTransientState(); | 1243 CleanTransientState(); |
| 1155 } | 1244 } |
| 1156 | 1245 |
| 1157 void OneClickSigninHelper::GaiaCredentialsValid() { | 1246 void OneClickSigninHelper::GaiaCredentialsValid() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 } | 1292 } |
| 1204 } | 1293 } |
| 1205 | 1294 |
| 1206 RedirectToNTP(true); | 1295 RedirectToNTP(true); |
| 1207 signin_tracker_.reset(); | 1296 signin_tracker_.reset(); |
| 1208 } | 1297 } |
| 1209 | 1298 |
| 1210 void OneClickSigninHelper::SigninSuccess() { | 1299 void OneClickSigninHelper::SigninSuccess() { |
| 1211 signin_tracker_.reset(); | 1300 signin_tracker_.reset(); |
| 1212 } | 1301 } |
| OLD | NEW |