| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sync_confirmation_handler.h" | 5 #include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h" |
| 6 | 6 |
| 7 #include <vector> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 11 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/signin_view_controller_delegate.h" | 15 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 15 #include "components/signin/core/browser/account_tracker_service.h" | 17 #include "components/signin/core/browser/account_tracker_service.h" |
| 16 #include "content/public/browser/user_metrics.h" | 18 #include "content/public/browser/user_metrics.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 35 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); | 37 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); |
| 36 web_ui()->RegisterMessageCallback("goToSettings", | 38 web_ui()->RegisterMessageCallback("goToSettings", |
| 37 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, | 39 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, |
| 38 base::Unretained(this))); | 40 base::Unretained(this))); |
| 39 web_ui()->RegisterMessageCallback("initializedWithSize", | 41 web_ui()->RegisterMessageCallback("initializedWithSize", |
| 40 base::Bind(&SyncConfirmationHandler::HandleInitializedWithSize, | 42 base::Bind(&SyncConfirmationHandler::HandleInitializedWithSize, |
| 41 base::Unretained(this))); | 43 base::Unretained(this))); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { | 46 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { |
| 45 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 47 bool open_activity_controls_url = false; |
| 48 bool success = args->GetBoolean(0, &open_activity_controls_url); |
| 49 DCHECK(success); |
| 50 uint32_t result = LoginUIService::SYNC_WITH_DEFAULT_SETTINGS; |
| 51 if (open_activity_controls_url) |
| 52 result |= LoginUIService::OPEN_ACTIVITY_CONTROLS_URL; |
| 53 CloseModalSigninWindow(result); |
| 46 } | 54 } |
| 47 | 55 |
| 48 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { | 56 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { |
| 49 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); | 57 bool open_activity_controls_url = false; |
| 58 bool success = args->GetBoolean(0, &open_activity_controls_url); |
| 59 DCHECK(success); |
| 60 uint32_t result = LoginUIService::CONFIGURE_SYNC_FIRST; |
| 61 if (open_activity_controls_url) |
| 62 result |= LoginUIService::OPEN_ACTIVITY_CONTROLS_URL; |
| 63 CloseModalSigninWindow(result); |
| 50 } | 64 } |
| 51 | 65 |
| 52 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { | 66 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { |
| 53 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); | 67 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); |
| 54 Browser* browser = GetDesktopBrowser(); | 68 Browser* browser = GetDesktopBrowser(); |
| 55 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 69 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
| 56 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | 70 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
| 57 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | 71 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
| 58 signin_metrics::ABORT_SIGNIN, | 72 signin_metrics::ABORT_SIGNIN, |
| 59 signin_metrics::SignoutDelete::IGNORE_METRIC); | 73 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 81 | 95 |
| 82 Browser* SyncConfirmationHandler::GetDesktopBrowser() { | 96 Browser* SyncConfirmationHandler::GetDesktopBrowser() { |
| 83 Browser* browser = chrome::FindBrowserWithWebContents( | 97 Browser* browser = chrome::FindBrowserWithWebContents( |
| 84 web_ui()->GetWebContents()); | 98 web_ui()->GetWebContents()); |
| 85 if (!browser) | 99 if (!browser) |
| 86 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui())); | 100 browser = chrome::FindLastActiveWithProfile(Profile::FromWebUI(web_ui())); |
| 87 DCHECK(browser); | 101 DCHECK(browser); |
| 88 return browser; | 102 return browser; |
| 89 } | 103 } |
| 90 | 104 |
| 91 void SyncConfirmationHandler::CloseModalSigninWindow( | 105 void SyncConfirmationHandler::CloseModalSigninWindow(uint32_t result) { |
| 92 LoginUIService::SyncConfirmationUIClosedResults results) { | |
| 93 Browser* browser = GetDesktopBrowser(); | 106 Browser* browser = GetDesktopBrowser(); |
| 94 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 107 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
| 95 SyncConfirmationUIClosed(results); | 108 SyncConfirmationUIClosed(result); |
| 96 browser->CloseModalSigninWindow(); | 109 browser->CloseModalSigninWindow(); |
| 97 } | 110 } |
| 98 | 111 |
| 99 void SyncConfirmationHandler::HandleInitializedWithSize( | 112 void SyncConfirmationHandler::HandleInitializedWithSize( |
| 100 const base::ListValue* args) { | 113 const base::ListValue* args) { |
| 101 Browser* browser = GetDesktopBrowser(); | 114 Browser* browser = GetDesktopBrowser(); |
| 102 Profile* profile = browser->profile(); | 115 Profile* profile = browser->profile(); |
| 103 std::vector<AccountInfo> accounts = | 116 std::vector<AccountInfo> accounts = |
| 104 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); | 117 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts(); |
| 105 | 118 |
| 106 if (accounts.empty()) | 119 if (accounts.empty()) |
| 107 return; | 120 return; |
| 108 | 121 |
| 109 AccountInfo primary_account_info = accounts[0]; | 122 AccountInfo primary_account_info = accounts[0]; |
| 110 | 123 |
| 111 if (!primary_account_info.IsValid()) | 124 if (!primary_account_info.IsValid()) |
| 112 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); | 125 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); |
| 113 else | 126 else |
| 114 SetUserImageURL(primary_account_info.picture_url); | 127 SetUserImageURL(primary_account_info.picture_url); |
| 115 | 128 |
| 116 double height; | 129 double height; |
| 117 bool success = args->GetDouble(0, &height); | 130 bool success = args->GetDouble(0, &height); |
| 118 DCHECK(success); | 131 DCHECK(success); |
| 119 | 132 |
| 120 browser->signin_view_controller()->delegate()->ResizeNativeView( | 133 browser->signin_view_controller()->delegate()->ResizeNativeView( |
| 121 static_cast<int>(height)); | 134 static_cast<int>(height)); |
| 122 } | 135 } |
| OLD | NEW |