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

Side by Side Diff: chrome/browser/ui/webui/options/personal_options_handler.cc

Issue 7400032: Multi-profile WebUI settings (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Notify when deleting profile from cache Created 9 years, 5 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/options/personal_options_handler.h" 5 #include "chrome/browser/ui/webui/options/personal_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/stl_util-inl.h" 12 #include "base/stl_util-inl.h"
13 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/value_conversions.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_info_cache.h"
19 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/sync/profile_sync_service.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
21 #include "chrome/browser/sync/sync_setup_flow.h" 25 #include "chrome/browser/sync/sync_setup_flow.h"
22 #include "chrome/browser/sync/sync_ui_util.h" 26 #include "chrome/browser/sync/sync_ui_util.h"
23 #include "chrome/browser/themes/theme_service.h" 27 #include "chrome/browser/themes/theme_service.h"
24 #include "chrome/browser/themes/theme_service_factory.h" 28 #include "chrome/browser/themes/theme_service_factory.h"
25 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/net/gaia/google_service_auth_error.h" 32 #include "chrome/common/net/gaia/google_service_auth_error.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 75
72 76
73 localized_strings->SetString( 77 localized_strings->SetString(
74 "syncOverview", 78 "syncOverview",
75 l10n_util::GetStringFUTF16(IDS_SYNC_OVERVIEW, 79 l10n_util::GetStringFUTF16(IDS_SYNC_OVERVIEW,
76 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 80 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
77 localized_strings->SetString( 81 localized_strings->SetString(
78 "syncFurtherOverview", 82 "syncFurtherOverview",
79 l10n_util::GetStringUTF16(IDS_SYNC_FURTHER_OVERVIEW)); 83 l10n_util::GetStringUTF16(IDS_SYNC_FURTHER_OVERVIEW));
80 localized_strings->SetString("syncSection", 84 localized_strings->SetString("syncSection",
81 multiprofile_ ? 85 l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME));
82 l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME) :
83 l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME));
84 localized_strings->SetString("customizeSync", 86 localized_strings->SetString("customizeSync",
85 multiprofile_ ? 87 l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL));
86 l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_CUSTOMIZE_BUTTON_LABEL) : 88
87 l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL)); 89 localized_strings->SetString("profiles",
88 if (multiprofile_) { 90 l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME));
89 localized_strings->SetString("createNewProfile", 91 localized_strings->SetString("profilesCreate",
90 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_INFO)); 92 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_BUTTON_LABEL));
91 localized_strings->SetString("createProfileButton", 93 localized_strings->SetString("profilesManage",
92 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_BUTTON_LABEL)); 94 l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_BUTTON_LABEL));
93 } 95 localized_strings->SetString("profilesDelete",
96 l10n_util::GetStringUTF16(IDS_PROFILES_DELETE_BUTTON_LABEL));
97 localized_strings->SetString("profilesListItemCurrent",
98 l10n_util::GetStringUTF16(IDS_PROFILES_LIST_ITEM_CURRENT));
94 99
95 localized_strings->SetString("passwords", 100 localized_strings->SetString("passwords",
96 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME)); 101 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME));
97 localized_strings->SetString("passwordsAskToSave", 102 localized_strings->SetString("passwordsAskToSave",
98 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE)); 103 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE));
99 localized_strings->SetString("passwordsNeverSave", 104 localized_strings->SetString("passwordsNeverSave",
100 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE)); 105 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE));
101 localized_strings->SetString("manage_passwords", 106 localized_strings->SetString("manage_passwords",
102 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS)); 107 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS));
103 108
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 #if defined(TOOLKIT_GTK) 199 #if defined(TOOLKIT_GTK)
195 web_ui_->RegisterMessageCallback( 200 web_ui_->RegisterMessageCallback(
196 "themesSetGTK", 201 "themesSetGTK",
197 NewCallback(this, &PersonalOptionsHandler::ThemesSetGTK)); 202 NewCallback(this, &PersonalOptionsHandler::ThemesSetGTK));
198 #endif 203 #endif
199 #if defined(OS_CHROMEOS) 204 #if defined(OS_CHROMEOS)
200 web_ui_->RegisterMessageCallback( 205 web_ui_->RegisterMessageCallback(
201 "loadAccountPicture", 206 "loadAccountPicture",
202 NewCallback(this, &PersonalOptionsHandler::LoadAccountPicture)); 207 NewCallback(this, &PersonalOptionsHandler::LoadAccountPicture));
203 #endif 208 #endif
209 web_ui_->RegisterMessageCallback(
210 "profilesCreate",
211 NewCallback(this, &PersonalOptionsHandler::ProfilesCreate));
204 } 212 }
205 213
206 void PersonalOptionsHandler::Observe(int type, 214 void PersonalOptionsHandler::Observe(int type,
207 const NotificationSource& source, 215 const NotificationSource& source,
208 const NotificationDetails& details) { 216 const NotificationDetails& details) {
209 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { 217 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) {
210 ObserveThemeChanged(); 218 ObserveThemeChanged();
219 } else if (multiprofile_ &&
220 type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) {
221 SendProfilesInfo();
211 #if defined(OS_CHROMEOS) 222 #if defined(OS_CHROMEOS)
212 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { 223 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) {
213 LoadAccountPicture(NULL); 224 LoadAccountPicture(NULL);
214 #endif 225 #endif
215 } else { 226 } else {
216 OptionsPageUIHandler::Observe(type, source, details); 227 OptionsPageUIHandler::Observe(type, source, details);
217 } 228 }
218 } 229 }
219 230
220 void PersonalOptionsHandler::OnStateChanged() { 231 void PersonalOptionsHandler::OnStateChanged() {
(...skipping 18 matching lines...) Expand all
239 status_label.assign(l10n_util::GetStringFUTF16( 250 status_label.assign(l10n_util::GetStringFUTF16(
240 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, 251 IDS_SYNC_ACCOUNT_SYNCING_TO_USER,
241 user_name, 252 user_name,
242 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL))); 253 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL)));
243 } 254 }
244 255
245 string16 start_stop_button_label; 256 string16 start_stop_button_label;
246 bool is_start_stop_button_visible = false; 257 bool is_start_stop_button_visible = false;
247 bool is_start_stop_button_enabled = false; 258 bool is_start_stop_button_enabled = false;
248 if (sync_setup_completed) { 259 if (sync_setup_completed) {
249 start_stop_button_label = multiprofile_ ? 260 start_stop_button_label =
250 l10n_util::GetStringUTF16(IDS_PROFILES_DISCONNECT_BUTTON_LABEL) :
251 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); 261 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL);
252 #if defined(OS_CHROMEOS) 262 #if defined(OS_CHROMEOS)
253 is_start_stop_button_visible = false; 263 is_start_stop_button_visible = false;
254 #else 264 #else
255 is_start_stop_button_visible = true; 265 is_start_stop_button_visible = true;
256 #endif // defined(OS_CHROMEOS) 266 #endif // defined(OS_CHROMEOS)
257 is_start_stop_button_enabled = !managed; 267 is_start_stop_button_enabled = !managed;
258 } else if (service->SetupInProgress()) { 268 } else if (service->SetupInProgress()) {
259 start_stop_button_label = 269 start_stop_button_label =
260 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); 270 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS);
261 is_start_stop_button_visible = true; 271 is_start_stop_button_visible = true;
262 is_start_stop_button_enabled = false; 272 is_start_stop_button_enabled = false;
263 } else { 273 } else {
264 start_stop_button_label = 274 start_stop_button_label =
265 multiprofile_ ? 275 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL);
266 l10n_util::GetStringUTF16(IDS_PROFILES_CONNECT_BUTTON_LABEL) :
267 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL);
268 is_start_stop_button_visible = true; 276 is_start_stop_button_visible = true;
269 is_start_stop_button_enabled = !managed; 277 is_start_stop_button_enabled = !managed;
270 } 278 }
271 279
272 scoped_ptr<Value> completed(Value::CreateBooleanValue(sync_setup_completed)); 280 scoped_ptr<Value> completed(Value::CreateBooleanValue(sync_setup_completed));
273 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncSetupCompleted", 281 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncSetupCompleted",
274 *completed); 282 *completed);
275 283
276 scoped_ptr<Value> label(Value::CreateStringValue(status_label)); 284 scoped_ptr<Value> label(Value::CreateStringValue(status_label));
277 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatus", *label); 285 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatus", *label);
(...skipping 18 matching lines...) Expand all
296 304
297 enabled.reset(Value::CreateBooleanValue(!managed)); 305 enabled.reset(Value::CreateBooleanValue(!managed));
298 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncActionLinkEnabled", 306 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncActionLinkEnabled",
299 *enabled); 307 *enabled);
300 308
301 visible.reset(Value::CreateBooleanValue(status_has_error)); 309 visible.reset(Value::CreateBooleanValue(status_has_error));
302 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatusErrorVisible", 310 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatusErrorVisible",
303 *visible); 311 *visible);
304 312
305 // Set profile creation text and button if multi-profiles switch is on. 313 // Set profile creation text and button if multi-profiles switch is on.
314 visible.reset(Value::CreateBooleanValue(multiprofile_));
315 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible",
316 *visible);
306 if (multiprofile_) { 317 if (multiprofile_) {
307 visible.reset(Value::CreateBooleanValue(true)); 318 SendProfilesInfo();
308 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible",
309 *visible);
310
311 // TODO(mirandac): enable when back end is ready.
312 enabled.reset(Value::CreateBooleanValue(false));
313 web_ui_->CallJavascriptFunction(
314 "PersonalOptions.setNewProfileButtonEnabled", *enabled);
315 } else {
316 visible.reset(Value::CreateBooleanValue(false));
317 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible",
318 *visible);
319 } 319 }
320 } 320 }
321 321
322 void PersonalOptionsHandler::OnLoginSuccess() { 322 void PersonalOptionsHandler::OnLoginSuccess() {
323 OnStateChanged(); 323 OnStateChanged();
324 } 324 }
325 325
326 void PersonalOptionsHandler::OnLoginFailure( 326 void PersonalOptionsHandler::OnLoginFailure(
327 const GoogleServiceAuthError& error) { 327 const GoogleServiceAuthError& error) {
328 OnStateChanged(); 328 OnStateChanged();
(...skipping 15 matching lines...) Expand all
344 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); 344 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme();
345 FundamentalValue enabled(!is_classic_theme); 345 FundamentalValue enabled(!is_classic_theme);
346 web_ui_->CallJavascriptFunction( 346 web_ui_->CallJavascriptFunction(
347 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); 347 "options.PersonalOptions.setThemesResetButtonEnabled", enabled);
348 } 348 }
349 349
350 void PersonalOptionsHandler::Initialize() { 350 void PersonalOptionsHandler::Initialize() {
351 // Listen for theme installation. 351 // Listen for theme installation.
352 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 352 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
353 NotificationService::AllSources()); 353 NotificationService::AllSources());
354 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
355 NotificationService::AllSources());
354 ObserveThemeChanged(); 356 ObserveThemeChanged();
355 357
356 ProfileSyncService* sync_service = 358 ProfileSyncService* sync_service =
357 web_ui_->GetProfile()->GetProfileSyncService(); 359 web_ui_->GetProfile()->GetProfileSyncService();
358 if (sync_service) { 360 if (sync_service) {
359 sync_service->AddObserver(this); 361 sync_service->AddObserver(this);
360 OnStateChanged(); 362 OnStateChanged();
361 363
362 DictionaryValue args; 364 DictionaryValue args;
363 SyncSetupFlow::GetArgsForConfigure(sync_service, &args); 365 SyncSetupFlow::GetArgsForConfigure(sync_service, &args);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 timestamp)); 399 timestamp));
398 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture", 400 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture",
399 image_url); 401 image_url);
400 402
401 StringValue email_value(email); 403 StringValue email_value(email);
402 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", 404 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture",
403 email_value, image_url); 405 email_value, image_url);
404 } 406 }
405 } 407 }
406 #endif 408 #endif
409
410 void PersonalOptionsHandler::SendProfilesInfo() {
411 ProfileInfoCache& cache =
412 g_browser_process->profile_manager()->GetProfileInfoCache();
413 ListValue profile_info_list;
414 FilePath current_profile_path = web_ui_->GetProfile()->GetPath();
415 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) {
416 DictionaryValue *profile_value = new DictionaryValue();
417 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i);
418 FilePath profile_path = cache.GetPathOfProfileAtIndex(i);
419 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i));
420 profile_value->SetString("iconURL",
421 cache.GetDefaultAvatarIconUrl(icon_index));
422 profile_value->Set("filePath",
423 base::CreateFilePathValue(
424 profile_path));
425 profile_value->SetBoolean("isCurrentProfile",
426 profile_path == current_profile_path);
427 profile_info_list.Append(profile_value);
428 }
429
430 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo",
431 profile_info_list);
432 }
433
434 void PersonalOptionsHandler::ProfilesCreate(const ListValue* args) {
435 ProfileManager::CreateMultiProfileAsync();
436 }
437
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698