Commit 55191fa2 authored by dbeam's avatar dbeam Committed by Commit bot

Split NTPLoginHandler across chrome://apps and chrome://history.

NTPLoginHandler was originally used to handle login from the NTP. It now
handles login on chrome://apps and chrome://history and employs a dirty
little hack to be re-used.

Undo that hack (exposing of ntp.updateLogin on chrome://history) and
split the handler logically, slimming the history handler
(which runs on mobile).

R=mad@chromium.org
BUG=329637

Review URL: https://codereview.chromium.org/1143963002

Cr-Commit-Position: refs/heads/master@{#330874}
parent c349e62d
...@@ -535,15 +535,10 @@ function setForeignSessions(sessionList, isTabSyncEnabled) { ...@@ -535,15 +535,10 @@ function setForeignSessions(sessionList, isTabSyncEnabled) {
} }
/** /**
* Called when this element is initialized, and from the new tab page when * Called when initialized or the user's signed in state changes,
* the user's signed in state changes,
* @param {string} header The first line of text (unused here).
* @param {string} subHeader The second line of text (unused here).
* @param {string} iconURL The url for the login status icon. If this is null
then the login status icon is hidden (unused here).
* @param {boolean} isUserSignedIn Is the user currently signed in? * @param {boolean} isUserSignedIn Is the user currently signed in?
*/ */
function updateLogin(header, subHeader, iconURL, isUserSignedIn) { function updateSignInState(isUserSignedIn) {
if (devicesView) if (devicesView)
devicesView.updateSignInState(isUserSignedIn); devicesView.updateSignInState(isUserSignedIn);
} }
...@@ -557,15 +552,6 @@ function load() { ...@@ -557,15 +552,6 @@ function load() {
if (!loadTimeData.getBoolean('isInstantExtendedApiEnabled')) if (!loadTimeData.getBoolean('isInstantExtendedApiEnabled'))
return; return;
// We must use this namespace to reuse the handler code for foreign session
// and login. TODO(estade): change the call site in ntp_login_handler.cc so
// this hack isn't necessary.
cr.define('ntp', function() {
return {
updateLogin: updateLogin
};
});
devicesView = new DevicesView(); devicesView = new DevicesView();
// Create the context menu that appears when the user right clicks // Create the context menu that appears when the user right clicks
...@@ -577,6 +563,8 @@ function load() { ...@@ -577,6 +563,8 @@ function load() {
}; };
$('search-field').addEventListener('search', doSearch); $('search-field').addEventListener('search', doSearch);
$('search-button').addEventListener('click', doSearch); $('search-button').addEventListener('click', doSearch);
chrome.send('otherDevicesInitialized');
} }
// Add handlers to HTML elements. // Add handlers to HTML elements.
......
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // 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> #include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/prefs/pref_notifier.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.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/browser/web_resource/promo_resource_service.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -79,52 +79,37 @@ base::string16 CreateElementWithClass(const base::string16& content, ...@@ -79,52 +79,37 @@ base::string16 CreateElementWithClass(const base::string16& content,
} // namespace } // namespace
NTPLoginHandler::NTPLoginHandler() { AppLauncherLoginHandler::AppLauncherLoginHandler() {}
}
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);
}
void NTPLoginHandler::RegisterMessages() { AppLauncherLoginHandler::~AppLauncherLoginHandler() {}
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);
PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); void AppLauncherLoginHandler::RegisterMessages() {
signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_info_watcher_.reset(new ProfileInfoWatcher(
pref_service, Profile::FromWebUI(web_ui()),
base::Bind(&NTPLoginHandler::UpdateLogin, base::Bind(&AppLauncherLoginHandler::UpdateLogin,
base::Unretained(this))); base::Unretained(this))));
web_ui()->RegisterMessageCallback("initializeSyncLogin", web_ui()->RegisterMessageCallback("initializeSyncLogin",
base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, base::Bind(&AppLauncherLoginHandler::HandleInitializeSyncLogin,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback("showSyncLoginUI", web_ui()->RegisterMessageCallback("showSyncLoginUI",
base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, base::Bind(&AppLauncherLoginHandler::HandleShowSyncLoginUI,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback("loginMessageSeen", web_ui()->RegisterMessageCallback("loginMessageSeen",
base::Bind(&NTPLoginHandler::HandleLoginMessageSeen, base::Bind(&AppLauncherLoginHandler::HandleLoginMessageSeen,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback("showAdvancedLoginUI", web_ui()->RegisterMessageCallback("showAdvancedLoginUI",
base::Bind(&NTPLoginHandler::HandleShowAdvancedLoginUI, base::Bind(&AppLauncherLoginHandler::HandleShowAdvancedLoginUI,
base::Unretained(this))); base::Unretained(this)));
} }
void NTPLoginHandler::OnProfileAuthInfoChanged( void AppLauncherLoginHandler::HandleInitializeSyncLogin(
const base::FilePath& profile_path) { const base::ListValue* args) {
UpdateLogin();
}
void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) {
UpdateLogin(); UpdateLogin();
} }
void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { void AppLauncherLoginHandler::HandleShowSyncLoginUI(
const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
if (!signin::ShouldShowPromo(profile)) if (!signin::ShouldShowPromo(profile))
return; return;
...@@ -148,7 +133,7 @@ void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { ...@@ -148,7 +133,7 @@ void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) {
RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED); RecordInHistogram(NTP_SIGN_IN_PROMO_CLICKED);
} }
void NTPLoginHandler::RecordInHistogram(int type) { void AppLauncherLoginHandler::RecordInHistogram(int type) {
// Invalid type to record. // Invalid type to record.
if (type < NTP_SIGN_IN_PROMO_VIEWED || if (type < NTP_SIGN_IN_PROMO_VIEWED ||
type > NTP_SIGN_IN_PROMO_CLICKED) { type > NTP_SIGN_IN_PROMO_CLICKED) {
...@@ -159,7 +144,8 @@ void NTPLoginHandler::RecordInHistogram(int type) { ...@@ -159,7 +144,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( Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
prefs::kSignInPromoShowNTPBubble, false); prefs::kSignInPromoShowNTPBubble, false);
NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController()); NewTabUI* ntp_ui = NewTabUI::FromWebUIController(web_ui()->GetController());
...@@ -168,26 +154,19 @@ void NTPLoginHandler::HandleLoginMessageSeen(const base::ListValue* args) { ...@@ -168,26 +154,19 @@ void NTPLoginHandler::HandleLoginMessageSeen(const base::ListValue* args) {
ntp_ui->set_showing_sync_bubble(true); ntp_ui->set_showing_sync_bubble(true);
} }
void NTPLoginHandler::HandleShowAdvancedLoginUI(const base::ListValue* args) { void AppLauncherLoginHandler::HandleShowAdvancedLoginUI(
const base::ListValue* args) {
Browser* browser = Browser* browser =
chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
if (browser) if (browser)
chrome::ShowBrowserSignin(browser, signin_metrics::SOURCE_NTP_LINK); chrome::ShowBrowserSignin(browser, signin_metrics::SOURCE_NTP_LINK);
} }
void NTPLoginHandler::UpdateLogin() { void AppLauncherLoginHandler::UpdateLogin() {
Profile* profile = Profile::FromWebUI(web_ui()); std::string username = profile_info_watcher_->GetAuthenticatedUsername();
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();
base::string16 header, sub_header; base::string16 header, sub_header;
std::string icon_url; std::string icon_url;
Profile* profile = Profile::FromWebUI(web_ui());
if (!username.empty()) { if (!username.empty()) {
ProfileInfoCache& cache = ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache(); g_browser_process->profile_manager()->GetProfileInfoCache();
...@@ -240,7 +219,7 @@ void NTPLoginHandler::UpdateLogin() { ...@@ -240,7 +219,7 @@ void NTPLoginHandler::UpdateLogin() {
} }
// static // static
bool NTPLoginHandler::ShouldShow(Profile* profile) { bool AppLauncherLoginHandler::ShouldShow(Profile* profile) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// For now we don't care about showing sync status on Chrome OS. The promo // 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. // UI and the avatar menu don't exist on that platform.
...@@ -252,8 +231,8 @@ bool NTPLoginHandler::ShouldShow(Profile* profile) { ...@@ -252,8 +231,8 @@ bool NTPLoginHandler::ShouldShow(Profile* profile) {
} }
// static // static
void NTPLoginHandler::GetLocalizedValues(Profile* profile, void AppLauncherLoginHandler::GetLocalizedValues(
base::DictionaryValue* values) { Profile* profile, base::DictionaryValue* values) {
PrefService* prefs = profile->GetPrefs(); PrefService* prefs = profile->GetPrefs();
bool hide_sync = !prefs->GetBoolean(prefs::kSignInPromoShowNTPBubble); bool hide_sync = !prefs->GetBoolean(prefs::kSignInPromoShowNTPBubble);
......
...@@ -2,30 +2,27 @@ ...@@ -2,30 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ #ifndef CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_LOGIN_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_LOGIN_HANDLER_H_
#include "base/prefs/pref_member.h" #include "base/macros.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h" #include "base/memory/scoped_ptr.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
class Profile; class Profile;
class ProfileInfoWatcher;
// The NTP login handler currently simply displays the current logged in // The login handler currently simply displays the current logged in
// username at the top of the NTP (and update itself when that changes). // username at the top of the NTP (and update itself when that changes).
// In the future it may expand to allow users to login from the NTP. // In the future it may expand to allow users to login from the NTP.
class NTPLoginHandler : public content::WebUIMessageHandler, class AppLauncherLoginHandler : public content::WebUIMessageHandler {
public ProfileInfoCacheObserver {
public: public:
NTPLoginHandler(); AppLauncherLoginHandler();
~NTPLoginHandler() override; ~AppLauncherLoginHandler() override;
// WebUIMessageHandler implementation: // WebUIMessageHandler implementation:
void RegisterMessages() override; void RegisterMessages() override;
// ProfileInfoCacheObserver implementation:
void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
// Returns true if the login handler should be shown in a new tab page // Returns true if the login handler should be shown in a new tab page
// for the given |profile|. |profile| must not be NULL. // for the given |profile|. |profile| must not be NULL.
static bool ShouldShow(Profile* profile); static bool ShouldShow(Profile* profile);
...@@ -66,7 +63,11 @@ class NTPLoginHandler : public content::WebUIMessageHandler, ...@@ -66,7 +63,11 @@ class NTPLoginHandler : public content::WebUIMessageHandler,
// Internal helper method // Internal helper method
void UpdateLogin(); void UpdateLogin();
BooleanPrefMember signin_allowed_pref_; // Watches this web UI's profile for info changes (e.g. authenticated username
// changes).
scoped_ptr<ProfileInfoWatcher> profile_info_watcher_;
DISALLOW_COPY_AND_ASSIGN(AppLauncherLoginHandler);
}; };
#endif // CHROME_BROWSER_UI_WEBUI_NTP_NTP_LOGIN_HANDLER_H_ #endif // CHROME_BROWSER_UI_WEBUI_APP_LAUNCHER_LOGIN_HANDLER_H_
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/app_launcher_login_handler.h"
#include "chrome/browser/ui/webui/metrics_handler.h" #include "chrome/browser/ui/webui/metrics_handler.h"
#include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
#include "chrome/browser/ui/webui/ntp/app_resource_cache_factory.h" #include "chrome/browser/ui/webui/ntp/app_resource_cache_factory.h"
#include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
#include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -39,8 +39,8 @@ AppLauncherPageUI::AppLauncherPageUI(content::WebUI* web_ui) ...@@ -39,8 +39,8 @@ AppLauncherPageUI::AppLauncherPageUI(content::WebUI* web_ui)
: content::WebUIController(web_ui) { : content::WebUIController(web_ui) {
web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_APP_LAUNCHER_TAB_TITLE)); web_ui->OverrideTitle(l10n_util::GetStringUTF16(IDS_APP_LAUNCHER_TAB_TITLE));
if (NTPLoginHandler::ShouldShow(GetProfile())) if (AppLauncherLoginHandler::ShouldShow(GetProfile()))
web_ui->AddMessageHandler(new NTPLoginHandler()); web_ui->AddMessageHandler(new AppLauncherLoginHandler());
if (!GetProfile()->IsOffTheRecord()) { if (!GetProfile()->IsOffTheRecord()) {
ExtensionService* service = ExtensionService* service =
......
// 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/history_login_handler.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/profile_info_watcher.h"
#include "content/public/browser/web_ui.h"
HistoryLoginHandler::HistoryLoginHandler() {}
HistoryLoginHandler::~HistoryLoginHandler() {}
void HistoryLoginHandler::RegisterMessages() {
profile_info_watcher_.reset(new ProfileInfoWatcher(
Profile::FromWebUI(web_ui()),
base::Bind(&HistoryLoginHandler::ProfileInfoChanged,
base::Unretained(this))));
web_ui()->RegisterMessageCallback("otherDevicesInitialized",
base::Bind(&HistoryLoginHandler::HandleOtherDevicesInitialized,
base::Unretained(this)));
}
void HistoryLoginHandler::HandleOtherDevicesInitialized(
const base::ListValue* /*args*/) {
ProfileInfoChanged();
}
void HistoryLoginHandler::ProfileInfoChanged() {
bool signed_in = !profile_info_watcher_->GetAuthenticatedUsername().empty();
web_ui()->CallJavascriptFunction(
"updateSignInState", base::FundamentalValue(signed_in));
}
// 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.
#ifndef CHROME_BROWSER_UI_WEBUI_HISTORY_LOGIN_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_HISTORY_LOGIN_HANDLER_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/web_ui_message_handler.h"
class ProfileInfoWatcher;
// The handler for login-related messages from chrome://history.
class HistoryLoginHandler : public content::WebUIMessageHandler {
public:
HistoryLoginHandler();
~HistoryLoginHandler() override;
// WebUIMessageHandler implementation.
void RegisterMessages() override;
private:
// Handler for the "otherDevicesInitialized" message. No args.
void HandleOtherDevicesInitialized(const base::ListValue* args);
// Called by |profile_info_watcher_| on desktop if profile info changes.
void ProfileInfoChanged();
// Watches this web UI's profile for info changes (e.g. authenticated username
// changes).
scoped_ptr<ProfileInfoWatcher> profile_info_watcher_;
DISALLOW_COPY_AND_ASSIGN(HistoryLoginHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_HISTORY_LOGIN_HANDLER_H_
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
#include "chrome/browser/ui/webui/foreign_session_handler.h" #include "chrome/browser/ui/webui/foreign_session_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_login_handler.h" #include "chrome/browser/ui/webui/history_login_handler.h"
#endif #endif
using bookmarks::BookmarkModel; using bookmarks::BookmarkModel;
...@@ -1029,11 +1029,11 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { ...@@ -1029,11 +1029,11 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
web_ui->AddMessageHandler(new BrowsingHistoryHandler()); web_ui->AddMessageHandler(new BrowsingHistoryHandler());
web_ui->AddMessageHandler(new MetricsHandler()); web_ui->AddMessageHandler(new MetricsHandler());
// On mobile we deal with foreign sessions differently. // On mobile we deal with foreign sessions differently.
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID) && !defined(OS_IOS)
if (chrome::IsInstantExtendedAPIEnabled()) { if (chrome::IsInstantExtendedAPIEnabled()) {
web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
web_ui->AddMessageHandler(new NTPLoginHandler()); web_ui->AddMessageHandler(new HistoryLoginHandler());
} }
#endif #endif
...@@ -1042,6 +1042,8 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { ...@@ -1042,6 +1042,8 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile));
} }
HistoryUI::~HistoryUI() {}
// static // static
base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
ui::ScaleFactor scale_factor) { ui::ScaleFactor scale_factor) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
...@@ -219,6 +220,7 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler, ...@@ -219,6 +220,7 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler,
class HistoryUI : public content::WebUIController { class HistoryUI : public content::WebUIController {
public: public:
explicit HistoryUI(content::WebUI* web_ui); explicit HistoryUI(content::WebUI* web_ui);
~HistoryUI() override;
static base::RefCountedMemory* GetFaviconResourceBytes( static base::RefCountedMemory* GetFaviconResourceBytes(
ui::ScaleFactor scale_factor); ui::ScaleFactor scale_factor);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
#include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
...@@ -105,9 +104,6 @@ NewTabUI::NewTabUI(content::WebUI* web_ui) ...@@ -105,9 +104,6 @@ NewTabUI::NewTabUI(content::WebUI* web_ui)
web_ui->AddMessageHandler(new AppLauncherHandler(service)); web_ui->AddMessageHandler(new AppLauncherHandler(service));
} }
if (NTPLoginHandler::ShouldShow(profile))
web_ui->AddMessageHandler(new NTPLoginHandler());
#if defined(ENABLE_THEMES) #if defined(ENABLE_THEMES)
// The theme handler can require some CPU, so do it after hooking up the most // The theme handler can require some CPU, so do it after hooking up the most
// visited handler. This allows the DB query for the new tab thumbs to happen // visited handler. This allows the DB query for the new tab thumbs to happen
......
...@@ -31,9 +31,9 @@ ...@@ -31,9 +31,9 @@
#include "chrome/browser/ui/apps/app_info_dialog.h" #include "chrome/browser/ui/apps/app_info_dialog.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h" #include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/webui/app_launcher_login_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
#include "chrome/browser/web_resource/notification_promo.h" #include "chrome/browser/web_resource/notification_promo.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -448,7 +448,7 @@ void NTPResourceCache::CreateNewTabHTML() { ...@@ -448,7 +448,7 @@ void NTPResourceCache::CreateNewTabHTML() {
load_time_data.SetString("syncLinkText", load_time_data.SetString("syncLinkText",
l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS)); l10n_util::GetStringUTF16(IDS_SYNC_ADVANCED_OPTIONS));
load_time_data.SetBoolean("shouldShowSyncLogin", load_time_data.SetBoolean("shouldShowSyncLogin",
NTPLoginHandler::ShouldShow(profile_)); AppLauncherLoginHandler::ShouldShow(profile_));
load_time_data.SetString("learnMore", load_time_data.SetString("learnMore",
l10n_util::GetStringUTF16(IDS_LEARN_MORE)); l10n_util::GetStringUTF16(IDS_LEARN_MORE));
const std::string& app_locale = g_browser_process->GetApplicationLocale(); const std::string& app_locale = g_browser_process->GetApplicationLocale();
...@@ -489,7 +489,7 @@ void NTPResourceCache::CreateNewTabHTML() { ...@@ -489,7 +489,7 @@ void NTPResourceCache::CreateNewTabHTML() {
#endif #endif
NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data); NewTabPageHandler::GetLocalizedValues(profile_, &load_time_data);
NTPLoginHandler::GetLocalizedValues(profile_, &load_time_data); AppLauncherLoginHandler::GetLocalizedValues(profile_, &load_time_data);
webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); webui::SetLoadTimeDataDefaults(app_locale, &load_time_data);
......
// 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/profile_info_watcher.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "components/signin/core/browser/signin_manager.h"
ProfileInfoWatcher::ProfileInfoWatcher(
Profile* profile, const base::Closure& callback)
: profile_(profile), callback_(callback) {
DCHECK(profile_);
DCHECK(!callback_.is_null());
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);
signin_allowed_pref_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
base::Bind(&ProfileInfoWatcher::RunCallback, base::Unretained(this)));
}
ProfileInfoWatcher::~ProfileInfoWatcher() {
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);
}
void ProfileInfoWatcher::OnProfileAuthInfoChanged(
const base::FilePath& profile_path) {
RunCallback();
}
std::string ProfileInfoWatcher::GetAuthenticatedUsername() const {
std::string username;
SigninManagerBase* signin_manager = GetSigninManager();
if (signin_manager)
username = signin_manager->GetAuthenticatedUsername();
return username;
}
SigninManagerBase* ProfileInfoWatcher::GetSigninManager() const {
return SigninManagerFactory::GetForProfile(profile_);
}
void ProfileInfoWatcher::RunCallback() {
if (GetSigninManager())
callback_.Run();
}
// 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.
#ifndef CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_
#define CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "base/prefs/pref_member.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
class Profile;
class SigninManagerBase;
// Watches profiles for changes in their cached info (e.g. the authenticated
// username changes).
class ProfileInfoWatcher : public ProfileInfoCacheObserver {
public:
ProfileInfoWatcher(Profile* profile, const base::Closure& callback);
~ProfileInfoWatcher() override;
// Gets the authenticated username (e.g. username@gmail.com) for |profile_|.
std::string GetAuthenticatedUsername() const;
private:
// ProfileInfoCacheObserver:
void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
// Gets the SigninManagerBase for |profile_|.
SigninManagerBase* GetSigninManager() const;
// Runs |callback_| when a profile changes. No-ops if |GetSigninManager()|
// returns nullptr.
void RunCallback();
// Weak reference to the profile this class observes.
Profile* const profile_;
// Called when the authenticated username changes.
base::Closure callback_;
BooleanPrefMember signin_allowed_pref_;
DISALLOW_COPY_AND_ASSIGN(ProfileInfoWatcher);
};
#endif // CHROME_BROWSER_UI_WEBUI_PROFILE_INFO_WATCHER_H_
...@@ -1733,6 +1733,8 @@ ...@@ -1733,6 +1733,8 @@
'browser/ui/website_settings/permission_menu_model.h', 'browser/ui/website_settings/permission_menu_model.h',
'browser/ui/website_settings/website_settings_utils.cc', 'browser/ui/website_settings/website_settings_utils.cc',
'browser/ui/website_settings/website_settings_utils.h', 'browser/ui/website_settings/website_settings_utils.h',
'browser/ui/webui/app_launcher_login_handler.cc',
'browser/ui/webui/app_launcher_login_handler.h',
'browser/ui/webui/bookmarks_ui.cc', 'browser/ui/webui/bookmarks_ui.cc',
'browser/ui/webui/bookmarks_ui.h', 'browser/ui/webui/bookmarks_ui.h',
'browser/ui/webui/chrome_web_contents_handler.cc', 'browser/ui/webui/chrome_web_contents_handler.cc',
...@@ -1769,6 +1771,8 @@ ...@@ -1769,6 +1771,8 @@
'browser/ui/webui/help/version_updater_mac.h', 'browser/ui/webui/help/version_updater_mac.h',
'browser/ui/webui/help/version_updater_mac.mm', 'browser/ui/webui/help/version_updater_mac.mm',
'browser/ui/webui/help/version_updater_win.cc', 'browser/ui/webui/help/version_updater_win.cc',
'browser/ui/webui/history_login_handler.cc',
'browser/ui/webui/history_login_handler.h',
'browser/ui/webui/identity_internals_ui.cc', 'browser/ui/webui/identity_internals_ui.cc',
'browser/ui/webui/identity_internals_ui.h', 'browser/ui/webui/identity_internals_ui.h',
'browser/ui/webui/inspect_ui.cc', 'browser/ui/webui/inspect_ui.cc',
...@@ -1787,8 +1791,6 @@ ...@@ -1787,8 +1791,6 @@
'browser/ui/webui/ntp/new_tab_page_sync_handler.h', 'browser/ui/webui/ntp/new_tab_page_sync_handler.h',
'browser/ui/webui/ntp/new_tab_ui.cc', 'browser/ui/webui/ntp/new_tab_ui.cc',
'browser/ui/webui/ntp/new_tab_ui.h', 'browser/ui/webui/ntp/new_tab_ui.h',
'browser/ui/webui/ntp/ntp_login_handler.cc',
'browser/ui/webui/ntp/ntp_login_handler.h',
'browser/ui/webui/ntp/ntp_resource_cache.cc', 'browser/ui/webui/ntp/ntp_resource_cache.cc',
'browser/ui/webui/ntp/ntp_resource_cache.h', 'browser/ui/webui/ntp/ntp_resource_cache.h',
'browser/ui/webui/ntp/ntp_resource_cache_factory.cc', 'browser/ui/webui/ntp/ntp_resource_cache_factory.cc',
...@@ -1900,6 +1902,8 @@ ...@@ -1900,6 +1902,8 @@
'browser/ui/webui/options/website_settings_handler.h', 'browser/ui/webui/options/website_settings_handler.h',
'browser/ui/webui/plugins_ui.cc', 'browser/ui/webui/plugins_ui.cc',
'browser/ui/webui/plugins_ui.h', 'browser/ui/webui/plugins_ui.h',
'browser/ui/webui/profile_info_watcher.cc',
'browser/ui/webui/profile_info_watcher.h',
'browser/ui/webui/quota_internals/quota_internals_handler.cc', 'browser/ui/webui/quota_internals/quota_internals_handler.cc',
'browser/ui/webui/quota_internals/quota_internals_handler.h', 'browser/ui/webui/quota_internals/quota_internals_handler.h',
'browser/ui/webui/quota_internals/quota_internals_proxy.cc', 'browser/ui/webui/quota_internals/quota_internals_proxy.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment