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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
diff --git a/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c933ce876a4172a2c03a9b122de8fdeb06311083
--- /dev/null
+++ b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc
@@ -0,0 +1,104 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/signin/sync_confirmation_handler.h"
+
+#include "base/bind.h"
+#include "chrome/browser/profiles/profile_avatar_icon_util.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
+#include "components/signin/core/browser/account_tracker_service.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_ui.h"
+#include "url/gurl.h"
+
+const int kProfileImageSize = 128;
+
+SyncConfirmationHandler::SyncConfirmationHandler() {}
+
+SyncConfirmationHandler::~SyncConfirmationHandler() {
+ Profile* profile = Profile::FromWebUI(web_ui());
+ AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
+}
+
+void SyncConfirmationHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback("confirm",
+ base::Bind(&SyncConfirmationHandler::HandleConfirm,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("undo",
+ base::Bind(&SyncConfirmationHandler::HandleUndo, base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("initialized",
+ base::Bind(&SyncConfirmationHandler::HandleInitialized,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("goToSettings",
+ base::Bind(&SyncConfirmationHandler::HandleGoToSettings,
+ base::Unretained(this)));
+}
+
+void SyncConfirmationHandler::HandleConfirm(const base::ListValue* args) {
+ CloseModalSigninWindow(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS);
+}
+
+void SyncConfirmationHandler::HandleGoToSettings(const base::ListValue* args) {
+ CloseModalSigninWindow(LoginUIService::CONFIGURE_SYNC_FIRST);
+}
+
+void SyncConfirmationHandler::HandleUndo(const base::ListValue* args) {
+ CloseModalSigninWindow(LoginUIService::ABORT_SIGNIN);
+ SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut(
+ signin_metrics::ABORT_SIGNIN);
+}
+
+void SyncConfirmationHandler::HandleInitialized(const base::ListValue* args) {
+ Browser* browser = GetDesktopBrowser();
+ Profile* profile = browser->profile();
+ AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile)->
+ GetAccounts()[0];
+
+ if (!info.IsValid())
+ AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this);
+ else
+ SetUserImageURL(info.picture_url);
+}
+
+void SyncConfirmationHandler::SetUserImageURL(const std::string& picture_url) {
+ GURL url;
+ if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url),
+ kProfileImageSize,
+ &url)) {
+ base::StringValue picture_url_value(url.spec());
+ web_ui()->CallJavascriptFunction(
+ "sync.confirmation.setUserImageURL", picture_url_value);
+ }
+}
+
+void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) {
+ DCHECK(info.IsValid());
+ Profile* profile = Profile::FromWebUI(web_ui());
+ AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this);
+
+ SetUserImageURL(info.picture_url);
+}
+
+Browser* SyncConfirmationHandler::GetDesktopBrowser() {
+ Browser* browser = chrome::FindBrowserWithWebContents(
+ web_ui()->GetWebContents());
+ if (!browser) {
+ browser = chrome::FindLastActiveWithProfile(
+ Profile::FromWebUI(web_ui()), chrome::GetActiveDesktop());
+ }
+ DCHECK(browser);
+ return browser;
+}
+
+void SyncConfirmationHandler::CloseModalSigninWindow(
+ LoginUIService::SyncConfirmationUIClosedResults results) {
+ Browser* browser = GetDesktopBrowser();
+ LoginUIServiceFactory::GetForProfile(browser->profile())->
+ SyncConfirmationUIClosed(results);
+ browser->window()->CloseModalSigninWindow();
+}

Powered by Google App Engine
This is Rietveld 408576698