Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Unified Diff: chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc

Issue 7610008: Sync Promo: Show profile avatar next to user name (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build issues Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
index 954f3f2dac809fc567d1ea95a546c7dd01561a84..90f985d4341314b2b4c6a23a0b4d8942f30fc85f 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
@@ -5,16 +5,27 @@
#include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h"
#include "base/command_line.h"
+#include "base/values.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.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/sync/profile_sync_service.h"
#include "chrome/common/chrome_notification_types.h"
+#include "content/common/notification_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/common/notification_details.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
NewTabSyncSetupHandler::NewTabSyncSetupHandler() : SyncSetupHandler() {
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
+ NotificationService::AllSources());
}
NewTabSyncSetupHandler::~NewTabSyncSetupHandler() {
@@ -46,6 +57,8 @@ void NewTabSyncSetupHandler::RegisterMessages() {
NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo));
web_ui_->RegisterMessageCallback("ExpandSyncPromo",
NewCallback(this, &NewTabSyncSetupHandler::HandleExpandSyncPromo));
+ web_ui_->RegisterMessageCallback("ShowProfilesMenu",
+ NewCallback(this, &NewTabSyncSetupHandler::HandleShowProfilesMenu));
SyncSetupHandler::RegisterMessages();
}
@@ -53,6 +66,11 @@ void NewTabSyncSetupHandler::RegisterMessages() {
void NewTabSyncSetupHandler::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
+ UpdateLogin();
+ return;
+ }
+
if (type == chrome::NOTIFICATION_PREF_CHANGED) {
std::string* name = Details<std::string>(details).ptr();
if (prefs::kGoogleServicesUsername == *name) {
@@ -102,12 +120,49 @@ void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) {
SaveExpandedPreference(true);
}
+void NewTabSyncSetupHandler::HandleShowProfilesMenu(const ListValue* args) {
+ // TODO(sail): Show the profiles menu.
+}
+
void NewTabSyncSetupHandler::UpdateLogin() {
std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString(
prefs::kGoogleServicesUsername);
- StringValue string_value(username);
+
+ string16 status_msg;
+ if (username.empty()) {
+ status_msg = l10n_util::GetStringUTF16(IDS_SYNC_STATUS_NOT_CONNECTED);
+ } else {
+ string16 short_product_name =
+ l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
+ status_msg = l10n_util::GetStringFUTF16(IDS_SYNC_STATUS_CONNECTED,
+ short_product_name,
+ UTF8ToUTF16(username));
+ }
+ StringValue status_msg_value(status_msg);
+
+ std::string icon_url;
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ if (cache.GetNumberOfProfiles() > 1) {
+ size_t index = cache.GetIndexOfProfileWithPath(
+ Profile::FromWebUI(web_ui_)->GetPath());
+ if (index != std::string::npos) {
+ size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
+ icon_url = ProfileInfoCache::GetDefaultAvatarIconUrl(icon_index);
+ }
+ }
+ StringValue icon_url_value(icon_url);
+
+ // If the user isn't signed in then make the login text clickable so that
+ // users can click on it to expand the sync promo. Otherwise, if the user
+ // has multiple profiles then clicking on it should show the profiles menu.
+ base::FundamentalValue is_clickable_value(
+ username.empty() || cache.GetNumberOfProfiles() > 1);
+
+ base::FundamentalValue is_signed_in_value(!username.empty());
web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin",
- string_value);
+ status_msg_value, icon_url_value,
+ is_signed_in_value, is_clickable_value);
}
void NewTabSyncSetupHandler::SaveExpandedPreference(bool is_expanded) {
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h ('k') | chrome/browser/ui/webui/sync_setup_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698