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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 content::WebContents* contents, | 320 content::WebContents* contents, |
321 const std::string& last_email, | 321 const std::string& last_email, |
322 const std::string& email, | 322 const std::string& email, |
323 Callback callback) | 323 Callback callback) |
324 : TabModalConfirmDialogDelegate(contents), | 324 : TabModalConfirmDialogDelegate(contents), |
325 last_email_(last_email), | 325 last_email_(last_email), |
326 email_(email), | 326 email_(email), |
327 callback_(callback) { | 327 callback_(callback) { |
328 } | 328 } |
329 | 329 |
330 // Tells when we are in the process of showing either the signin to chrome page | |
331 // or the one click sign in to chrome page. | |
332 bool AreWeShowingSignin(GURL url, SyncPromoUI::Source source, | |
333 std::string email) { | |
334 GURL::Replacements replacements; | |
335 replacements.ClearQuery(); | |
336 GURL clean_login_url = | |
337 GURL(GaiaUrls::GetInstance()->service_login_url()).ReplaceComponents( | |
338 replacements); | |
339 | |
340 return (url.ReplaceComponents(replacements) == clean_login_url && | |
341 source != SyncPromoUI::SOURCE_UNKNOWN) || !email.empty(); | |
342 } | |
343 | |
344 void LogHistogramValue(SyncPromoUI::Source source, int action) { | |
345 std::string histogram_prefix; | |
Roger Tawa OOO till Jul 10th
2013/02/28 16:32:26
var not needed.
jwd
2013/02/28 19:16:05
Done.
| |
346 switch (source) { | |
347 case SyncPromoUI::SOURCE_START_PAGE: | |
348 UMA_HISTOGRAM_ENUMERATION("Signin.StartPageActions", action, | |
349 one_click_signin::HISTOGRAM_MAX); | |
350 break; | |
351 case SyncPromoUI::SOURCE_NTP_LINK: | |
352 UMA_HISTOGRAM_ENUMERATION("Signin.NTPLinkActions", action, | |
353 one_click_signin::HISTOGRAM_MAX); | |
354 break; | |
355 case SyncPromoUI::SOURCE_MENU: | |
356 UMA_HISTOGRAM_ENUMERATION("Signin.MenuActions", action, | |
357 one_click_signin::HISTOGRAM_MAX); | |
358 break; | |
359 case SyncPromoUI::SOURCE_SETTINGS: | |
360 UMA_HISTOGRAM_ENUMERATION("Signin.SettingsActions", action, | |
361 one_click_signin::HISTOGRAM_MAX); | |
362 break; | |
363 case SyncPromoUI::SOURCE_EXTENSION_INSTALL_BUBBLE: | |
364 UMA_HISTOGRAM_ENUMERATION("Signin.ExtensionInstallBubbleActions", action, | |
365 one_click_signin::HISTOGRAM_MAX); | |
366 break; | |
367 case SyncPromoUI::SOURCE_WEBSTORE_INSTALL: | |
368 UMA_HISTOGRAM_ENUMERATION("Signin.WebstoreInstallActions", action, | |
369 one_click_signin::HISTOGRAM_MAX); | |
370 break; | |
371 case SyncPromoUI::SOURCE_APP_LAUNCHER: | |
372 UMA_HISTOGRAM_ENUMERATION("Signin.AppLauncherActions", action, | |
373 one_click_signin::HISTOGRAM_MAX); | |
374 break; | |
375 case SyncPromoUI::SOURCE_UNKNOWN: | |
376 UMA_HISTOGRAM_ENUMERATION("Signin.OneClickActions", action, | |
377 one_click_signin::HISTOGRAM_MAX); | |
378 break; | |
379 default: | |
380 NOTREACHED() << "Invalid Source"; | |
381 return; | |
382 } | |
383 UMA_HISTOGRAM_ENUMERATION("Signin.AllAccessPointActions", action, | |
384 one_click_signin::HISTOGRAM_MAX); | |
385 } | |
386 | |
330 } // namespace | 387 } // namespace |
331 | 388 |
332 // The infobar asking the user if they want to use one-click sign in. | 389 // 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 | 390 // TODO(rogerta): once we move to a web-based sign in flow, we can get rid |
334 // of this infobar. | 391 // of this infobar. |
335 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { | 392 class OneClickInfoBarDelegateImpl : public OneClickSigninInfoBarDelegate { |
336 public: | 393 public: |
337 // Creates a one click signin delegate and adds it to |infobar_service|. | 394 // Creates a one click signin delegate and adds it to |infobar_service|. |
338 static void Create(InfoBarService* infobar_service, | 395 static void Create(InfoBarService* infobar_service, |
339 const std::string& session_index, | 396 const std::string& session_index, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); | 552 return OneClickSigninInfoBarDelegate::GetAlternateColors(alt_colors); |
496 } | 553 } |
497 | 554 |
498 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { | 555 void OneClickInfoBarDelegateImpl::RecordHistogramAction(int action) { |
499 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 556 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
500 one_click_signin::HISTOGRAM_MAX); | 557 one_click_signin::HISTOGRAM_MAX); |
501 } | 558 } |
502 | 559 |
503 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) | 560 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) |
504 : content::WebContentsObserver(web_contents), | 561 : content::WebContentsObserver(web_contents), |
562 showing_signin_(false), | |
505 auto_accept_(AUTO_ACCEPT_NONE), | 563 auto_accept_(AUTO_ACCEPT_NONE), |
506 source_(SyncPromoUI::SOURCE_UNKNOWN) { | 564 source_(SyncPromoUI::SOURCE_UNKNOWN) { |
507 } | 565 } |
508 | 566 |
509 OneClickSigninHelper::~OneClickSigninHelper() { | 567 OneClickSigninHelper::~OneClickSigninHelper() { |
510 content::WebContents* contents = web_contents(); | 568 content::WebContents* contents = web_contents(); |
511 if (contents) { | 569 if (contents) { |
512 Profile* profile = | 570 Profile* profile = |
513 Profile::FromBrowserContext(contents->GetBrowserContext()); | 571 Profile::FromBrowserContext(contents->GetBrowserContext()); |
514 ProfileSyncService* sync_service = | 572 ProfileSyncService* sync_service = |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, | 891 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, |
834 route_id); | 892 route_id); |
835 | 893 |
836 // TODO(mathp): The appearance of this infobar should be tested using a | 894 // TODO(mathp): The appearance of this infobar should be tested using a |
837 // browser_test. | 895 // browser_test. |
838 OneClickSigninHelper* helper = | 896 OneClickSigninHelper* helper = |
839 OneClickSigninHelper::FromWebContents(web_contents); | 897 OneClickSigninHelper::FromWebContents(web_contents); |
840 if (!helper) | 898 if (!helper) |
841 return; | 899 return; |
842 | 900 |
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) { | 901 if (auto_accept != AUTO_ACCEPT_NONE) { |
853 helper->auto_accept_ = auto_accept; | 902 helper->auto_accept_ = auto_accept; |
854 helper->source_ = source; | 903 helper->source_ = source; |
855 } | 904 } |
856 | 905 |
857 CanOfferFor can_offer_for = | 906 CanOfferFor can_offer_for = |
858 (auto_accept != AUTO_ACCEPT_EXPLICIT && | 907 (auto_accept != AUTO_ACCEPT_EXPLICIT && |
859 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? | 908 helper->auto_accept_ != AUTO_ACCEPT_EXPLICIT) ? |
860 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; | 909 CAN_OFFER_FOR_INTERSTITAL_ONLY : CAN_OFFER_FOR_ALL; |
861 std::string error_message; | 910 std::string error_message; |
862 | 911 |
863 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, | 912 if (!web_contents || !CanOffer(web_contents, can_offer_for, email, |
864 &error_message)) { | 913 &error_message)) { |
865 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; | 914 VLOG(1) << "OneClickSigninHelper::ShowInfoBarUIThread: not offering"; |
866 if (helper && helper->error_message_.empty() && !error_message.empty()) | 915 if (helper && helper->error_message_.empty() && !error_message.empty()) |
867 helper->error_message_ = error_message; | 916 helper->error_message_ = error_message; |
868 | 917 |
869 return; | 918 return; |
870 } | 919 } |
871 | 920 |
921 // Save the email in the one-click signin manager. The manager may | |
922 // not exist if the contents is incognito or if the profile is already | |
923 // connected to a Google account. | |
924 if (!session_index.empty()) | |
925 helper->session_index_ = session_index; | |
926 | |
927 if (!email.empty()) | |
928 helper->email_ = email; | |
929 | |
872 if (continue_url.is_valid()) | 930 if (continue_url.is_valid()) |
873 helper->continue_url_ = continue_url; | 931 helper->continue_url_ = continue_url; |
874 } | 932 } |
875 | 933 |
876 void OneClickSigninHelper::RedirectToNTP(bool show_bubble) { | 934 void OneClickSigninHelper::RedirectToNTP(bool show_bubble) { |
877 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; | 935 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; |
878 | 936 |
879 // Redirect to NTP with sign in bubble visible. | 937 // Redirect to NTP with sign in bubble visible. |
880 content::WebContents* contents = web_contents(); | 938 content::WebContents* contents = web_contents(); |
881 Profile* profile = | 939 Profile* profile = |
(...skipping 27 matching lines...) Expand all Loading... | |
909 | 967 |
910 content::WebContents* contents = web_contents(); | 968 content::WebContents* contents = web_contents(); |
911 contents->GetController().LoadURL(page, | 969 contents->GetController().LoadURL(page, |
912 content::Referrer(), | 970 content::Referrer(), |
913 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 971 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
914 std::string()); | 972 std::string()); |
915 } | 973 } |
916 | 974 |
917 void OneClickSigninHelper::CleanTransientState() { | 975 void OneClickSigninHelper::CleanTransientState() { |
918 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; | 976 VLOG(1) << "OneClickSigninHelper::CleanTransientState"; |
977 showing_signin_ = false; | |
919 email_.clear(); | 978 email_.clear(); |
920 password_.clear(); | 979 password_.clear(); |
921 auto_accept_ = AUTO_ACCEPT_NONE; | 980 auto_accept_ = AUTO_ACCEPT_NONE; |
922 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 981 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
923 continue_url_ = GURL(); | 982 continue_url_ = GURL(); |
924 | 983 |
925 // Post to IO thread to clear pending email. | 984 // Post to IO thread to clear pending email. |
926 Profile* profile = | 985 Profile* profile = |
927 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 986 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
928 content::BrowserThread::PostTask( | 987 content::BrowserThread::PostTask( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 | 1025 |
967 // If an error has already occured during the sign in flow, make sure to | 1026 // 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 | 1027 // display it to the user and abort the process. Do this only for |
969 // explicit sign ins. | 1028 // explicit sign ins. |
970 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 1029 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
971 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 1030 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
972 RedirectToNTP(true); | 1031 RedirectToNTP(true); |
973 return; | 1032 return; |
974 } | 1033 } |
975 | 1034 |
1035 if (AreWeShowingSignin(url, source_, email_)) { | |
1036 if (!showing_signin_) | |
1037 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); | |
1038 showing_signin_ = true; | |
1039 } | |
1040 | |
976 // When Gaia finally redirects to the continue URL, Gaia will add some | 1041 // When Gaia finally redirects to the continue URL, Gaia will add some |
977 // extra query parameters. So ignore the parameters when checking to see | 1042 // extra query parameters. So ignore the parameters when checking to see |
978 // if the user has continued. | 1043 // if the user has continued. |
979 GURL::Replacements replacements; | 1044 GURL::Replacements replacements; |
980 replacements.ClearQuery(); | 1045 replacements.ClearQuery(); |
981 const bool continue_url_match_accept = ( | 1046 const bool continue_url_match_accept = ( |
982 auto_accept_ == AUTO_ACCEPT_EXPLICIT && | 1047 auto_accept_ == AUTO_ACCEPT_EXPLICIT && |
983 continue_url_.is_valid() && | 1048 continue_url_.is_valid() && |
984 url.ReplaceComponents(replacements) == | 1049 url.ReplaceComponents(replacements) == |
985 continue_url_.ReplaceComponents(replacements)); | 1050 continue_url_.ReplaceComponents(replacements)); |
986 | 1051 |
987 // If there is no valid email or password yet, there is nothing to do. | 1052 // If there is no valid email or password yet, there is nothing to do. |
988 if (email_.empty() || password_.empty()) { | 1053 if (email_.empty() || password_.empty()) { |
1054 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; | |
989 if (continue_url_match_accept) | 1055 if (continue_url_match_accept) |
990 RedirectToSignin(); | 1056 RedirectToSignin(); |
991 std::string unused_value; | 1057 std::string unused_value; |
992 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) | 1058 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) |
993 RedirectToNTP(false); | 1059 RedirectToNTP(false); |
994 return; | 1060 return; |
995 } | 1061 } |
996 | 1062 |
997 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have | 1063 // 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 | 1064 // the option of checking the the box "Let me choose what to sync". When the |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1203 } | 1269 } |
1204 } | 1270 } |
1205 | 1271 |
1206 RedirectToNTP(true); | 1272 RedirectToNTP(true); |
1207 signin_tracker_.reset(); | 1273 signin_tracker_.reset(); |
1208 } | 1274 } |
1209 | 1275 |
1210 void OneClickSigninHelper::SigninSuccess() { | 1276 void OneClickSigninHelper::SigninSuccess() { |
1211 signin_tracker_.reset(); | 1277 signin_tracker_.reset(); |
1212 } | 1278 } |
OLD | NEW |