OLD | NEW |
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 Loading... |
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |