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

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

Issue 1487283005: Implement the new Sync Confirmation dialog on Linux and Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
9 #include "chrome/browser/signin/account_tracker_service_factory.h"
10 #include "chrome/browser/signin/signin_manager_factory.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
14 #include "components/signin/core/browser/account_tracker_service.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "url/gurl.h"
18
19 const int kProfileImageSize = 128;
20
21 SyncConfirmationHandler::SyncConfirmationHandler() {}
22
23 SyncConfirmationHandler::~SyncConfirmationHandler() {
24 Profile* profile = Profile::FromWebUI(web_ui());
25 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
26 }
27
28 void SyncConfirmationHandler::RegisterMessages() {
29 web_ui()->RegisterMessageCallback("confirm",
30 base::Bind(&SyncConfirmationHandler::HandleConfirm,
31 base::Unretained(this)));
32 web_ui()->RegisterMessageCallback("undo",
33 base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this)));
34 web_ui()->RegisterMessageCallback("initialized",
35 base::Bind(&SyncConfirmationHandler::HandleInitialized,
36 base::Unretained(this)));
37 web_ui()->RegisterMessageCallback("goToSettings",
38 base::Bind(&SyncConfirmationHandler::HandleGoToSettings,
39 base::Unretained(this)));
40 }
41
42 void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) {
43 CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
44 }
45
46 void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) {
47 CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST);
48 }
49
50 void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) {
51 Browser* browser = GetDesktopBrowser();
52 LoginUIServiceFactory::GetForProfile(browser->profile())->
53 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN);
54 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut(
55 signin_metrics::ABORT_SIGNIN);
56 browser->window()->CloseModalSigninWindow();
57 }
Dan Beam 2016/01/22 01:26:58 do you have any tests for this handler? content::T
anthonyvd 2016/01/22 17:19:57 I'll add some.
58
59 void SyncConfirmationHandler::HandleInitialized(const base::ListValue* args) {
60 Browser* browser = GetDesktopBrowser();
61 Profile* profile = browser->profile();
62 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile)->
63 GetAccounts()[0];
64
65 if (!info.IsValid())
66 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this);
67 else
68 SetUserImageURL(info.picture_url);
69 }
70
71 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) {
72 GURL url;
73 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url),
74 kProfileImageSize,
75 &url)) {
76 base::StringValue picture_url_value(url.spec());
77 web_ui()->CallJavascriptFunction(
78 "sync.confirmation.setUserImageURL", picture_url_value);
79 }
80 }
81
82 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) {
83 DCHECK(info.IsValid());
84 Profile* profile = Profile::FromWebUI(web_ui());
85 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
86
87 SetUserImageURL(info.picture_url);
88 }
89
90 Browser* SyncConfirmationHandler::GetDesktopBrowser() {
91 Browser* browser = chrome::FindBrowserWithWebContents(
92 web_ui()->GetWebContents());
93 if (!browser) {
94 browser = chrome::FindLastActiveWithProfile(
95 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop());
96 }
97 DCHECK(browser);
98 return browser;
99 }
100
101 void SyncConfirmationHandler::CloseModalSigninWindow(
102 LoginUIService::SyncConfirmationUIClosedResults results) {
103 Browser* browser = GetDesktopBrowser();
104 LoginUIServiceFactory::GetForProfile(browser->profile())->
105 SyncConfirmationUIClosed(results);
106 browser->window()->CloseModalSigninWindow();
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698