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> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/user_metrics.h" |
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
11 #include "chrome/browser/signin/account_tracker_service_factory.h" | 12 #include "chrome/browser/signin/account_tracker_service_factory.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 13 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/signin_view_controller_delegate.h" | 15 #include "chrome/browser/ui/signin_view_controller_delegate.h" |
15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
16 #include "chrome/browser/ui/webui/signin/signin_utils.h" | 17 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
17 #include "components/signin/core/browser/account_tracker_service.h" | 18 #include "components/signin/core/browser/account_tracker_service.h" |
18 #include "content/public/browser/user_metrics.h" | |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 const int kProfileImageSize = 128; | 23 const int kProfileImageSize = 128; |
24 | 24 |
25 SyncConfirmationHandler::SyncConfirmationHandler() | 25 SyncConfirmationHandler::SyncConfirmationHandler() |
26 : did_user_explicitly_interact(false) {} | 26 : did_user_explicitly_interact(false) {} |
27 | 27 |
28 SyncConfirmationHandler::~SyncConfirmationHandler() { | 28 SyncConfirmationHandler::~SyncConfirmationHandler() { |
29 Profile* profile = Profile::FromWebUI(web_ui()); | 29 Profile* profile = Profile::FromWebUI(web_ui()); |
30 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | 30 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); |
31 | 31 |
32 // Abort signin and prevent sync from starting if none of the actions on the | 32 // Abort signin and prevent sync from starting if none of the actions on the |
33 // sync confirmation dialog are taken by the user. | 33 // sync confirmation dialog are taken by the user. |
34 if (!did_user_explicitly_interact) { | 34 if (!did_user_explicitly_interact) { |
35 HandleUndo(nullptr); | 35 HandleUndo(nullptr); |
36 content::RecordAction(base::UserMetricsAction("Signin_Abort_Signin")); | 36 base::RecordAction(base::UserMetricsAction("Signin_Abort_Signin")); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 void SyncConfirmationHandler::RegisterMessages() { | 40 void SyncConfirmationHandler::RegisterMessages() { |
41 web_ui()->RegisterMessageCallback("confirm", | 41 web_ui()->RegisterMessageCallback("confirm", |
42 base::Bind(&SyncConfirmationHandler::HandleConfirm, | 42 base::Bind(&SyncConfirmationHandler::HandleConfirm, |
43 base::Unretained(this))); | 43 base::Unretained(this))); |
44 web_ui()->RegisterMessageCallback("undo", | 44 web_ui()->RegisterMessageCallback("undo", |
45 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); | 45 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this))); |
46 web_ui()->RegisterMessageCallback("goToSettings", | 46 web_ui()->RegisterMessageCallback("goToSettings", |
47 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, | 47 base::Bind(&SyncConfirmationHandler::HandleGoToSettings, |
48 base::Unretained(this))); | 48 base::Unretained(this))); |
49 web_ui()->RegisterMessageCallback("initializedWithSize", | 49 web_ui()->RegisterMessageCallback("initializedWithSize", |
50 base::Bind(&SyncConfirmationHandler::HandleInitializedWithSize, | 50 base::Bind(&SyncConfirmationHandler::HandleInitializedWithSize, |
51 base::Unretained(this))); | 51 base::Unretained(this))); |
52 } | 52 } |
53 | 53 |
54 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { | 54 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) { |
55 did_user_explicitly_interact = true; | 55 did_user_explicitly_interact = true; |
56 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 56 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
57 } | 57 } |
58 | 58 |
59 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { | 59 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) { |
60 did_user_explicitly_interact = true; | 60 did_user_explicitly_interact = true; |
61 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); | 61 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST); |
62 } | 62 } |
63 | 63 |
64 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { | 64 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) { |
65 did_user_explicitly_interact = true; | 65 did_user_explicitly_interact = true; |
66 content::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); | 66 base::RecordAction(base::UserMetricsAction("Signin_Undo_Signin")); |
67 Browser* browser = signin::GetDesktopBrowser(web_ui()); | 67 Browser* browser = signin::GetDesktopBrowser(web_ui()); |
68 if (browser) { | 68 if (browser) { |
69 LoginUIServiceFactory::GetForProfile(browser->profile())-> | 69 LoginUIServiceFactory::GetForProfile(browser->profile())-> |
70 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | 70 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
71 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | 71 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
72 signin_metrics::ABORT_SIGNIN, | 72 signin_metrics::ABORT_SIGNIN, |
73 signin_metrics::SignoutDelete::IGNORE_METRIC); | 73 signin_metrics::SignoutDelete::IGNORE_METRIC); |
74 browser->CloseModalSigninWindow(); | 74 browser->CloseModalSigninWindow(); |
75 } | 75 } |
76 } | 76 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 signin::SetInitializedModalHeight(web_ui(), args); | 142 signin::SetInitializedModalHeight(web_ui(), args); |
143 | 143 |
144 // After the dialog is shown, some platforms might have an element focused. | 144 // After the dialog is shown, some platforms might have an element focused. |
145 // To be consistent, clear the focused element on all platforms. | 145 // To be consistent, clear the focused element on all platforms. |
146 // TODO(anthonyvd): Figure out why this is needed on Mac and not other | 146 // TODO(anthonyvd): Figure out why this is needed on Mac and not other |
147 // platforms and if there's a way to start unfocused while avoiding this | 147 // platforms and if there's a way to start unfocused while avoiding this |
148 // workaround. | 148 // workaround. |
149 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); | 149 web_ui()->CallJavascriptFunctionUnsafe("sync.confirmation.clearFocus"); |
150 } | 150 } |
OLD | NEW |