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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/values.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/prefs/pref_notifier.h" 11 #include "chrome/browser/prefs/pref_notifier.h"
9 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "content/common/notification_service.h"
13 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
15 #include "content/common/notification_details.h" 21 #include "content/common/notification_details.h"
22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
16 25
17 NewTabSyncSetupHandler::NewTabSyncSetupHandler() : SyncSetupHandler() { 26 NewTabSyncSetupHandler::NewTabSyncSetupHandler() : SyncSetupHandler() {
27 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
28 NotificationService::AllSources());
18 } 29 }
19 30
20 NewTabSyncSetupHandler::~NewTabSyncSetupHandler() { 31 NewTabSyncSetupHandler::~NewTabSyncSetupHandler() {
21 } 32 }
22 33
23 bool NewTabSyncSetupHandler::ShouldShowSyncPromo() { 34 bool NewTabSyncSetupHandler::ShouldShowSyncPromo() {
24 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
25 // There's no need to show the sync promo on cros since cros users are logged 36 // There's no need to show the sync promo on cros since cros users are logged
26 // into sync already. 37 // into sync already.
27 return false; 38 return false;
(...skipping 11 matching lines...) Expand all
39 return SyncSetupHandler::Attach(web_ui); 50 return SyncSetupHandler::Attach(web_ui);
40 } 51 }
41 52
42 void NewTabSyncSetupHandler::RegisterMessages() { 53 void NewTabSyncSetupHandler::RegisterMessages() {
43 web_ui_->RegisterMessageCallback("InitializeSyncPromo", 54 web_ui_->RegisterMessageCallback("InitializeSyncPromo",
44 NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo)); 55 NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo));
45 web_ui_->RegisterMessageCallback("CollapseSyncPromo", 56 web_ui_->RegisterMessageCallback("CollapseSyncPromo",
46 NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo)); 57 NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo));
47 web_ui_->RegisterMessageCallback("ExpandSyncPromo", 58 web_ui_->RegisterMessageCallback("ExpandSyncPromo",
48 NewCallback(this, &NewTabSyncSetupHandler::HandleExpandSyncPromo)); 59 NewCallback(this, &NewTabSyncSetupHandler::HandleExpandSyncPromo));
60 web_ui_->RegisterMessageCallback("ShowProfilesMenu",
61 NewCallback(this, &NewTabSyncSetupHandler::HandleShowProfilesMenu));
49 62
50 SyncSetupHandler::RegisterMessages(); 63 SyncSetupHandler::RegisterMessages();
51 } 64 }
52 65
53 void NewTabSyncSetupHandler::Observe(int type, 66 void NewTabSyncSetupHandler::Observe(int type,
54 const NotificationSource& source, 67 const NotificationSource& source,
55 const NotificationDetails& details) { 68 const NotificationDetails& details) {
69 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
70 UpdateLogin();
71 return;
72 }
73
56 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 74 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
57 std::string* name = Details<std::string>(details).ptr(); 75 std::string* name = Details<std::string>(details).ptr();
58 if (prefs::kGoogleServicesUsername == *name) { 76 if (prefs::kGoogleServicesUsername == *name) {
59 UpdateLogin(); 77 UpdateLogin();
60 return; 78 return;
61 } 79 }
62 } 80 }
63 SyncSetupHandler::Observe(type, source, details); 81 SyncSetupHandler::Observe(type, source, details);
64 } 82 }
65 83
(...skipping 29 matching lines...) Expand all
95 CloseSyncSetup(); 113 CloseSyncSetup();
96 SaveExpandedPreference(false); 114 SaveExpandedPreference(false);
97 } 115 }
98 116
99 117
100 void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) { 118 void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) {
101 OpenSyncSetup(); 119 OpenSyncSetup();
102 SaveExpandedPreference(true); 120 SaveExpandedPreference(true);
103 } 121 }
104 122
123 void NewTabSyncSetupHandler::HandleShowProfilesMenu(const ListValue* args) {
124 // TODO(sail): Show the profiles menu.
125 }
126
105 void NewTabSyncSetupHandler::UpdateLogin() { 127 void NewTabSyncSetupHandler::UpdateLogin() {
106 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( 128 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString(
107 prefs::kGoogleServicesUsername); 129 prefs::kGoogleServicesUsername);
108 StringValue string_value(username); 130
131 string16 status_msg;
132 if (username.empty()) {
133 status_msg = l10n_util::GetStringUTF16(IDS_SYNC_STATUS_NOT_CONNECTED);
134 } else {
135 string16 short_product_name =
136 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
137 status_msg = l10n_util::GetStringFUTF16(IDS_SYNC_STATUS_CONNECTED,
138 short_product_name,
139 UTF8ToUTF16(username));
140 }
141 StringValue status_msg_value(status_msg);
142
143 std::string icon_url;
144 ProfileInfoCache& cache =
145 g_browser_process->profile_manager()->GetProfileInfoCache();
146 if (cache.GetNumberOfProfiles() > 1) {
147 size_t index = cache.GetIndexOfProfileWithPath(
148 Profile::FromWebUI(web_ui_)->GetPath());
149 if (index != std::string::npos) {
150 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index);
151 icon_url = ProfileInfoCache::GetDefaultAvatarIconUrl(icon_index);
152 }
153 }
154 StringValue icon_url_value(icon_url);
155
156 // If the user isn't signed in then make the login text clickable so that
157 // users can click on it to expand the sync promo. Otherwise, if the user
158 // has multiple profiles then clicking on it should show the profiles menu.
159 base::FundamentalValue is_clickable_value(
160 username.empty() || cache.GetNumberOfProfiles() > 1);
161
162 base::FundamentalValue is_signed_in_value(!username.empty());
109 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin", 163 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin",
110 string_value); 164 status_msg_value, icon_url_value,
165 is_signed_in_value, is_clickable_value);
111 } 166 }
112 167
113 void NewTabSyncSetupHandler::SaveExpandedPreference(bool is_expanded) { 168 void NewTabSyncSetupHandler::SaveExpandedPreference(bool is_expanded) {
114 Profile* profile = Profile::FromWebUI(web_ui_); 169 Profile* profile = Profile::FromWebUI(web_ui_);
115 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoExpanded, is_expanded); 170 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoExpanded, is_expanded);
116 profile->GetPrefs()->ScheduleSavePersistentPrefs(); 171 profile->GetPrefs()->ScheduleSavePersistentPrefs();
117 } 172 }
OLDNEW
« 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