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

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: Fix Mac/ChromeOS builds and iOS tests. 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 signin_metrics::SignoutDelete::IGNORE_METRIC);
57 browser->window()->CloseModalSigninWindow();
58 }
59
60 void SyncConfirmationHandler::HandleInitialized(const base::ListValue* args) {
61 Browser* browser = GetDesktopBrowser();
62 Profile* profile = browser->profile();
63 std::vector<AccountInfo> accounts =
64 AccountTrackerServiceFactory::GetForProfile(profile)->GetAccounts();
65
66 if (accounts.empty())
67 return;
68
69 AccountInfo primary_account_info = accounts[0];
70
71 if (!primary_account_info.IsValid())
72 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this);
73 else
74 SetUserImageURL(primary_account_info.picture_url);
75 }
76
77 void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) {
78 GURL url;
79 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url),
80 kProfileImageSize,
81 &url)) {
82 base::StringValue picture_url_value(url.spec());
83 web_ui()->CallJavascriptFunction(
84 "sync.confirmation.setUserImageURL", picture_url_value);
85 }
86 }
87
88 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) {
89 DCHECK(info.IsValid());
90 Profile* profile = Profile::FromWebUI(web_ui());
91 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
92
93 SetUserImageURL(info.picture_url);
94 }
95
96 Browser* SyncConfirmationHandler::GetDesktopBrowser() {
97 Browser* browser = chrome::FindBrowserWithWebContents(
98 web_ui()->GetWebContents());
99 if (!browser) {
100 browser = chrome::FindLastActiveWithProfile(
101 Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop());
102 }
103 DCHECK(browser);
104 return browser;
105 }
106
107 void SyncConfirmationHandler::CloseModalSigninWindow(
108 LoginUIService::SyncConfirmationUIClosedResults results) {
109 Browser* browser = GetDesktopBrowser();
110 LoginUIServiceFactory::GetForProfile(browser->profile())->
111 SyncConfirmationUIClosed(results);
112 browser->window()->CloseModalSigninWindow();
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698