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

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

Issue 16172007: Show email confirmation for sign in from the hot-dog menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
« 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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_forward.h" 13 #include "base/callback.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/supports_user_data.h" 21 #include "base/supports_user_data.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/values.h" 23 #include "base/values.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 NOTREACHED() << "Invalid auto_accept: " << args.auto_accept; 238 NOTREACHED() << "Invalid auto_accept: " << args.auto_accept;
239 break; 239 break;
240 } 240 }
241 if (action != one_click_signin::HISTOGRAM_MAX) 241 if (action != one_click_signin::HISTOGRAM_MAX)
242 LogOneClickHistogramValue(action); 242 LogOneClickHistogramValue(action);
243 } 243 }
244 244
245 void StartExplicitSync(const StartSyncArgs& args, 245 void StartExplicitSync(const StartSyncArgs& args,
246 content::WebContents* contents, 246 content::WebContents* contents,
247 OneClickSigninSyncStarter::StartSyncMode start_mode, 247 OneClickSigninSyncStarter::StartSyncMode start_mode,
248 base::Closure start_sync_callback,
248 int button) { 249 int button) {
249 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) { 250 if (button == IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_OK_BUTTON) {
250 contents->GetController().LoadURL( 251 contents->GetController().LoadURL(
251 GURL(chrome::kChromeUINewTabURL), content::Referrer(), 252 GURL(chrome::kChromeUINewTabURL), content::Referrer(),
252 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); 253 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
253 chrome::ShowSettingsSubPage(args.browser, 254 chrome::ShowSettingsSubPage(args.browser,
254 std::string(chrome::kSearchUsersSubPage)); 255 std::string(chrome::kSearchUsersSubPage));
255 } else { 256 } else {
256 StartSync(args, start_mode); 257 StartSync(args, start_mode);
258 start_sync_callback.Run();
257 } 259 }
258 } 260 }
259 261
260 void ClearPendingEmailOnIOThread(content::ResourceContext* context) { 262 void ClearPendingEmailOnIOThread(content::ResourceContext* context) {
261 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 263 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
262 DCHECK(io_data); 264 DCHECK(io_data);
263 io_data->set_reverse_autologin_pending_email(std::string()); 265 io_data->set_reverse_autologin_pending_email(std::string());
264 } 266 }
265 267
266 // Determines the source of the sign in and the continue URL. Its either one 268 // Determines the source of the sign in and the continue URL. Its either one
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ? 911 GURL url(source_ == SyncPromoUI::SOURCE_APPS_PAGE_LINK ?
910 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); 912 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
911 content::OpenURLParams params(url, 913 content::OpenURLParams params(url,
912 content::Referrer(), 914 content::Referrer(),
913 CURRENT_TAB, 915 CURRENT_TAB,
914 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 916 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
915 false); 917 false);
916 contents->OpenURL(params); 918 contents->OpenURL(params);
917 } 919 }
918 920
921 void OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary() {
922 if (source_ != SyncPromoUI::SOURCE_SETTINGS &&
923 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL)
924 RedirectToNtpOrAppsPage();
Roger Tawa OOO till Jul 10th 2013/06/05 23:48:37 Add { and } for if statement.
fdoray 2013/06/10 15:44:13 Done.
925 }
926
919 void OneClickSigninHelper::RedirectToSignin() { 927 void OneClickSigninHelper::RedirectToSignin() {
920 VLOG(1) << "OneClickSigninHelper::RedirectToSignin"; 928 VLOG(1) << "OneClickSigninHelper::RedirectToSignin";
921 929
922 // Extract the existing sounce=X value. Default to "2" if missing. 930 // Extract the existing sounce=X value. Default to "2" if missing.
923 SyncPromoUI::Source source = 931 SyncPromoUI::Source source =
924 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_); 932 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_);
925 if (source == SyncPromoUI::SOURCE_UNKNOWN) 933 if (source == SyncPromoUI::SOURCE_UNKNOWN)
926 source = SyncPromoUI::SOURCE_MENU; 934 source = SyncPromoUI::SOURCE_MENU;
927 GURL page = SyncPromoUI::GetSyncPromoURL(GURL(), source, false); 935 GURL page = SyncPromoUI::GetSyncPromoURL(GURL(), source, false);
928 936
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 case AUTO_ACCEPT_EXPLICIT: { 1177 case AUTO_ACCEPT_EXPLICIT: {
1170 if (switched_to_advanced_) { 1178 if (switched_to_advanced_) {
1171 LogHistogramValue(original_source_, 1179 LogHistogramValue(original_source_,
1172 one_click_signin::HISTOGRAM_WITH_ADVANCED); 1180 one_click_signin::HISTOGRAM_WITH_ADVANCED);
1173 LogHistogramValue(original_source_, 1181 LogHistogramValue(original_source_,
1174 one_click_signin::HISTOGRAM_ACCEPTED); 1182 one_click_signin::HISTOGRAM_ACCEPTED);
1175 } else { 1183 } else {
1176 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED); 1184 LogHistogramValue(source_, one_click_signin::HISTOGRAM_ACCEPTED);
1177 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS); 1185 LogHistogramValue(source_, one_click_signin::HISTOGRAM_WITH_DEFAULTS);
1178 } 1186 }
1187
1188 // Remove the blank page from the history of the current tab. It's not
1189 // necessary to do this if the sign in is from the Settings page /
1190 // Webstore because the current tab will be closed after sign in
1191 // completes.
1192 if (source_ != SyncPromoUI::SOURCE_SETTINGS &&
1193 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL)
1194 RemoveCurrentHistoryItem(contents);
1195
1179 OneClickSigninSyncStarter::StartSyncMode start_mode = 1196 OneClickSigninSyncStarter::StartSyncMode start_mode =
1180 source_ == SyncPromoUI::SOURCE_SETTINGS ? 1197 source_ == SyncPromoUI::SOURCE_SETTINGS ?
1181 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : 1198 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST :
1182 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; 1199 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;
1183 1200
1184 std::string last_email = 1201 std::string last_email =
1185 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); 1202 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername);
1186 1203
1187 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) { 1204 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email_)) {
1188 // If the new email address is different from the email address that 1205 // If the new email address is different from the email address that
1189 // just signed in, show a confirmation dialog. 1206 // just signed in, show a confirmation dialog.
1190 1207
1191 // No need to display a second confirmation so pass false below. 1208 // No need to display a second confirmation so pass false below.
1192 // TODO(atwilson): Move this into OneClickSigninSyncStarter. 1209 // TODO(atwilson): Move this into OneClickSigninSyncStarter.
1193 ConfirmEmailDialogDelegate::AskForConfirmation( 1210 ConfirmEmailDialogDelegate::AskForConfirmation(
1194 contents, 1211 contents,
1195 last_email, 1212 last_email,
1196 email_, 1213 email_,
1197 base::Bind( 1214 base::Bind(
1198 &StartExplicitSync, 1215 &StartExplicitSync,
1199 StartSyncArgs(profile, browser, auto_accept_, 1216 StartSyncArgs(profile, browser, auto_accept_,
1200 session_index_, email_, password_, 1217 session_index_, email_, password_,
1201 force_same_tab_navigation, 1218 force_same_tab_navigation,
1202 false /* confirmation_required */, source_), 1219 false /* confirmation_required */, source_),
1203 contents, 1220 contents,
1204 start_mode)); 1221 start_mode,
1222 base::Bind(
1223 &OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary,
1224 base::Unretained(this))));
1205 } else { 1225 } else {
1206 StartSync( 1226 StartSync(
1207 StartSyncArgs(profile, browser, auto_accept_, session_index_, 1227 StartSyncArgs(profile, browser, auto_accept_, session_index_,
1208 email_, password_, force_same_tab_navigation, 1228 email_, password_, force_same_tab_navigation,
1209 untrusted_confirmation_required_, source_), 1229 untrusted_confirmation_required_, source_),
1210 start_mode); 1230 start_mode);
1231
1232 // If this explicit sign in is not from settings page/webstore, show
1233 // the NTP/Apps page after sign in completes. In the case of the
1234 // settings page, it will get closed by SyncSetupHandler. In the case
1235 // of webstore, it will redirect back to webstore.
1236 RedirectToNtpOrAppsPageIfNecessary();
1211 } 1237 }
1212 1238
1213 if (source_ == SyncPromoUI::SOURCE_SETTINGS && 1239 if (source_ == SyncPromoUI::SOURCE_SETTINGS &&
1214 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == 1240 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) ==
1215 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { 1241 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) {
1216 redirect_url_ = continue_url_; 1242 redirect_url_ = continue_url_;
1217 ProfileSyncService* sync_service = 1243 ProfileSyncService* sync_service =
1218 ProfileSyncServiceFactory::GetForProfile(profile); 1244 ProfileSyncServiceFactory::GetForProfile(profile);
1219 if (sync_service) 1245 if (sync_service)
1220 sync_service->AddObserver(this); 1246 sync_service->AddObserver(this);
1221 } 1247 }
1222
1223 // If this explicit sign in is not from settings page/webstore, show the
1224 // NTP/Apps page after sign in completes. In the case of the settings
1225 // page, it will get closed by SyncSetupHandler. In the case of webstore,
1226 // it will redirect back to webstore.
1227 if (source_ != SyncPromoUI::SOURCE_SETTINGS &&
1228 source_ != SyncPromoUI::SOURCE_WEBSTORE_INSTALL) {
1229 RemoveCurrentHistoryItem(contents);
1230 RedirectToNtpOrAppsPage();
1231 }
1232 break; 1248 break;
1233 } 1249 }
1234 case AUTO_ACCEPT_REJECTED_FOR_PROFILE: 1250 case AUTO_ACCEPT_REJECTED_FOR_PROFILE:
1235 AddEmailToOneClickRejectedList(profile, email_); 1251 AddEmailToOneClickRejectedList(profile, email_);
1236 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED); 1252 LogOneClickHistogramValue(one_click_signin::HISTOGRAM_REJECTED);
1237 break; 1253 break;
1238 default: 1254 default:
1239 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; 1255 NOTREACHED() << "Invalid auto_accept=" << auto_accept_;
1240 break; 1256 break;
1241 } 1257 }
(...skipping 21 matching lines...) Expand all
1263 contents->GetController().LoadURL(redirect_url_, 1279 contents->GetController().LoadURL(redirect_url_,
1264 content::Referrer(), 1280 content::Referrer(),
1265 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1281 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1266 std::string()); 1282 std::string());
1267 } 1283 }
1268 1284
1269 // Clear the redirect URL. 1285 // Clear the redirect URL.
1270 redirect_url_ = GURL(); 1286 redirect_url_ = GURL();
1271 sync_service->RemoveObserver(this); 1287 sync_service->RemoveObserver(this);
1272 } 1288 }
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