Index: chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
diff --git a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
index c1a007f96bd88c352c32a60631d396d6e684ff00..e80b3490bad76a1e55a192930e5c3d614ef27776 100644 |
--- a/chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
+++ b/chrome/browser/ui/webui/ntp/ntp_login_handler.cc |
@@ -11,10 +11,13 @@ |
#include "base/metrics/histogram.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/google/google_util.h" |
#include "chrome/browser/prefs/pref_notifier.h" |
#include "chrome/browser/prefs/pref_service.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/profiles/profile_metrics.h" |
#include "chrome/browser/sync/profile_sync_service.h" |
#include "chrome/browser/sync/sync_setup_flow.h" |
@@ -23,6 +26,7 @@ |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/browser/ui/webui/sync_promo_ui.h" |
+#include "chrome/browser/ui/webui/web_ui_util.h" |
#include "chrome/browser/web_resource/promo_resource_service.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/pref_names.h" |
@@ -32,6 +36,7 @@ |
#include "grit/chromium_strings.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "content/public/browser/notification_service.h" |
NTPLoginHandler::NTPLoginHandler() { |
} |
@@ -43,6 +48,9 @@ WebUIMessageHandler* NTPLoginHandler::Attach(WebUI* web_ui) { |
PrefService* pref_service = Profile::FromWebUI(web_ui)->GetPrefs(); |
username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); |
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
+ content::NotificationService::AllSources()); |
+ |
return WebUIMessageHandler::Attach(web_ui); |
} |
@@ -64,10 +72,14 @@ void NTPLoginHandler::RegisterMessages() { |
void NTPLoginHandler::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
- DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); |
- std::string* name = content::Details<std::string>(details).ptr(); |
- if (prefs::kGoogleServicesUsername == *name) |
- UpdateLogin(); |
+ if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { |
+ UpdateLogin(); |
+ } else { |
+ DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); |
+ std::string* name = content::Details<std::string>(details).ptr(); |
+ if (prefs::kGoogleServicesUsername == *name) |
+ UpdateLogin(); |
+ } |
} |
void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { |
@@ -137,8 +149,23 @@ void NTPLoginHandler::UpdateLogin() { |
prefs::kGoogleServicesUsername); |
string16 header, sub_header; |
+ std::string icon_url; |
if (!username.empty()) { |
- header = UTF8ToUTF16(username); |
+ string16 full_name; |
+ ProfileInfoCache& cache = |
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
+ if (profile_index != std::string::npos) { |
+ full_name = cache.GetGAIANameOfProfileAtIndex(profile_index); |
+ SkBitmap bmp = cache.GetGAIAPictureOfProfileAtIndex(profile_index); |
+ if (!bmp.isNull()) |
+ icon_url = web_ui_util::GetImageDataUrl(bmp); |
+ } |
+ if (full_name.empty()) { |
+ header = UTF8ToUTF16(username); |
+ } else { |
+ header = full_name; |
+ } |
} else if (SyncPromoUI::ShouldShowSyncPromo(profile) && |
(SyncPromoUI::UserHasSeenSyncPromoAtStartup(profile) || |
PromoResourceService::CanShowNTPSignInPromo(profile))) { |
@@ -157,8 +184,9 @@ void NTPLoginHandler::UpdateLogin() { |
StringValue header_value(header); |
StringValue sub_header_value(sub_header); |
+ StringValue icon_url_value(icon_url); |
web_ui_->CallJavascriptFunction( |
- "updateLogin", header_value, sub_header_value); |
+ "updateLogin", header_value, sub_header_value, icon_url_value); |
} |
// static |