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

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_handler_impl.cc

Issue 1160073004: chrome/browser/ui: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/webui/signin/inline_login_handler_impl.h" 5 #include "chrome/browser/ui/webui/signin/inline_login_handler_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/location.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/single_thread_task_runner.h"
13 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 19 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_window.h" 22 #include "chrome/browser/profiles/profile_window.h"
20 #include "chrome/browser/signin/about_signin_internals_factory.h" 23 #include "chrome/browser/signin/about_signin_internals_factory.h"
21 #include "chrome/browser/signin/account_tracker_service_factory.h" 24 #include "chrome/browser/signin/account_tracker_service_factory.h"
22 #include "chrome/browser/signin/chrome_signin_client_factory.h" 25 #include "chrome/browser/signin/chrome_signin_client_factory.h"
23 #include "chrome/browser/signin/local_auth.h" 26 #include "chrome/browser/signin/local_auth.h"
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
25 #include "chrome/browser/signin/signin_error_controller_factory.h" 28 #include "chrome/browser/signin/signin_error_controller_factory.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 327 }
325 328
326 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT || 329 if (source == signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT ||
327 source == signin_metrics::SOURCE_REAUTH) { 330 source == signin_metrics::SOURCE_REAUTH) {
328 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> 331 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
329 UpdateCredentials(account_id, result.refresh_token); 332 UpdateCredentials(account_id, result.refresh_token);
330 333
331 if (signin::IsAutoCloseEnabledInURL(current_url_)) { 334 if (signin::IsAutoCloseEnabledInURL(current_url_)) {
332 // Close the gaia sign in tab via a task to make sure we aren't in the 335 // Close the gaia sign in tab via a task to make sure we aren't in the
333 // middle of any webui handler code. 336 // middle of any webui handler code.
334 base::MessageLoop::current()->PostTask( 337 base::ThreadTaskRunnerHandle::Get()->PostTask(
335 FROM_HERE, 338 FROM_HERE,
336 base::Bind(&InlineLoginHandlerImpl::CloseTab, 339 base::Bind(&InlineLoginHandlerImpl::CloseTab, handler_,
337 handler_, 340 signin::ShouldShowAccountManagement(current_url_)));
338 signin::ShouldShowAccountManagement(current_url_)));
339 } 341 }
340 342
341 if (source == signin_metrics::SOURCE_REAUTH) 343 if (source == signin_metrics::SOURCE_REAUTH)
342 signin_manager->MergeSigninCredentialIntoCookieJar(); 344 signin_manager->MergeSigninCredentialIntoCookieJar();
343 } else { 345 } else {
344 ProfileSyncService* sync_service = 346 ProfileSyncService* sync_service =
345 ProfileSyncServiceFactory::GetForProfile(profile_); 347 ProfileSyncServiceFactory::GetForProfile(profile_);
346 SigninErrorController* error_controller = 348 SigninErrorController* error_controller =
347 SigninErrorControllerFactory::GetForProfile(profile_); 349 SigninErrorControllerFactory::GetForProfile(profile_);
348 350
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Call OneClickSigninSyncStarter to exchange oauth code for tokens. 385 // Call OneClickSigninSyncStarter to exchange oauth code for tokens.
384 // OneClickSigninSyncStarter will delete itself once the job is done. 386 // OneClickSigninSyncStarter will delete itself once the job is done.
385 new OneClickSigninSyncStarter( 387 new OneClickSigninSyncStarter(
386 profile_, browser, 388 profile_, browser,
387 gaia_id_, email_, password_, result.refresh_token, 389 gaia_id_, email_, password_, result.refresh_token,
388 start_mode, 390 start_mode,
389 contents, 391 contents,
390 confirmation_required, 392 confirmation_required,
391 signin::GetNextPageURLForPromoURL(current_url_), 393 signin::GetNextPageURLForPromoURL(current_url_),
392 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_)); 394 base::Bind(&InlineLoginHandlerImpl::SyncStarterCallback, handler_));
393 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 395 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
394 } 396 }
395 } 397 }
396 } 398 }
397 399
398 bool InlineSigninHelper::HandleCrossAccountError( 400 bool InlineSigninHelper::HandleCrossAccountError(
399 const std::string& refresh_token, 401 const std::string& refresh_token,
400 signin_metrics::Source source, 402 signin_metrics::Source source,
401 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required, 403 OneClickSigninSyncStarter::ConfirmationRequired confirmation_required,
402 OneClickSigninSyncStarter::StartSyncMode start_mode) { 404 OneClickSigninSyncStarter::StartSyncMode start_mode) {
403 std::string last_email = 405 std::string last_email =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 break; 453 break;
452 case ConfirmEmailDialogDelegate::CLOSE: 454 case ConfirmEmailDialogDelegate::CLOSE:
453 if (handler_) { 455 if (handler_) {
454 handler_->SyncStarterCallback( 456 handler_->SyncStarterCallback(
455 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE); 457 OneClickSigninSyncStarter::SYNC_SETUP_FAILURE);
456 } 458 }
457 break; 459 break;
458 default: 460 default:
459 DCHECK(false) << "Invalid action"; 461 DCHECK(false) << "Invalid action";
460 } 462 }
461 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 463 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
462 } 464 }
463 465
464 void InlineSigninHelper::OnClientOAuthFailure( 466 void InlineSigninHelper::OnClientOAuthFailure(
465 const GoogleServiceAuthError& error) { 467 const GoogleServiceAuthError& error) {
466 if (handler_) 468 if (handler_)
467 handler_->HandleLoginError(error.ToString()); 469 handler_->HandleLoginError(error.ToString());
468 470
469 AboutSigninInternals* about_signin_internals = 471 AboutSigninInternals* about_signin_internals =
470 AboutSigninInternalsFactory::GetForProfile(profile_); 472 AboutSigninInternalsFactory::GetForProfile(profile_);
471 about_signin_internals->OnRefreshTokenReceived("Failure"); 473 about_signin_internals->OnRefreshTokenReceived("Failure");
472 474
473 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 475 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
474 } 476 }
475 477
476 } // namespace 478 } // namespace
477 479
478 InlineLoginHandlerImpl::InlineLoginHandlerImpl() 480 InlineLoginHandlerImpl::InlineLoginHandlerImpl()
479 : confirm_untrusted_signin_(false), 481 : confirm_untrusted_signin_(false),
480 weak_factory_(this) { 482 weak_factory_(this) {
481 } 483 }
482 484
483 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {} 485 InlineLoginHandlerImpl::~InlineLoginHandlerImpl() {}
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 return; 752 return;
751 } 753 }
752 754
753 const GURL& current_url = contents->GetLastCommittedURL(); 755 const GURL& current_url = contents->GetLastCommittedURL();
754 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url); 756 signin_metrics::Source source = signin::GetSourceForPromoURL(current_url);
755 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); 757 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url);
756 758
757 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) { 759 if (result == OneClickSigninSyncStarter::SYNC_SETUP_FAILURE) {
758 RedirectToNtpOrAppsPage(contents, source); 760 RedirectToNtpOrAppsPage(contents, source);
759 } else if (auto_close) { 761 } else if (auto_close) {
760 base::MessageLoop::current()->PostTask( 762 base::ThreadTaskRunnerHandle::Get()->PostTask(
761 FROM_HERE, 763 FROM_HERE,
762 base::Bind(&InlineLoginHandlerImpl::CloseTab, 764 base::Bind(&InlineLoginHandlerImpl::CloseTab,
763 weak_factory_.GetWeakPtr(), 765 weak_factory_.GetWeakPtr(),
764 signin::ShouldShowAccountManagement(current_url))); 766 signin::ShouldShowAccountManagement(current_url)));
765 } else { 767 } else {
766 RedirectToNtpOrAppsPageIfNecessary(contents, source); 768 RedirectToNtpOrAppsPageIfNecessary(contents, source);
767 } 769 }
768 } 770 }
769 771
770 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) { 772 void InlineLoginHandlerImpl::CloseTab(bool show_account_management) {
771 content::WebContents* tab = web_ui()->GetWebContents(); 773 content::WebContents* tab = web_ui()->GetWebContents();
772 Browser* browser = chrome::FindBrowserWithWebContents(tab); 774 Browser* browser = chrome::FindBrowserWithWebContents(tab);
773 if (browser) { 775 if (browser) {
774 TabStripModel* tab_strip_model = browser->tab_strip_model(); 776 TabStripModel* tab_strip_model = browser->tab_strip_model();
775 if (tab_strip_model) { 777 if (tab_strip_model) {
776 int index = tab_strip_model->GetIndexOfWebContents(tab); 778 int index = tab_strip_model->GetIndexOfWebContents(tab);
777 if (index != TabStripModel::kNoTab) { 779 if (index != TabStripModel::kNoTab) {
778 tab_strip_model->ExecuteContextMenuCommand( 780 tab_strip_model->ExecuteContextMenuCommand(
779 index, TabStripModel::CommandCloseTab); 781 index, TabStripModel::CommandCloseTab);
780 } 782 }
781 } 783 }
782 784
783 if (show_account_management) { 785 if (show_account_management) {
784 browser->window()->ShowAvatarBubbleFromAvatarButton( 786 browser->window()->ShowAvatarBubbleFromAvatarButton(
785 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT, 787 BrowserWindow::AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
786 signin::ManageAccountsParams()); 788 signin::ManageAccountsParams());
787 } 789 }
788 } 790 }
789 } 791 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698