Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 12477009: With browser instant extended enabled, signing in should redirect to chrome://apps instead of to NT… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments (Reverted to patchset 1) Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/defaults.h" 25 #include "chrome/browser/defaults.h"
26 #include "chrome/browser/google/google_util.h" 26 #include "chrome/browser/google/google_util.h"
27 #include "chrome/browser/infobars/infobar_service.h" 27 #include "chrome/browser/infobars/infobar_service.h"
28 #include "chrome/browser/prefs/scoped_user_pref_update.h" 28 #include "chrome/browser/prefs/scoped_user_pref_update.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/profiles/profile_info_cache.h" 30 #include "chrome/browser/profiles/profile_info_cache.h"
31 #include "chrome/browser/profiles/profile_io_data.h" 31 #include "chrome/browser/profiles/profile_io_data.h"
32 #include "chrome/browser/profiles/profile_manager.h" 32 #include "chrome/browser/profiles/profile_manager.h"
33 #include "chrome/browser/search/search.h"
33 #include "chrome/browser/signin/signin_manager.h" 34 #include "chrome/browser/signin/signin_manager.h"
34 #include "chrome/browser/signin/signin_manager_factory.h" 35 #include "chrome/browser/signin/signin_manager_factory.h"
35 #include "chrome/browser/signin/signin_names_io_thread.h" 36 #include "chrome/browser/signin/signin_names_io_thread.h"
36 #include "chrome/browser/sync/profile_sync_service.h" 37 #include "chrome/browser/sync/profile_sync_service.h"
37 #include "chrome/browser/sync/profile_sync_service_factory.h" 38 #include "chrome/browser/sync/profile_sync_service_factory.h"
38 #include "chrome/browser/sync/sync_prefs.h" 39 #include "chrome/browser/sync/sync_prefs.h"
39 #include "chrome/browser/tab_contents/tab_util.h" 40 #include "chrome/browser/tab_contents/tab_util.h"
40 #include "chrome/browser/ui/browser_finder.h" 41 #include "chrome/browser/ui/browser_finder.h"
41 #include "chrome/browser/ui/browser_window.h" 42 #include "chrome/browser/ui/browser_window.h"
42 #include "chrome/browser/ui/chrome_pages.h" 43 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 217 }
217 } 218 }
218 219
219 void ClearPendingEmailOnIOThread(content::ResourceContext* context) { 220 void ClearPendingEmailOnIOThread(content::ResourceContext* context) {
220 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 221 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
221 DCHECK(io_data); 222 DCHECK(io_data);
222 io_data->set_reverse_autologin_pending_email(std::string()); 223 io_data->set_reverse_autologin_pending_email(std::string());
223 } 224 }
224 225
225 // Determines the source of the sign in and the continue URL. Its either one 226 // Determines the source of the sign in and the continue URL. Its either one
226 // of the known sign in access point (first run, NTP, menu, settings) or its 227 // of the known sign in access point (first run, NTP, Apps page, menu, settings)
227 // an implicit sign in via another Google property. In the former case, 228 // or its an implicit sign in via another Google property. In the former case,
228 // "service" is also checked to make sure its "chromiumsync". 229 // "service" is also checked to make sure its "chromiumsync".
229 SyncPromoUI::Source GetSigninSource(const GURL& url, GURL* continue_url) { 230 SyncPromoUI::Source GetSigninSource(const GURL& url, GURL* continue_url) {
230 std::string value; 231 std::string value;
231 net::GetValueForKeyInQuery(url, "service", &value); 232 net::GetValueForKeyInQuery(url, "service", &value);
232 bool possibly_an_explicit_signin = value == "chromiumsync"; 233 bool possibly_an_explicit_signin = value == "chromiumsync";
233 234
234 // Find the final continue URL for this sign in. In some cases, Gaia can 235 // Find the final continue URL for this sign in. In some cases, Gaia can
235 // continue to itself, with the original continue URL buried under a couple 236 // continue to itself, with the original continue URL buried under a couple
236 // of layers of indirection. Peel those layers away. The final destination 237 // of layers of indirection. Peel those layers away. The final destination
237 // can also be "IsGaiaSignonRealm" so stop if we get to the end (but be sure 238 // can also be "IsGaiaSignonRealm" so stop if we get to the end (but be sure
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 const std::string& token = tokens[i]; 859 const std::string& token = tokens[i];
859 if (token == "accepted") { 860 if (token == "accepted") {
860 auto_accept = AUTO_ACCEPT_ACCEPTED; 861 auto_accept = AUTO_ACCEPT_ACCEPTED;
861 } else if (token == "configure") { 862 } else if (token == "configure") {
862 auto_accept = AUTO_ACCEPT_CONFIGURE; 863 auto_accept = AUTO_ACCEPT_CONFIGURE;
863 } else if (token == "rejected-for-profile") { 864 } else if (token == "rejected-for-profile") {
864 auto_accept = AUTO_ACCEPT_REJECTED_FOR_PROFILE; 865 auto_accept = AUTO_ACCEPT_REJECTED_FOR_PROFILE;
865 } 866 }
866 } 867 }
867 868
868 // If this is an explicit sign in (i.e., first run, NTP, menu,settings) 869 // If this is an explicit sign in (i.e., first run, NTP, Apps page, menu,
869 // then force the auto accept type to explicit. 870 // settings) then force the auto accept type to explicit.
870 source = GetSigninSource(request->url(), &continue_url); 871 source = GetSigninSource(request->url(), &continue_url);
871 if (source != SyncPromoUI::SOURCE_UNKNOWN) 872 if (source != SyncPromoUI::SOURCE_UNKNOWN)
872 auto_accept = AUTO_ACCEPT_EXPLICIT; 873 auto_accept = AUTO_ACCEPT_EXPLICIT;
873 } 874 }
874 875
875 if (auto_accept != AUTO_ACCEPT_NONE) { 876 if (auto_accept != AUTO_ACCEPT_NONE) {
876 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" 877 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:"
877 << " auto_accept=" << auto_accept; 878 << " auto_accept=" << auto_accept;
878 } 879 }
879 880
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 if (!session_index.empty()) 949 if (!session_index.empty())
949 helper->session_index_ = session_index; 950 helper->session_index_ = session_index;
950 951
951 if (!email.empty()) 952 if (!email.empty())
952 helper->email_ = email; 953 helper->email_ = email;
953 954
954 if (continue_url.is_valid()) 955 if (continue_url.is_valid())
955 helper->continue_url_ = continue_url; 956 helper->continue_url_ = continue_url;
956 } 957 }
957 958
958 void OneClickSigninHelper::RedirectToNTP(bool show_bubble) { 959 void OneClickSigninHelper::RedirectToNtpOrAppsPage(bool show_bubble) {
959 VLOG(1) << "OneClickSigninHelper::RedirectToNTP"; 960 VLOG(1) << "OneClickSigninHelper::RedirectToNtpOrAppsPage";
960 961
961 // Redirect to NTP with sign in bubble visible. 962 // Redirect to NTP/Apps page with sign in bubble visible.
962 content::WebContents* contents = web_contents(); 963 content::WebContents* contents = web_contents();
963 Profile* profile = 964 Profile* profile =
964 Profile::FromBrowserContext(contents->GetBrowserContext()); 965 Profile::FromBrowserContext(contents->GetBrowserContext());
965 PrefService* pref_service = profile->GetPrefs(); 966 PrefService* pref_service = profile->GetPrefs();
966 if (show_bubble) { 967 if (show_bubble) {
967 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); 968 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true);
968 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_); 969 pref_service->SetString(prefs::kSyncPromoErrorMessage, error_message_);
969 } 970 }
970 971
971 content::OpenURLParams params( 972 GURL url(chrome::search::IsInstantExtendedAPIEnabled() ?
972 GURL(chrome::kChromeUINewTabURL), 973 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
973 content::Referrer(), 974 content::OpenURLParams params(url,
974 CURRENT_TAB, 975 content::Referrer(),
975 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 976 CURRENT_TAB,
976 false); 977 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
978 false);
977 contents->OpenURL(params); 979 contents->OpenURL(params);
978 980
979 error_message_.clear(); 981 error_message_.clear();
980 } 982 }
981 983
982 void OneClickSigninHelper::RedirectToSignin() { 984 void OneClickSigninHelper::RedirectToSignin() {
983 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; 985 VLOG(1) << "OneClickSigninHelper::RedirectToSignin";
984 986
985 // Extract the existing sounce=X value. Default to "2" if missing. 987 // Extract the existing sounce=X value. Default to "2" if missing.
986 SyncPromoUI::Source source = 988 SyncPromoUI::Source source =
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 const GURL url = contents->GetURL(); 1051 const GURL url = contents->GetURL();
1050 Profile* profile = 1052 Profile* profile =
1051 Profile::FromBrowserContext(contents->GetBrowserContext()); 1053 Profile::FromBrowserContext(contents->GetBrowserContext());
1052 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec(); 1054 VLOG(1) << "OneClickSigninHelper::DidStopLoading: url=" << url.spec();
1053 1055
1054 // If an error has already occured during the sign in flow, make sure to 1056 // If an error has already occured during the sign in flow, make sure to
1055 // display it to the user and abort the process. Do this only for 1057 // display it to the user and abort the process. Do this only for
1056 // explicit sign ins. 1058 // explicit sign ins.
1057 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { 1059 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) {
1058 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; 1060 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_;
1059 RedirectToNTP(true); 1061 RedirectToNtpOrAppsPage(true);
1060 return; 1062 return;
1061 } 1063 }
1062 1064
1063 if (AreWeShowingSignin(url, source_, email_)) { 1065 if (AreWeShowingSignin(url, source_, email_)) {
1064 if (!showing_signin_) { 1066 if (!showing_signin_) {
1065 if (source_ == SyncPromoUI::SOURCE_UNKNOWN) 1067 if (source_ == SyncPromoUI::SOURCE_UNKNOWN)
1066 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN); 1068 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_SHOWN);
1067 else 1069 else
1068 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN); 1070 LogHistogramValue(source_, one_click_signin::HISTOGRAM_SHOWN);
1069 } 1071 }
(...skipping 11 matching lines...) Expand all
1081 continue_url_.ReplaceComponents(replacements)); 1083 continue_url_.ReplaceComponents(replacements));
1082 1084
1083 // If there is no valid email or password yet, there is nothing to do. 1085 // If there is no valid email or password yet, there is nothing to do.
1084 if (email_.empty() || password_.empty()) { 1086 if (email_.empty() || password_.empty()) {
1085 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do"; 1087 VLOG(1) << "OneClickSigninHelper::DidStopLoading: nothing to do";
1086 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT) 1088 if (continue_url_match && auto_accept_ == AUTO_ACCEPT_EXPLICIT)
1087 RedirectToSignin(); 1089 RedirectToSignin();
1088 std::string unused_value; 1090 std::string unused_value;
1089 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) { 1091 if (net::GetValueForKeyInQuery(url, "ntp", &unused_value)) {
1090 SyncPromoUI::SetUserSkippedSyncPromo(profile); 1092 SyncPromoUI::SetUserSkippedSyncPromo(profile);
1091 RedirectToNTP(false); 1093 RedirectToNtpOrAppsPage(false);
1092 } 1094 }
1093 return; 1095 return;
1094 } 1096 }
1095 1097
1096 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have 1098 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have
1097 // the option of checking the the box "Let me choose what to sync". When the 1099 // the option of checking the the box "Let me choose what to sync". When the
1098 // sign in process started, the source parameter in the continue URL may have 1100 // sign in process started, the source parameter in the continue URL may have
1099 // indicated one of the three options above. However, once this box is 1101 // indicated one of the three options above. However, once this box is
1100 // checked, the source parameter will indicate settings. This will only be 1102 // checked, the source parameter will indicate settings. This will only be
1101 // communicated back to chrome when Gaia redirects to the continue URL, and 1103 // communicated back to chrome when Gaia redirects to the continue URL, and
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == 1235 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) ==
1234 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { 1236 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) {
1235 redirect_url_ = continue_url_; 1237 redirect_url_ = continue_url_;
1236 ProfileSyncService* sync_service = 1238 ProfileSyncService* sync_service =
1237 ProfileSyncServiceFactory::GetForProfile(profile); 1239 ProfileSyncServiceFactory::GetForProfile(profile);
1238 if (sync_service) 1240 if (sync_service)
1239 sync_service->AddObserver(this); 1241 sync_service->AddObserver(this);
1240 } 1242 }
1241 1243
1242 // If this explicit sign in is not from settings page/webstore, show the 1244 // If this explicit sign in is not from settings page/webstore, show the
1243 // NTP after sign in completes. In the case of the settings page, it will 1245 // NTP/Apps page after sign in completes. In the case of the settings
1244 // get closed by SyncSetupHandler. In the case of webstore, it will 1246 // page, it will get closed by SyncSetupHandler. In the case of webstore,
1245 // redirect back to webstore. 1247 // it will redirect back to webstore.
1246 if (source_ != SyncPromoUI::SOURCE_SETTINGS && 1248 if (source_ != SyncPromoUI::SOURCE_SETTINGS &&
1247 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { 1249 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) {
1248 signin_tracker_.reset(new SigninTracker(profile, this)); 1250 signin_tracker_.reset(new SigninTracker(profile, this));
1249 // Show the NTP, but don't show the signed-in bubble yet. 1251 RedirectToNtpOrAppsPage(false);
1250 RedirectToNTP(false);
1251 } 1252 }
1252 break; 1253 break;
1253 } 1254 }
1254 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: 1255 case AUTO_ACCEPT_REJECTED_FOR_PROFILE:
1255 AddEmailToOneClickRejectedList(profile, email_); 1256 AddEmailToOneClickRejectedList(profile, email_);
1256 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); 1257 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED);
1257 break; 1258 break;
1258 default: 1259 default:
1259 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; 1260 NOTREACHED() << "Invalid auto_accept=" << auto_accept_;
1260 break; 1261 break;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 error_message_.clear(); 1305 error_message_.clear();
1305 break; 1306 break;
1306 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: 1307 case GoogleServiceAuthError::SERVICE_UNAVAILABLE:
1307 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_UNRECOVERABLE_ERROR); 1308 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_UNRECOVERABLE_ERROR);
1308 break; 1309 break;
1309 default: 1310 default:
1310 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_ERROR_SIGNING_IN); 1311 error_message_ = l10n_util::GetStringUTF8(IDS_SYNC_ERROR_SIGNING_IN);
1311 break; 1312 break;
1312 } 1313 }
1313 } 1314 }
1314 1315 RedirectOnSigninComplete();
1315 RedirectToNTP(true);
1316 signin_tracker_.reset();
1317 } 1316 }
1318 1317
1319 void OneClickSigninHelper::SigninSuccess() { 1318 void OneClickSigninHelper::SigninSuccess() {
1320 // Signed in now, so show the signed-in bubble. 1319 RedirectOnSigninComplete();
1321 RedirectToNTP(true); 1320 }
1321
1322 void OneClickSigninHelper::RedirectOnSigninComplete() {
1323 // Show the result in the sign-in bubble.
1324 RedirectToNtpOrAppsPage(true);
1322 signin_tracker_.reset(); 1325 signin_tracker_.reset();
1323 } 1326 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698