Chromium Code Reviews| Index: chrome/browser/ui/webui/app_launcher_login_handler.cc |
| diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/app_launcher_login_handler.cc |
| similarity index 80% |
| rename from chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
| rename to chrome/browser/ui/webui/app_launcher_login_handler.cc |
| index f9cfa021a6792ac56cf3e7f80e9f10f9b90999ec..2d656fa1cd1fd771ddba75ad707d7f7ff953689c 100644 |
| --- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
| +++ b/chrome/browser/ui/webui/app_launcher_login_handler.cc |
| @@ -2,7 +2,7 @@ |
| // 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/ntp/ntp_login_handler.h" |
| +#include "chrome/browser/ui/webui/app_launcher_login_handler.h" |
| #include <string> |
| @@ -27,6 +27,7 @@ |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/chrome_pages.h" |
| #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| +#include "chrome/browser/ui/webui/profile_info_watcher.h" |
| #include "chrome/browser/web_resource/promo_resource_service.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| @@ -79,52 +80,37 @@ base::string16 CreateElementWithClass(const base::string16& content, |
| } // namespace |
| -NTPLoginHandler::NTPLoginHandler() { |
| -} |
| - |
| -NTPLoginHandler::~NTPLoginHandler() { |
| - ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| - // The profile_manager might be NULL in testing environments. |
| - if (profile_manager) |
| - profile_manager->GetProfileInfoCache().RemoveObserver(this); |
| -} |
| +AppLauncherLoginHandler::AppLauncherLoginHandler() {} |
| -void NTPLoginHandler::RegisterMessages() { |
| - ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| - // The profile_manager might be NULL in testing environments. |
| - if (profile_manager) |
| - profile_manager->GetProfileInfoCache().AddObserver(this); |
| +AppLauncherLoginHandler::~AppLauncherLoginHandler() {} |
| - PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| - signin_allowed_pref_.Init(prefs::kSigninAllowed, |
| - pref_service, |
| - base::Bind(&NTPLoginHandler::UpdateLogin, |
| - base::Unretained(this))); |
| +void AppLauncherLoginHandler::RegisterMessages() { |
| + profile_info_watcher_.reset(new ProfileInfoWatcher( |
| + Profile::FromWebUI(web_ui()), |
| + base::Bind(&AppLauncherLoginHandler::UpdateLogin, |
| + base::Unretained(this)))); |
| web_ui()->RegisterMessageCallback("initializeSyncLogin", |
| - base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, |
| + base::Bind(&AppLauncherLoginHandler::HandleInitializeSyncLogin, |
| base::Unretained(this))); |
| web_ui()->RegisterMessageCallback("showSyncLoginUI", |
| - base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, |
| + base::Bind(&AppLauncherLoginHandler::HandleShowSyncLoginUI, |
| base::Unretained(this))); |
| web_ui()->RegisterMessageCallback("loginMessageSeen", |
| - base::Bind(&NTPLoginHandler::HandleLoginMessageSeen, |
| + base::Bind(&AppLauncherLoginHandler::HandleLoginMessageSeen, |
| base::Unretained(this))); |
| web_ui()->RegisterMessageCallback("showAdvancedLoginUI", |
| - base::Bind(&NTPLoginHandler::HandleShowAdvancedLoginUI, |
| + base::Bind(&AppLauncherLoginHandler::HandleShowAdvancedLoginUI, |
| base::Unretained(this))); |
| } |
| -void NTPLoginHandler::OnProfileAuthInfoChanged( |
| - const base::FilePath& profile_path) { |
| - UpdateLogin(); |
| -} |
| - |
| -void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { |
| +void AppLauncherLoginHandler::HandleInitializeSyncLogin( |
| + const base::ListValue* args) { |
| UpdateLogin(); |
| } |
| -void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { |
| +void AppLauncherLoginHandler::HandleShowSyncLoginUI( |
| + const base::ListValue* args) { |
| Profile* profile = Profile::FromWebUI(web_ui()); |
| if (!signin::ShouldShowPromo(profile)) |
| return; |
| @@ -148,7 +134,7 @@ void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { |
| RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); |
| } |
| -void NTPLoginHandler::RecordInHistogram(int type) { |
| +void AppLauncherLoginHandler::RecordInHistogram(int type) { |
| // Invalid type to record. |
| if (type < NTP_SIGN_IN_PROMO_VIEWED || |
| type > NTP_SIGN_IN_PROMO_CLICKED) { |
| @@ -159,7 +145,8 @@ void NTPLoginHandler::RecordInHistogram(int type) { |
| } |
| } |
| -void NTPLoginHandler::HandleLoginMessageSeen(const base::ListValue* args) { |
| +void AppLauncherLoginHandler::HandleLoginMessageSeen( |
| + const base::ListValue* args) { |
| Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
| prefs::kSignInPromoShowNTPBubble, false); |
| NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); |
| @@ -168,26 +155,19 @@ void NTPLoginHandler::HandleLoginMessageSeen(const base::ListValue* args) { |
| ntp_ui->set_showing_sync_bubble(true); |
| } |
| -void NTPLoginHandler::HandleShowAdvancedLoginUI(const base::ListValue* args) { |
| +void AppLauncherLoginHandler::HandleShowAdvancedLoginUI( |
| + const base::ListValue* args) { |
| Browser* browser = |
| chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| if (browser) |
| chrome::ShowBrowserSignin(browser, signin_metrics::SOURCE_NTP_LINK); |
| } |
| -void NTPLoginHandler::UpdateLogin() { |
| - Profile* profile = Profile::FromWebUI(web_ui()); |
| - SigninManagerBase* signin_manager = |
| - SigninManagerFactory::GetForProfile(profile); |
| - if (!signin_manager) { |
| - // Guests on desktop do not have a signin manager. |
| - return; |
| - } |
| - |
| - std::string username = signin_manager->GetAuthenticatedUsername(); |
| - |
| +void AppLauncherLoginHandler::UpdateLogin() { |
| + std::string username = profile_info_watcher_->GetAuthenticatedUsername(); |
|
MAD
2015/05/20 19:33:01
DCHECK(profile_info_watcher_.get()); ?
Dan Beam
2015/05/20 21:53:23
nah, that's redundant
https://code.google.com/p/ch
|
| base::string16 header, sub_header; |
| std::string icon_url; |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| if (!username.empty()) { |
| ProfileInfoCache& cache = |
| g_browser_process->profile_manager()->GetProfileInfoCache(); |
| @@ -240,7 +220,7 @@ void NTPLoginHandler::UpdateLogin() { |
| } |
| // static |
| -bool NTPLoginHandler::ShouldShow(Profile* profile) { |
| +bool AppLauncherLoginHandler::ShouldShow(Profile* profile) { |
| #if defined(OS_CHROMEOS) |
| // For now we don't care about showing sync status on Chrome OS. The promo |
| // UI and the avatar menu don't exist on that platform. |
| @@ -252,8 +232,8 @@ bool NTPLoginHandler::ShouldShow(Profile* profile) { |
| } |
| // static |
| -void NTPLoginHandler::GetLocalizedValues(Profile* profile, |
| - base::DictionaryValue* values) { |
| +void AppLauncherLoginHandler::GetLocalizedValues( |
| + Profile* profile, base::DictionaryValue* values) { |
| PrefService* prefs = profile->GetPrefs(); |
| bool hide_sync = !prefs->GetBoolean(prefs::kSignInPromoShowNTPBubble); |