OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/metrics/histogram.h" | |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/value_conversions.h" | 21 #include "base/value_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
22 #include "chrome/browser/auto_launch_trial.h" | 23 #include "chrome/browser/auto_launch_trial.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/chrome_page_zoom.h" | 25 #include "chrome/browser/chrome_page_zoom.h" |
25 #include "chrome/browser/custom_home_pages_table_model.h" | 26 #include "chrome/browser/custom_home_pages_table_model.h" |
26 #include "chrome/browser/download/download_prefs.h" | 27 #include "chrome/browser/download/download_prefs.h" |
27 #include "chrome/browser/gpu/gpu_mode_manager.h" | 28 #include "chrome/browser/gpu/gpu_mode_manager.h" |
28 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
29 #include "chrome/browser/net/url_fixer_upper.h" | 30 #include "chrome/browser/net/url_fixer_upper.h" |
30 #include "chrome/browser/prefs/session_startup_pref.h" | 31 #include "chrome/browser/prefs/session_startup_pref.h" |
31 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 32 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
32 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" | 33 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" |
33 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 34 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
34 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 35 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
36 #include "chrome/browser/profiles/profile.h" | |
35 #include "chrome/browser/profiles/profile_info_cache.h" | 37 #include "chrome/browser/profiles/profile_info_cache.h" |
36 #include "chrome/browser/profiles/profile_info_util.h" | 38 #include "chrome/browser/profiles/profile_info_util.h" |
39 #include "chrome/browser/profiles/profile_metrics.h" | |
37 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 40 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
38 #include "chrome/browser/search/search.h" | 41 #include "chrome/browser/search/search.h" |
39 #include "chrome/browser/search_engines/template_url.h" | 42 #include "chrome/browser/search_engines/template_url.h" |
40 #include "chrome/browser/search_engines/template_url_service.h" | 43 #include "chrome/browser/search_engines/template_url_service.h" |
41 #include "chrome/browser/search_engines/template_url_service_factory.h" | 44 #include "chrome/browser/search_engines/template_url_service_factory.h" |
42 #include "chrome/browser/service/service_process_control.h" | 45 #include "chrome/browser/service/service_process_control.h" |
43 #include "chrome/browser/signin/signin_manager.h" | 46 #include "chrome/browser/signin/signin_manager.h" |
44 #include "chrome/browser/signin/signin_manager_factory.h" | 47 #include "chrome/browser/signin/signin_manager_factory.h" |
45 #include "chrome/browser/sync/profile_sync_service.h" | 48 #include "chrome/browser/sync/profile_sync_service.h" |
46 #include "chrome/browser/sync/profile_sync_service_factory.h" | 49 #include "chrome/browser/sync/profile_sync_service_factory.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 142 } |
140 | 143 |
141 void CreateDesktopShortcutForProfile(Profile* profile, | 144 void CreateDesktopShortcutForProfile(Profile* profile, |
142 Profile::CreateStatus status) { | 145 Profile::CreateStatus status) { |
143 ProfileShortcutManager* shortcut_manager = | 146 ProfileShortcutManager* shortcut_manager = |
144 g_browser_process->profile_manager()->profile_shortcut_manager(); | 147 g_browser_process->profile_manager()->profile_shortcut_manager(); |
145 if (shortcut_manager) | 148 if (shortcut_manager) |
146 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 149 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
147 } | 150 } |
148 | 151 |
152 void OnProfileCreatedCallCallbacks( | |
Bernhard Bauer
2013/06/03 10:52:47
Naming nit: Name this either based on what it does
| |
153 const std::vector<ProfileManager::CreateCallback>& callbacks, | |
154 Profile* profile, | |
155 Profile::CreateStatus status) { | |
156 std::vector<ProfileManager::CreateCallback>::const_iterator it; | |
157 for (it = callbacks.begin(); it != callbacks.end(); ++it) { | |
158 it->Run(profile, status); | |
159 } | |
160 } | |
161 | |
162 void OpenNewWindowForProfile( | |
163 chrome::HostDesktopType desktop_type, | |
164 Profile* profile, | |
165 Profile::CreateStatus status) { | |
166 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
Bernhard Bauer
2013/06/03 10:52:47
Early return on other status?
| |
167 ProfileManager::FindOrCreateNewWindowForProfile( | |
168 profile, | |
169 chrome::startup::IS_PROCESS_STARTUP, | |
170 chrome::startup::IS_FIRST_RUN, | |
171 desktop_type, | |
172 false); | |
173 } | |
174 } | |
175 | |
149 } // namespace | 176 } // namespace |
150 | 177 |
151 BrowserOptionsHandler::BrowserOptionsHandler() | 178 BrowserOptionsHandler::BrowserOptionsHandler() |
152 : page_initialized_(false), | 179 : page_initialized_(false), |
153 template_url_service_(NULL), | 180 template_url_service_(NULL), |
154 weak_ptr_factory_(this) { | 181 weak_ptr_factory_(this) { |
155 #if !defined(OS_MACOSX) | 182 #if !defined(OS_MACOSX) |
156 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); | 183 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); |
157 #endif | 184 #endif |
158 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) | 185 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 base::Unretained(this))); | 559 base::Unretained(this))); |
533 web_ui()->RegisterMessageCallback( | 560 web_ui()->RegisterMessageCallback( |
534 "setDefaultSearchEngine", | 561 "setDefaultSearchEngine", |
535 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, | 562 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, |
536 base::Unretained(this))); | 563 base::Unretained(this))); |
537 web_ui()->RegisterMessageCallback( | 564 web_ui()->RegisterMessageCallback( |
538 "createProfile", | 565 "createProfile", |
539 base::Bind(&BrowserOptionsHandler::CreateProfile, | 566 base::Bind(&BrowserOptionsHandler::CreateProfile, |
540 base::Unretained(this))); | 567 base::Unretained(this))); |
541 web_ui()->RegisterMessageCallback( | 568 web_ui()->RegisterMessageCallback( |
569 "deleteProfile", | |
570 base::Bind(&BrowserOptionsHandler::DeleteProfile, | |
571 base::Unretained(this))); | |
572 web_ui()->RegisterMessageCallback( | |
542 "themesReset", | 573 "themesReset", |
543 base::Bind(&BrowserOptionsHandler::ThemesReset, | 574 base::Bind(&BrowserOptionsHandler::ThemesReset, |
544 base::Unretained(this))); | 575 base::Unretained(this))); |
545 #if defined(TOOLKIT_GTK) | 576 #if defined(TOOLKIT_GTK) |
546 web_ui()->RegisterMessageCallback( | 577 web_ui()->RegisterMessageCallback( |
547 "themesSetGTK", | 578 "themesSetGTK", |
548 base::Bind(&BrowserOptionsHandler::ThemesSetGTK, | 579 base::Bind(&BrowserOptionsHandler::ThemesSetGTK, |
549 base::Unretained(this))); | 580 base::Unretained(this))); |
550 #endif | 581 #endif |
551 web_ui()->RegisterMessageCallback( | 582 web_ui()->RegisterMessageCallback( |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 return; | 1113 return; |
1083 | 1114 |
1084 Browser* browser = | 1115 Browser* browser = |
1085 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 1116 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
1086 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | 1117 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
1087 if (browser) | 1118 if (browser) |
1088 desktop_type = browser->host_desktop_type(); | 1119 desktop_type = browser->host_desktop_type(); |
1089 | 1120 |
1090 string16 name; | 1121 string16 name; |
1091 string16 icon; | 1122 string16 icon; |
1092 std::vector<ProfileManager::CreateCallback> callbacks; | |
1093 bool create_shortcut = false; | 1123 bool create_shortcut = false; |
1094 bool managed_user = false; | 1124 bool managed_user = false; |
1095 if (args->GetString(0, &name) && args->GetString(1, &icon)) { | 1125 if (args->GetString(0, &name) && args->GetString(1, &icon)) { |
1096 if (args->GetBoolean(2, &create_shortcut)) { | 1126 if (args->GetBoolean(2, &create_shortcut)) { |
1097 bool success = args->GetBoolean(3, &managed_user); | 1127 bool success = args->GetBoolean(3, &managed_user); |
1098 DCHECK(success); | 1128 DCHECK(success); |
1099 } | 1129 } |
1100 } | 1130 } |
1101 | 1131 |
1132 std::vector<ProfileManager::CreateCallback> callbacks; | |
1102 if (create_shortcut) | 1133 if (create_shortcut) |
1103 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile)); | 1134 callbacks.push_back(base::Bind(&CreateDesktopShortcutForProfile)); |
1104 | 1135 |
1136 ProfileManager::CreateCallback show_user_feedback = | |
1137 base::Bind(&BrowserOptionsHandler::OnProfileCreatedShowUserFeedback, | |
1138 weak_ptr_factory_.GetWeakPtr(), desktop_type, managed_user); | |
1139 | |
1105 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) { | 1140 if (managed_user && ManagedUserService::AreManagedUsersEnabled()) { |
1106 #if defined(ENABLE_MANAGED_USERS) | 1141 #if defined(ENABLE_MANAGED_USERS) |
1107 ManagedUserRegistrationService* registration_service = | 1142 ManagedUserRegistrationService* registration_service = |
1108 ManagedUserRegistrationServiceFactory::GetForProfile(profile); | 1143 ManagedUserRegistrationServiceFactory::GetForProfile(profile); |
1109 callbacks.push_back(registration_service->GetRegistrationAndInitCallback()); | 1144 callbacks.push_back(registration_service->GetRegistrationAndInitCallback( |
1145 show_user_feedback)); | |
1110 #else | 1146 #else |
1111 NOTREACHED(); | 1147 NOTREACHED(); |
1112 #endif | 1148 #endif |
1149 } else { | |
1150 callbacks.push_back(show_user_feedback); | |
1113 } | 1151 } |
1114 | 1152 |
1153 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | |
1154 | |
1115 ProfileManager::CreateMultiProfileAsync( | 1155 ProfileManager::CreateMultiProfileAsync( |
1116 name, icon, base::Bind(&BrowserOptionsHandler::OnProfileCreated, | 1156 name, icon, base::Bind(&OnProfileCreatedCallCallbacks, callbacks), |
1117 weak_ptr_factory_.GetWeakPtr(), | |
1118 desktop_type, managed_user, callbacks), | |
1119 managed_user); | 1157 managed_user); |
1120 } | 1158 } |
1121 | 1159 |
1122 void BrowserOptionsHandler::OnProfileCreated( | 1160 void BrowserOptionsHandler::OnProfileCreatedShowUserFeedback( |
1123 chrome::HostDesktopType desktop_type, | 1161 chrome::HostDesktopType desktop_type, |
1124 bool is_managed, | 1162 bool is_managed, |
1125 const std::vector<ProfileManager::CreateCallback>& callbacks, | |
1126 Profile* profile, | 1163 Profile* profile, |
1127 Profile::CreateStatus status) { | 1164 Profile::CreateStatus status) { |
1128 std::vector<ProfileManager::CreateCallback>::const_iterator it; | 1165 if (status != Profile::CREATE_STATUS_CREATED) { |
1129 for (it = callbacks.begin(); it != callbacks.end(); ++it) { | 1166 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", |
1130 it->Run(profile, status); | 1167 status, |
1168 Profile::MAX_CREATE_STATUS); | |
1131 } | 1169 } |
1132 | 1170 |
1133 switch (status) { | 1171 switch (status) { |
1134 case Profile::CREATE_STATUS_FAIL: { | 1172 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
1135 web_ui()->CallJavascriptFunction( | 1173 web_ui()->CallJavascriptFunction( |
1136 "BrowserOptions.showCreateProfileLocalError"); | 1174 "BrowserOptions.showCreateProfileLocalError"); |
1175 DeleteProfileAtPath(profile->GetPath()); | |
1176 break; | |
1177 } | |
1178 case Profile::CREATE_STATUS_REMOTE_FAIL: { | |
1179 web_ui()->CallJavascriptFunction( | |
1180 "BrowserOptions.showCreateProfileRemoteError"); | |
1181 DeleteProfileAtPath(profile->GetPath()); | |
1137 break; | 1182 break; |
1138 } | 1183 } |
1139 case Profile::CREATE_STATUS_CREATED: { | 1184 case Profile::CREATE_STATUS_CREATED: { |
1140 // Do nothing for an intermediate status. | 1185 // Do nothing for an intermediate status. |
1141 break; | 1186 break; |
1142 } | 1187 } |
1143 case Profile::CREATE_STATUS_INITIALIZED: { | 1188 case Profile::CREATE_STATUS_INITIALIZED: { |
1144 DictionaryValue dict; | 1189 DictionaryValue dict; |
1145 dict.SetString("name", | 1190 dict.SetString("name", |
1146 profile->GetPrefs()->GetString(prefs::kProfileName)); | 1191 profile->GetPrefs()->GetString(prefs::kProfileName)); |
1147 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); | 1192 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
1148 dict.SetBoolean("isManaged", is_managed); | 1193 dict.SetBoolean("isManaged", is_managed); |
1149 web_ui()->CallJavascriptFunction( | 1194 web_ui()->CallJavascriptFunction( |
1150 "BrowserOptions.showCreateProfileSuccess", dict); | 1195 "BrowserOptions.showCreateProfileSuccess", dict); |
1151 | 1196 |
1152 // If the new profile is a managed user, instead of opening a new window | 1197 // If the new profile is a managed user, instead of opening a new window |
1153 // right away, a confirmation overlay will be shown from the creation | 1198 // right away, a confirmation overlay will be shown from the creation |
1154 // dialog. | 1199 // dialog. |
1155 if (!is_managed) { | 1200 if (!is_managed) { |
1156 // Opening the new window must be the last action, after all callbacks | 1201 // Opening the new window must be the last action, after all callbacks |
1157 // have been run, to give them a chance to initialize the profile. | 1202 // have been run, to give them a chance to initialize the profile. |
1158 ProfileManager::FindOrCreateNewWindowForProfile( | 1203 OpenNewWindowForProfile(desktop_type, |
1159 profile, | 1204 profile, |
1160 chrome::startup::IS_PROCESS_STARTUP, | 1205 Profile::CREATE_STATUS_INITIALIZED); |
1161 chrome::startup::IS_FIRST_RUN, | |
1162 desktop_type, | |
1163 false); | |
1164 } | 1206 } |
1165 break; | 1207 break; |
1166 } | 1208 } |
1209 case Profile::MAX_CREATE_STATUS: { | |
1210 NOTREACHED(); | |
1211 break; | |
1212 } | |
1167 } | 1213 } |
1168 } | 1214 } |
1169 | 1215 |
1216 void BrowserOptionsHandler::DeleteProfile(const ListValue* args) { | |
Bernhard Bauer
2013/06/03 10:52:47
Is there a chance we could keep this in ManageProf
Pam (message me for reviews)
2013/06/03 13:39:28
There's quite a bit in BrowserOptionsHandler that
Bernhard Bauer
2013/06/03 14:25:01
Hm. TBH, I'd rather have profile creation and dele
Pam (message me for reviews)
2013/06/03 14:27:11
Yeah, so would I, but I didn't want to get involve
| |
1217 DCHECK(args); | |
1218 const Value* file_path_value; | |
1219 if (!args->Get(0, &file_path_value)) | |
1220 return; | |
1221 | |
1222 base::FilePath file_path; | |
1223 if (!base::GetValueAsFilePath(*file_path_value, &file_path)) | |
1224 return; | |
1225 DeleteProfileAtPath(file_path); | |
1226 } | |
1227 | |
1228 void BrowserOptionsHandler::DeleteProfileAtPath(base::FilePath file_path) { | |
1229 #if defined(ENABLE_MANAGED_USERS) | |
1230 // This handler could have been called in managed mode, for example because | |
1231 // the user fiddled with the web inspector. Silently return in this case. | |
1232 ManagedUserService* service = | |
1233 ManagedUserServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | |
1234 if (service->ProfileIsManaged()) | |
Bernhard Bauer
2013/06/03 10:52:47
Use the static version? That prevents us from crea
Pam (message me for reviews)
2013/06/03 13:39:28
Changed throughout.
| |
1235 return; | |
1236 #endif | |
1237 | |
1238 if (!ProfileManager::IsMultipleProfilesEnabled()) | |
1239 return; | |
1240 | |
1241 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | |
1242 | |
1243 Browser* browser = | |
1244 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | |
1245 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | |
1246 if (browser) | |
1247 desktop_type = browser->host_desktop_type(); | |
1248 | |
1249 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | |
1250 file_path, | |
1251 base::Bind(&OpenNewWindowForProfile, desktop_type)); | |
1252 } | |
1253 | |
1170 void BrowserOptionsHandler::ObserveThemeChanged() { | 1254 void BrowserOptionsHandler::ObserveThemeChanged() { |
1171 Profile* profile = Profile::FromWebUI(web_ui()); | 1255 Profile* profile = Profile::FromWebUI(web_ui()); |
1172 #if defined(TOOLKIT_GTK) | 1256 #if defined(TOOLKIT_GTK) |
1173 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); | 1257 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); |
1174 bool is_gtk_theme = theme_service->UsingNativeTheme(); | 1258 bool is_gtk_theme = theme_service->UsingNativeTheme(); |
1175 base::FundamentalValue gtk_enabled(!is_gtk_theme); | 1259 base::FundamentalValue gtk_enabled(!is_gtk_theme); |
1176 web_ui()->CallJavascriptFunction("BrowserOptions.setGtkThemeButtonEnabled", | 1260 web_ui()->CallJavascriptFunction("BrowserOptions.setGtkThemeButtonEnabled", |
1177 gtk_enabled); | 1261 gtk_enabled); |
1178 #else | 1262 #else |
1179 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | 1263 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1615 base::FundamentalValue disabled(profile_pref_registrar_.IsManaged() || | 1699 base::FundamentalValue disabled(profile_pref_registrar_.IsManaged() || |
1616 is_extension_controlled); | 1700 is_extension_controlled); |
1617 base::FundamentalValue extension_controlled(is_extension_controlled); | 1701 base::FundamentalValue extension_controlled(is_extension_controlled); |
1618 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", | 1702 web_ui()->CallJavascriptFunction("BrowserOptions.setupProxySettingsSection", |
1619 disabled, extension_controlled); | 1703 disabled, extension_controlled); |
1620 | 1704 |
1621 #endif // !defined(OS_CHROMEOS) | 1705 #endif // !defined(OS_CHROMEOS) |
1622 } | 1706 } |
1623 | 1707 |
1624 } // namespace options | 1708 } // namespace options |
OLD | NEW |