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..a0af1e98f8d5165daa3b704d621355ace5ab88a6 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/signin/sync_confirmation_handler.cc |
@@ -0,0 +1,117 @@ |
+// 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.cc" |
+#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" |
+ |
+namespace { |
+ |
+const int kProfileImageSize = 128; |
Dan Beam
2016/01/06 22:57:57
can you make this (and the size param to GetImageU
anthonyvd
2016/01/08 22:39:42
Done.
|
+ |
+Browser* GetDesktopBrowser(content::WebUI* web_ui) { |
+ Browser* browser = chrome::FindBrowserWithWebContents( |
+ web_ui->GetWebContents()); |
+ if (!browser) { |
+ browser = chrome::FindLastActiveWithProfile( |
+ Profile::FromWebUI(web_ui), chrome::GetActiveDesktop()); |
+ } |
+ return browser; |
+} |
+ |
+} // namespace |
+ |
+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::HandleConfirmMessage, |
+ base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("undo", |
+ base::Bind(&SyncConfirmationHandler::HandleUndoMessage, |
+ base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("initialized", |
+ base::Bind(&SyncConfirmationHandler::HandleInitializedMessage, |
+ base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("goToSettings", |
+ base::Bind(&SyncConfirmationHandler::HandleGoToSettingsMessage, |
+ base::Unretained(this))); |
+} |
+ |
+void SyncConfirmationHandler::HandleConfirmMessage( |
+ const base::ListValue* args) { |
+ Browser* browser = GetDesktopBrowser(web_ui()); |
+ DCHECK(browser); |
Dan Beam
2016/01/06 22:57:58
just move this DCHECK() to GetDesktopBrowser()
anthonyvd
2016/01/08 22:39:41
Done.
|
+ LoginUIServiceFactory::GetForProfile(browser->profile())-> |
+ SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
Dan Beam
2016/01/06 22:57:57
indent off
anthonyvd
2016/01/08 22:39:42
Done.
|
+ browser->window()->CloseModalSigninWindow(); |
Dan Beam
2016/01/06 22:57:57
can you do something long the lines of:
CloseMo
anthonyvd
2016/01/08 22:39:42
Done.
|
+} |
+ |
+void SyncConfirmationHandler::HandleGoToSettingsMessage( |
+ const base::ListValue* args) { |
+ Browser* browser = GetDesktopBrowser(web_ui()); |
+ DCHECK(browser); |
+ LoginUIServiceFactory::GetForProfile(browser->profile())-> |
+ SyncConfirmationUIClosed(LoginUIService::CONFIGURE_SYNC_FIRST); |
Dan Beam
2016/01/06 22:57:57
indent off
anthonyvd
2016/01/08 22:39:42
Done.
|
+ browser->window()->CloseModalSigninWindow(); |
+} |
+ |
+void SyncConfirmationHandler::HandleUndoMessage(const base::ListValue* args) { |
+ Browser* browser = GetDesktopBrowser(web_ui()); |
+ DCHECK(browser); |
+ LoginUIServiceFactory::GetForProfile(browser->profile())-> |
+ SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); |
Dan Beam
2016/01/06 22:57:58
indent off
anthonyvd
2016/01/08 22:39:41
Done.
|
+ SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( |
+ signin_metrics::ABORT_SIGNIN); |
+ browser->window()->CloseModalSigninWindow(); |
+} |
+ |
+void SyncConfirmationHandler::HandleInitializedMessage( |
+ const base::ListValue* args) { |
+ Browser* browser = GetDesktopBrowser(web_ui()); |
+ DCHECK(browser); |
+ Profile* profile = browser->profile(); |
+ AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile)-> |
+ GetAccounts()[0]; |
+ |
+ if (!info.IsValid()) { |
+ AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); |
+ } else { |
+ SetUserImageURL(info.picture_url); |
+ } |
Dan Beam
2016/01/06 22:57:57
no curlies
anthonyvd
2016/01/08 22:39:42
Done.
|
+} |
+ |
+void SyncConfirmationHandler::SetUserImageURL(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); |
+} |