Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.cc" | |
| 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 namespace { | |
| 20 | |
| 21 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.
| |
| 22 | |
| 23 Browser* GetDesktopBrowser(content::WebUI* web_ui) { | |
| 24 Browser* browser = chrome::FindBrowserWithWebContents( | |
| 25 web_ui->GetWebContents()); | |
| 26 if (!browser) { | |
| 27 browser = chrome::FindLastActiveWithProfile( | |
| 28 Profile::FromWebUI(web_ui), chrome::GetActiveDesktop()); | |
| 29 } | |
| 30 return browser; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 SyncConfirmationHandler::SyncConfirmationHandler() {} | |
| 36 | |
| 37 SyncConfirmationHandler::~SyncConfirmationHandler() { | |
| 38 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 39 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | |
| 40 } | |
| 41 | |
| 42 void SyncConfirmationHandler::RegisterMessages() { | |
| 43 web_ui()->RegisterMessageCallback("confirm", | |
| 44 base::Bind(&SyncConfirmationHandler::HandleConfirmMessage, | |
| 45 base::Unretained(this))); | |
| 46 web_ui()->RegisterMessageCallback("undo", | |
| 47 base::Bind(&SyncConfirmationHandler::HandleUndoMessage, | |
| 48 base::Unretained(this))); | |
| 49 web_ui()->RegisterMessageCallback("initialized", | |
| 50 base::Bind(&SyncConfirmationHandler::HandleInitializedMessage, | |
| 51 base::Unretained(this))); | |
| 52 web_ui()->RegisterMessageCallback("goToSettings", | |
| 53 base::Bind(&SyncConfirmationHandler::HandleGoToSettingsMessage, | |
| 54 base::Unretained(this))); | |
| 55 } | |
| 56 | |
| 57 void SyncConfirmationHandler::HandleConfirmMessage( | |
| 58 const base::ListValue* args) { | |
| 59 Browser* browser = GetDesktopBrowser(web_ui()); | |
| 60 DCHECK(browser); | |
|
Dan Beam
2016/01/06 22:57:58
just move this DCHECK() to GetDesktopBrowser()
anthonyvd
2016/01/08 22:39:41
Done.
| |
| 61 LoginUIServiceFactory::GetForProfile(browser->profile())-> | |
| 62 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | |
|
Dan Beam
2016/01/06 22:57:57
indent off
anthonyvd
2016/01/08 22:39:42
Done.
| |
| 63 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.
| |
| 64 } | |
| 65 | |
| 66 void SyncConfirmationHandler::HandleGoToSettingsMessage( | |
| 67 const base::ListValue* args) { | |
| 68 Browser* browser = GetDesktopBrowser(web_ui()); | |
| 69 DCHECK(browser); | |
| 70 LoginUIServiceFactory::GetForProfile(browser->profile())-> | |
| 71 SyncConfirmationUIClosed(LoginUIService::CONFIGURE_SYNC_FIRST); | |
|
Dan Beam
2016/01/06 22:57:57
indent off
anthonyvd
2016/01/08 22:39:42
Done.
| |
| 72 browser->window()->CloseModalSigninWindow(); | |
| 73 } | |
| 74 | |
| 75 void SyncConfirmationHandler::HandleUndoMessage(const base::ListValue* args) { | |
| 76 Browser* browser = GetDesktopBrowser(web_ui()); | |
| 77 DCHECK(browser); | |
| 78 LoginUIServiceFactory::GetForProfile(browser->profile())-> | |
| 79 SyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | |
|
Dan Beam
2016/01/06 22:57:58
indent off
anthonyvd
2016/01/08 22:39:41
Done.
| |
| 80 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()))->SignOut( | |
| 81 signin_metrics::ABORT_SIGNIN); | |
| 82 browser->window()->CloseModalSigninWindow(); | |
| 83 } | |
| 84 | |
| 85 void SyncConfirmationHandler::HandleInitializedMessage( | |
| 86 const base::ListValue* args) { | |
| 87 Browser* browser = GetDesktopBrowser(web_ui()); | |
| 88 DCHECK(browser); | |
| 89 Profile* profile = browser->profile(); | |
| 90 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile)-> | |
| 91 GetAccounts()[0]; | |
| 92 | |
| 93 if (!info.IsValid()) { | |
| 94 AccountTrackerServiceFactory::GetForProfile(profile)->AddObserver(this); | |
| 95 } else { | |
| 96 SetUserImageURL(info.picture_url); | |
| 97 } | |
|
Dan Beam
2016/01/06 22:57:57
no curlies
anthonyvd
2016/01/08 22:39:42
Done.
| |
| 98 } | |
| 99 | |
| 100 void SyncConfirmationHandler::SetUserImageURL(std::string picture_url) { | |
| 101 GURL url; | |
| 102 if (profiles::GetImageURLWithThumbnailSize(GURL(picture_url), | |
| 103 kProfileImageSize, | |
| 104 &url)) { | |
| 105 base::StringValue picture_url_value(url.spec()); | |
| 106 web_ui()->CallJavascriptFunction( | |
| 107 "sync.confirmation.setUserImageURL", picture_url_value); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void SyncConfirmationHandler::OnAccountUpdated(const AccountInfo& info) { | |
| 112 DCHECK(info.IsValid()); | |
| 113 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 114 AccountTrackerServiceFactory::GetForProfile(profile)->RemoveObserver(this); | |
| 115 | |
| 116 SetUserImageURL(info.picture_url); | |
| 117 } | |
| OLD | NEW |