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

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

Issue 872433006: Disconnect one click sign in code. The code itself will be removed in followup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix merge Created 5 years, 10 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
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 // Add a specific email to the list of emails rejected for one-click 222 // Add a specific email to the list of emails rejected for one-click
223 // sign-in, for this profile. 223 // sign-in, for this profile.
224 void AddEmailToOneClickRejectedList(Profile* profile, 224 void AddEmailToOneClickRejectedList(Profile* profile,
225 const std::string& email) { 225 const std::string& email) {
226 ListPrefUpdate updater(profile->GetPrefs(), 226 ListPrefUpdate updater(profile->GetPrefs(),
227 prefs::kReverseAutologinRejectedEmailList); 227 prefs::kReverseAutologinRejectedEmailList);
228 updater->AppendIfNotPresent(new base::StringValue(email)); 228 updater->AppendIfNotPresent(new base::StringValue(email));
229 } 229 }
230 230
231 void RedirectToNtpOrAppsPageWithIds(int child_id,
232 int route_id,
233 signin_metrics::Source source) {
234 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id,
235 route_id);
236 if (!web_contents)
237 return;
238
239 OneClickSigninHelper::RedirectToNtpOrAppsPage(web_contents, source);
240 }
241
242 // Start syncing with the given user information. 231 // Start syncing with the given user information.
243 void StartSync(const OneClickSigninHelper::StartSyncArgs& args, 232 void StartSync(const OneClickSigninHelper::StartSyncArgs& args,
244 OneClickSigninSyncStarter::StartSyncMode start_mode) { 233 OneClickSigninSyncStarter::StartSyncMode start_mode) {
245 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { 234 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) {
246 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_UNDO); 235 OneClickSigninHelper::LogHistogramValue(signin_metrics::HISTOGRAM_UNDO);
247 return; 236 return;
248 } 237 }
249 238
250 // The wrapper deletes itself once it's done. 239 // The wrapper deletes itself once it's done.
251 OneClickSigninHelper::SyncStarterWrapper* wrapper = 240 OneClickSigninHelper::SyncStarterWrapper* wrapper =
(...skipping 19 matching lines...) Expand all
271 break; 260 break;
272 } 261 }
273 if (action != signin_metrics::HISTOGRAM_MAX) 262 if (action != signin_metrics::HISTOGRAM_MAX)
274 OneClickSigninHelper::LogHistogramValue(action); 263 OneClickSigninHelper::LogHistogramValue(action);
275 } 264 }
276 265
277 void StartExplicitSync(const OneClickSigninHelper::StartSyncArgs& args, 266 void StartExplicitSync(const OneClickSigninHelper::StartSyncArgs& args,
278 content::WebContents* contents, 267 content::WebContents* contents,
279 OneClickSigninSyncStarter::StartSyncMode start_mode, 268 OneClickSigninSyncStarter::StartSyncMode start_mode,
280 ConfirmEmailDialogDelegate::Action action) { 269 ConfirmEmailDialogDelegate::Action action) {
281 bool enable_inline = !switches::IsEnableWebBasedSignin();
282 if (action == ConfirmEmailDialogDelegate::START_SYNC) { 270 if (action == ConfirmEmailDialogDelegate::START_SYNC) {
283 StartSync(args, start_mode); 271 StartSync(args, start_mode);
284 if (!enable_inline) {
285 // Redirect/tab closing for inline flow is handled by the sync callback.
286 OneClickSigninHelper::RedirectToNtpOrAppsPageIfNecessary(
287 contents, args.source);
288 }
289 } else { 272 } else {
290 // Perform a redirection to the NTP/Apps page to hide the blank page when 273 // Perform a redirection to the NTP/Apps page to hide the blank page when
291 // the action is CLOSE or CREATE_NEW_USER. The redirection is useful when 274 // the action is CLOSE or CREATE_NEW_USER. The redirection is useful when
292 // the action is CREATE_NEW_USER because the "Create new user" page might 275 // the action is CREATE_NEW_USER because the "Create new user" page might
293 // be opened in a different tab that is already showing settings. 276 // be opened in a different tab that is already showing settings.
294 if (enable_inline) { 277 args.callback.Run(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
295 // Redirect/tab closing for inline flow is handled by the sync callback.
296 args.callback.Run(OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
297 } else {
298 // Redirect, but don't do so immediately; otherwise there might be two
299 // nested navigations, which would cause a crash: http://crbug.com/293261
300 // Instead, post a task to the current thread.
301 base::MessageLoopProxy::current()->PostNonNestableTask(
302 FROM_HERE,
303 base::Bind(RedirectToNtpOrAppsPageWithIds,
304 contents->GetRenderProcessHost()->GetID(),
305 contents->GetRoutingID(),
306 args.source));
307 }
308 if (action == ConfirmEmailDialogDelegate::CREATE_NEW_USER) { 278 if (action == ConfirmEmailDialogDelegate::CREATE_NEW_USER) {
309 chrome::ShowSettingsSubPage(args.browser, 279 chrome::ShowSettingsSubPage(args.browser,
310 std::string(chrome::kCreateProfileSubPage)); 280 std::string(chrome::kCreateProfileSubPage));
311 } 281 }
312 } 282 }
313 } 283 }
314 284
315 void ClearPendingEmailOnIOThread(content::ResourceContext* context) { 285 void ClearPendingEmailOnIOThread(content::ResourceContext* context) {
316 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 286 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
317 DCHECK(io_data); 287 DCHECK(io_data);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 CurrentHistoryCleaner::~CurrentHistoryCleaner() { 418 CurrentHistoryCleaner::~CurrentHistoryCleaner() {
449 } 419 }
450 420
451 void CurrentHistoryCleaner::DidCommitProvisionalLoadForFrame( 421 void CurrentHistoryCleaner::DidCommitProvisionalLoadForFrame(
452 content::RenderFrameHost* render_frame_host, 422 content::RenderFrameHost* render_frame_host,
453 const GURL& url, 423 const GURL& url,
454 ui::PageTransition transition_type) { 424 ui::PageTransition transition_type) {
455 // Return early if this is not top-level navigation. 425 // Return early if this is not top-level navigation.
456 if (render_frame_host->GetParent()) 426 if (render_frame_host->GetParent())
457 return; 427 return;
458
459 content::NavigationController* nc = &web_contents()->GetController();
460 HistoryService* hs = HistoryServiceFactory::GetForProfile(
461 Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
462 ServiceAccessType::IMPLICIT_ACCESS);
463
464 // Have to wait until something else gets added to history before removal.
465 if (history_index_to_remove_ < nc->GetLastCommittedEntryIndex()) {
466 content::NavigationEntry* entry =
467 nc->GetEntryAtIndex(history_index_to_remove_);
468 if (signin::IsContinueUrlForWebBasedSigninFlow(entry->GetURL())) {
469 hs->DeleteURL(entry->GetURL());
470 nc->RemoveEntryAtIndex(history_index_to_remove_);
471 delete this; // Success.
472 }
473 }
474 } 428 }
475 429
476 void CurrentHistoryCleaner::WebContentsDestroyed() { 430 void CurrentHistoryCleaner::WebContentsDestroyed() {
477 delete this; // Failure. 431 delete this; // Failure.
478 } 432 }
479 433
480 } // namespace 434 } // namespace
481 435
482 436
483 // StartSyncArgs -------------------------------------------------------------- 437 // StartSyncArgs --------------------------------------------------------------
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 // complete. 996 // complete.
1043 if (helper->original_continue_url_.is_empty()) 997 if (helper->original_continue_url_.is_empty())
1044 helper->original_continue_url_ = continue_url; 998 helper->original_continue_url_ = continue_url;
1045 helper->continue_url_ = continue_url; 999 helper->continue_url_ = continue_url;
1046 } 1000 }
1047 } 1001 }
1048 1002
1049 // static 1003 // static
1050 void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem( 1004 void OneClickSigninHelper::RemoveSigninRedirectURLHistoryItem(
1051 content::WebContents* web_contents) { 1005 content::WebContents* web_contents) {
1052 // Only actually remove the item if it's the blank.html continue url.
1053 if (signin::IsContinueUrlForWebBasedSigninFlow(
1054 web_contents->GetLastCommittedURL())) {
1055 new CurrentHistoryCleaner(web_contents); // will self-destruct when done
1056 }
1057 } 1006 }
1058 1007
1059 // static 1008 // static
1060 bool OneClickSigninHelper::HandleCrossAccountError( 1009 bool OneClickSigninHelper::HandleCrossAccountError(
1061 Profile* profile, 1010 Profile* profile,
1062 const std::string& session_index, 1011 const std::string& session_index,
1063 const std::string& email, 1012 const std::string& email,
1064 const std::string& password, 1013 const std::string& password,
1065 const std::string& refresh_token, 1014 const std::string& refresh_token,
1066 OneClickSigninHelper::AutoAccept auto_accept, 1015 OneClickSigninHelper::AutoAccept auto_accept,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_DEFAULTS); 1334 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_DEFAULTS);
1386 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); 1335 SigninManager::DisableOneClickSignIn(profile->GetPrefs());
1387 // Start syncing with the default settings - prompt the user to sign in 1336 // Start syncing with the default settings - prompt the user to sign in
1388 // first. 1337 // first.
1389 if (!do_not_start_sync_for_testing_) { 1338 if (!do_not_start_sync_for_testing_) {
1390 StartSync( 1339 StartSync(
1391 StartSyncArgs(profile, browser, auto_accept_, 1340 StartSyncArgs(profile, browser, auto_accept_,
1392 session_index_, email_, password_, "", 1341 session_index_, email_, password_, "",
1393 NULL /* don't force sync setup in same tab */, 1342 NULL /* don't force sync setup in same tab */,
1394 true /* confirmation_required */, source_, 1343 true /* confirmation_required */, source_,
1395 CreateSyncStarterCallback()), 1344 OneClickSigninSyncStarter::Callback()),
1396 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); 1345 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
1397 } 1346 }
1398 break; 1347 break;
1399 case AUTO_ACCEPT_CONFIGURE: 1348 case AUTO_ACCEPT_CONFIGURE:
1400 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); 1349 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED);
1401 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_ADVANCED); 1350 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_ADVANCED);
1402 SigninManager::DisableOneClickSignIn(profile->GetPrefs()); 1351 SigninManager::DisableOneClickSignIn(profile->GetPrefs());
1403 // Display the extra confirmation (even in the SAML case) in case this 1352 // Display the extra confirmation (even in the SAML case) in case this
1404 // was an untrusted renderer. 1353 // was an untrusted renderer.
1405 if (!do_not_start_sync_for_testing_) { 1354 if (!do_not_start_sync_for_testing_) {
1406 StartSync( 1355 StartSync(
1407 StartSyncArgs(profile, browser, auto_accept_, 1356 StartSyncArgs(profile, browser, auto_accept_,
1408 session_index_, email_, password_, "", 1357 session_index_, email_, password_, "",
1409 NULL /* don't force sync setup in same tab */, 1358 NULL /* don't force sync setup in same tab */,
1410 true /* confirmation_required */, source_, 1359 true /* confirmation_required */, source_,
1411 CreateSyncStarterCallback()), 1360 OneClickSigninSyncStarter::Callback()),
1412 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); 1361 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST);
1413 } 1362 }
1414 break; 1363 break;
1415 case AUTO_ACCEPT_EXPLICIT: { 1364 case AUTO_ACCEPT_EXPLICIT: {
1416 signin_metrics::Source original_source = 1365 signin_metrics::Source original_source =
1417 signin::GetSourceForPromoURL(original_continue_url_); 1366 signin::GetSourceForPromoURL(original_continue_url_);
1418 if (switched_to_advanced_) { 1367 if (switched_to_advanced_) {
1419 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_ADVANCED); 1368 LogHistogramValue(signin_metrics::HISTOGRAM_WITH_ADVANCED);
1420 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED); 1369 LogHistogramValue(signin_metrics::HISTOGRAM_ACCEPTED);
1421 } else { 1370 } else {
(...skipping 15 matching lines...) Expand all
1437 OneClickSigninSyncStarter::StartSyncMode start_mode = 1386 OneClickSigninSyncStarter::StartSyncMode start_mode =
1438 source_ == signin_metrics::SOURCE_SETTINGS ? 1387 source_ == signin_metrics::SOURCE_SETTINGS ?
1439 (error_controller->HasError() && 1388 (error_controller->HasError() &&
1440 sync_service && sync_service->HasSyncSetupCompleted()) ? 1389 sync_service && sync_service->HasSyncSetupCompleted()) ?
1441 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : 1390 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE :
1442 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : 1391 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST :
1443 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; 1392 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS;
1444 1393
1445 if (!HandleCrossAccountError(profile, session_index_, email_, password_, 1394 if (!HandleCrossAccountError(profile, session_index_, email_, password_,
1446 "", auto_accept_, source_, start_mode, 1395 "", auto_accept_, source_, start_mode,
1447 CreateSyncStarterCallback())) { 1396 OneClickSigninSyncStarter::Callback())) {
1448 if (!do_not_start_sync_for_testing_) { 1397 if (!do_not_start_sync_for_testing_) {
1449 StartSync( 1398 StartSync(
1450 StartSyncArgs(profile, browser, auto_accept_, 1399 StartSyncArgs(profile, browser, auto_accept_,
1451 session_index_, email_, password_, "", 1400 session_index_, email_, password_, "",
1452 contents, 1401 contents,
1453 untrusted_confirmation_required_, source_, 1402 untrusted_confirmation_required_, source_,
1454 CreateSyncStarterCallback()), 1403 OneClickSigninSyncStarter::Callback()),
1455 start_mode); 1404 start_mode);
1456 } 1405 }
1457 1406
1458 // If this explicit sign in is not from settings page/webstore, show 1407 // If this explicit sign in is not from settings page/webstore, show
1459 // the NTP/Apps page after sign in completes. In the case of the 1408 // the NTP/Apps page after sign in completes. In the case of the
1460 // settings page, it will get auto-closed after sync setup. In the case 1409 // settings page, it will get auto-closed after sync setup. In the case
1461 // of webstore, it will redirect back to webstore. 1410 // of webstore, it will redirect back to webstore.
1462 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_); 1411 RedirectToNtpOrAppsPageIfNecessary(web_contents(), source_);
1463 } 1412 }
1464 1413
(...skipping 10 matching lines...) Expand all
1475 AddEmailToOneClickRejectedList(profile, email_); 1424 AddEmailToOneClickRejectedList(profile, email_);
1476 LogHistogramValue(signin_metrics::HISTOGRAM_REJECTED); 1425 LogHistogramValue(signin_metrics::HISTOGRAM_REJECTED);
1477 break; 1426 break;
1478 default: 1427 default:
1479 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; 1428 NOTREACHED() << "Invalid auto_accept=" << auto_accept_;
1480 break; 1429 break;
1481 } 1430 }
1482 1431
1483 CleanTransientState(); 1432 CleanTransientState();
1484 } 1433 }
1485
1486 OneClickSigninSyncStarter::Callback
1487 OneClickSigninHelper::CreateSyncStarterCallback() {
1488 // The callback will only be invoked if this object is still alive when sync
1489 // setup is completed. This is correct because this object is only deleted
1490 // when the web contents that potentially shows a blank page is deleted.
1491 return base::Bind(&OneClickSigninHelper::SyncSetupCompletedCallback,
1492 weak_pointer_factory_.GetWeakPtr());
1493 }
1494
1495 void OneClickSigninHelper::SyncSetupCompletedCallback(
1496 OneClickSigninSyncStarter::SyncSetupResult result) {
1497 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE &&
1498 web_contents()) {
1499 GURL current_url = web_contents()->GetVisibleURL();
1500
1501 // If the web contents is showing a blank page and not about to be closed,
1502 // redirect to the NTP or apps page.
1503 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) &&
1504 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) {
1505 RedirectToNtpOrAppsPage(
1506 web_contents(),
1507 signin::GetSourceForPromoURL(original_continue_url_));
1508 }
1509 }
1510 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | chrome/browser/ui/sync/one_click_signin_sync_starter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698