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

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

Issue 2468723003: Move session service and supervised users to buildflags. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/create_profile_handler.h" 5 #include "chrome/browser/ui/webui/options/create_profile_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/value_conversions.h" 15 #include "base/value_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/profiles/profile_attributes_entry.h" 18 #include "chrome/browser/profiles/profile_attributes_entry.h"
19 #include "chrome/browser/profiles/profile_attributes_storage.h" 19 #include "chrome/browser/profiles/profile_attributes_storage.h"
20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
21 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/profiles/profile_metrics.h" 22 #include "chrome/browser/profiles/profile_metrics.h"
23 #include "chrome/browser/profiles/profiles_state.h" 23 #include "chrome/browser/profiles/profiles_state.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/webui/profile_helper.h" 25 #include "chrome/browser/ui/webui/profile_helper.h"
26 #include "chrome/common/features.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
28 #include "components/browser_sync/profile_sync_service.h" 29 #include "components/browser_sync/profile_sync_service.h"
29 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
30 #include "content/public/browser/web_ui.h" 31 #include "content/public/browser/web_ui.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 33
33 #if defined(ENABLE_SUPERVISED_USERS) 34 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
34 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h" 35 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h"
35 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" 36 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
36 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h" 37 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h"
37 #include "chrome/browser/supervised_user/supervised_user_service.h" 38 #include "chrome/browser/supervised_user/supervised_user_service.h"
38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 39 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
39 #endif 40 #endif
40 41
41 namespace options { 42 namespace options {
42 43
43 CreateProfileHandler::CreateProfileHandler() 44 CreateProfileHandler::CreateProfileHandler()
44 : profile_creation_type_(NO_CREATION_IN_PROGRESS), 45 : profile_creation_type_(NO_CREATION_IN_PROGRESS),
45 weak_ptr_factory_(this) { 46 weak_ptr_factory_(this) {
46 } 47 }
47 48
48 CreateProfileHandler::~CreateProfileHandler() { 49 CreateProfileHandler::~CreateProfileHandler() {
49 #if defined(ENABLE_SUPERVISED_USERS) 50 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
50 // Cancellation is only supported for supervised users. 51 // Cancellation is only supported for supervised users.
51 CancelProfileRegistration(false); 52 CancelProfileRegistration(false);
52 #endif 53 #endif
53 } 54 }
54 55
55 void CreateProfileHandler::GetLocalizedValues( 56 void CreateProfileHandler::GetLocalizedValues(
56 base::DictionaryValue* localized_strings) { 57 base::DictionaryValue* localized_strings) {
57 } 58 }
58 59
59 void CreateProfileHandler::RegisterMessages() { 60 void CreateProfileHandler::RegisterMessages() {
60 #if defined(ENABLE_SUPERVISED_USERS) 61 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
61 // Cancellation is only supported for supervised users. 62 // Cancellation is only supported for supervised users.
62 web_ui()->RegisterMessageCallback( 63 web_ui()->RegisterMessageCallback(
63 "cancelCreateProfile", 64 "cancelCreateProfile",
64 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, 65 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation,
65 base::Unretained(this))); 66 base::Unretained(this)));
66 #endif 67 #endif
67 web_ui()->RegisterMessageCallback( 68 web_ui()->RegisterMessageCallback(
68 "createProfile", 69 "createProfile",
69 base::Bind(&CreateProfileHandler::CreateProfile, 70 base::Bind(&CreateProfileHandler::CreateProfile,
70 base::Unretained(this))); 71 base::Unretained(this)));
71 } 72 }
72 73
73 void CreateProfileHandler::CreateProfile(const base::ListValue* args) { 74 void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
74 #if defined(ENABLE_SUPERVISED_USERS) 75 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
75 // This handler could have been called for a supervised user, for example 76 // This handler could have been called for a supervised user, for example
76 // because the user fiddled with the web inspector. Silently return. 77 // because the user fiddled with the web inspector. Silently return.
77 if (Profile::FromWebUI(web_ui())->IsSupervised()) 78 if (Profile::FromWebUI(web_ui())->IsSupervised())
78 return; 79 return;
79 #endif 80 #endif
80 81
81 if (!profiles::IsMultipleProfilesEnabled()) 82 if (!profiles::IsMultipleProfilesEnabled())
82 return; 83 return;
83 84
84 // We can have only one in progress profile creation 85 // We can have only one in progress profile creation
(...skipping 14 matching lines...) Expand all
99 DCHECK(base::IsStringASCII(icon_url)); 100 DCHECK(base::IsStringASCII(icon_url));
100 base::TrimWhitespace(name, base::TRIM_ALL, &name); 101 base::TrimWhitespace(name, base::TRIM_ALL, &name);
101 CHECK(!name.empty()); 102 CHECK(!name.empty());
102 #ifndef NDEBUG 103 #ifndef NDEBUG
103 size_t icon_index; 104 size_t icon_index;
104 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); 105 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index));
105 #endif 106 #endif
106 args->GetBoolean(2, &create_shortcut); 107 args->GetBoolean(2, &create_shortcut);
107 } 108 }
108 std::string supervised_user_id; 109 std::string supervised_user_id;
109 #if defined(ENABLE_SUPERVISED_USERS) 110 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
110 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) 111 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id))
111 return; 112 return;
112 #endif 113 #endif
113 114
114 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); 115 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG);
115 116
116 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( 117 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync(
117 name, icon_url, base::Bind(&CreateProfileHandler::OnProfileCreated, 118 name, icon_url, base::Bind(&CreateProfileHandler::OnProfileCreated,
118 weak_ptr_factory_.GetWeakPtr(), 119 weak_ptr_factory_.GetWeakPtr(),
119 create_shortcut, supervised_user_id), 120 create_shortcut, supervised_user_id),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void CreateProfileHandler::HandleProfileCreationSuccess( 159 void CreateProfileHandler::HandleProfileCreationSuccess(
159 bool create_shortcut, 160 bool create_shortcut,
160 const std::string& supervised_user_id, 161 const std::string& supervised_user_id,
161 Profile* profile) { 162 Profile* profile) {
162 switch (profile_creation_type_) { 163 switch (profile_creation_type_) {
163 case NON_SUPERVISED_PROFILE_CREATION: { 164 case NON_SUPERVISED_PROFILE_CREATION: {
164 DCHECK(supervised_user_id.empty()); 165 DCHECK(supervised_user_id.empty());
165 CreateShortcutAndShowSuccess(create_shortcut, profile); 166 CreateShortcutAndShowSuccess(create_shortcut, profile);
166 break; 167 break;
167 } 168 }
168 #if defined(ENABLE_SUPERVISED_USERS) 169 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
169 case SUPERVISED_PROFILE_CREATION: 170 case SUPERVISED_PROFILE_CREATION:
170 case SUPERVISED_PROFILE_IMPORT: 171 case SUPERVISED_PROFILE_IMPORT:
171 RegisterSupervisedUser(create_shortcut, supervised_user_id, profile); 172 RegisterSupervisedUser(create_shortcut, supervised_user_id, profile);
172 break; 173 break;
173 #endif 174 #endif
174 case NO_CREATION_IN_PROGRESS: 175 case NO_CREATION_IN_PROGRESS:
175 NOTREACHED(); 176 NOTREACHED();
176 break; 177 break;
177 } 178 }
178 } 179 }
179 180
180 void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, 181 void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut,
181 Profile* profile) { 182 Profile* profile) {
182 if (create_shortcut) { 183 if (create_shortcut) {
183 ProfileShortcutManager* shortcut_manager = 184 ProfileShortcutManager* shortcut_manager =
184 g_browser_process->profile_manager()->profile_shortcut_manager(); 185 g_browser_process->profile_manager()->profile_shortcut_manager();
185 186
186 if (shortcut_manager) 187 if (shortcut_manager)
187 shortcut_manager->CreateProfileShortcut(profile->GetPath()); 188 shortcut_manager->CreateProfileShortcut(profile->GetPath());
188 } 189 }
189 190
190 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); 191 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value());
191 profile_path_being_created_.clear(); 192 profile_path_being_created_.clear();
192 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 193 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
193 base::DictionaryValue dict; 194 base::DictionaryValue dict;
194 dict.SetString("name", 195 dict.SetString("name",
195 profile->GetPrefs()->GetString(prefs::kProfileName)); 196 profile->GetPrefs()->GetString(prefs::kProfileName));
196 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); 197 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath()));
197 #if defined(ENABLE_SUPERVISED_USERS) 198 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
198 bool is_supervised = 199 bool is_supervised =
199 profile_creation_type_ == SUPERVISED_PROFILE_CREATION || 200 profile_creation_type_ == SUPERVISED_PROFILE_CREATION ||
200 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; 201 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT;
201 dict.SetBoolean("isSupervised", is_supervised); 202 dict.SetBoolean("isSupervised", is_supervised);
202 #endif 203 #endif
203 web_ui()->CallJavascriptFunctionUnsafe( 204 web_ui()->CallJavascriptFunctionUnsafe(
204 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); 205 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict);
205 206
206 // If the new profile is a supervised user, instead of opening a new window 207 // If the new profile is a supervised user, instead of opening a new window
207 // right away, a confirmation overlay will be shown by JS from the creation 208 // right away, a confirmation overlay will be shown by JS from the creation
208 // dialog. If we are importing an existing supervised profile or creating a 209 // dialog. If we are importing an existing supervised profile or creating a
209 // new non-supervised user profile we don't show any confirmation, so open 210 // new non-supervised user profile we don't show any confirmation, so open
210 // the new window now. 211 // the new window now.
211 bool should_open_new_window = true; 212 bool should_open_new_window = true;
212 #if defined(ENABLE_SUPERVISED_USERS) 213 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
213 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) 214 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION)
214 should_open_new_window = false; 215 should_open_new_window = false;
215 #endif 216 #endif
216 217
217 if (should_open_new_window) { 218 if (should_open_new_window) {
218 // Opening the new window must be the last action, after all callbacks 219 // Opening the new window must be the last action, after all callbacks
219 // have been run, to give them a chance to initialize the profile. 220 // have been run, to give them a chance to initialize the profile.
220 webui::OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED); 221 webui::OpenNewWindowForProfile(profile, Profile::CREATE_STATUS_INITIALIZED);
221 } 222 }
222 profile_creation_type_ = NO_CREATION_IN_PROGRESS; 223 profile_creation_type_ = NO_CREATION_IN_PROGRESS;
(...skipping 22 matching lines...) Expand all
245 status, 246 status,
246 Profile::MAX_CREATE_STATUS); 247 Profile::MAX_CREATE_STATUS);
247 UMA_HISTOGRAM_MEDIUM_TIMES( 248 UMA_HISTOGRAM_MEDIUM_TIMES(
248 "Profile.CreateTimeNoTimeout", 249 "Profile.CreateTimeNoTimeout",
249 base::TimeTicks::Now() - profile_creation_start_time_); 250 base::TimeTicks::Now() - profile_creation_start_time_);
250 } 251 }
251 252
252 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal() 253 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal()
253 const { 254 const {
254 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; 255 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR;
255 #if defined(ENABLE_SUPERVISED_USERS) 256 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
256 // Local errors can occur during supervised profile import. 257 // Local errors can occur during supervised profile import.
257 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) 258 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT)
258 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; 259 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR;
259 #endif 260 #endif
260 return l10n_util::GetStringUTF16(message_id); 261 return l10n_util::GetStringUTF16(message_id);
261 } 262 }
262 263
263 #if defined(ENABLE_SUPERVISED_USERS) 264 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
264 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote() 265 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote()
265 const { 266 const {
266 return l10n_util::GetStringUTF16( 267 return l10n_util::GetStringUTF16(
267 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? 268 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
268 IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR : 269 IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR :
269 IDS_PROFILES_CREATE_REMOTE_ERROR); 270 IDS_PROFILES_CREATE_REMOTE_ERROR);
270 } 271 }
271 272
272 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin() 273 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin()
273 const { 274 const {
274 return l10n_util::GetStringUTF16( 275 return l10n_util::GetStringUTF16(
275 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? 276 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
276 IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR : 277 IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR :
277 IDS_PROFILES_CREATE_SIGN_IN_ERROR); 278 IDS_PROFILES_CREATE_SIGN_IN_ERROR);
278 } 279 }
279 #endif 280 #endif
280 281
281 std::string CreateProfileHandler::GetJavascriptMethodName( 282 std::string CreateProfileHandler::GetJavascriptMethodName(
282 ProfileCreationStatus status) const { 283 ProfileCreationStatus status) const {
283 switch (profile_creation_type_) { 284 switch (profile_creation_type_) {
284 #if defined(ENABLE_SUPERVISED_USERS) 285 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
285 case SUPERVISED_PROFILE_IMPORT: 286 case SUPERVISED_PROFILE_IMPORT:
286 switch (status) { 287 switch (status) {
287 case PROFILE_CREATION_SUCCESS: 288 case PROFILE_CREATION_SUCCESS:
288 return "BrowserOptions.showSupervisedUserImportSuccess"; 289 return "BrowserOptions.showSupervisedUserImportSuccess";
289 case PROFILE_CREATION_ERROR: 290 case PROFILE_CREATION_ERROR:
290 return "BrowserOptions.showSupervisedUserImportError"; 291 return "BrowserOptions.showSupervisedUserImportError";
291 } 292 }
292 break; 293 break;
293 #endif 294 #endif
294 default: 295 default:
295 switch (status) { 296 switch (status) {
296 case PROFILE_CREATION_SUCCESS: 297 case PROFILE_CREATION_SUCCESS:
297 return "BrowserOptions.showCreateProfileSuccess"; 298 return "BrowserOptions.showCreateProfileSuccess";
298 case PROFILE_CREATION_ERROR: 299 case PROFILE_CREATION_ERROR:
299 return "BrowserOptions.showCreateProfileError"; 300 return "BrowserOptions.showCreateProfileError";
300 } 301 }
301 break; 302 break;
302 } 303 }
303 304
304 NOTREACHED(); 305 NOTREACHED();
305 return std::string(); 306 return std::string();
306 } 307 }
307 308
308 #if defined(ENABLE_SUPERVISED_USERS) 309 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
309 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( 310 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs(
310 const base::ListValue* args, std::string* supervised_user_id) { 311 const base::ListValue* args, std::string* supervised_user_id) {
311 bool supervised_user = false; 312 bool supervised_user = false;
312 if (args->GetSize() >= 5) { 313 if (args->GetSize() >= 5) {
313 bool success = args->GetBoolean(3, &supervised_user); 314 bool success = args->GetBoolean(3, &supervised_user);
314 DCHECK(success); 315 DCHECK(success);
315 316
316 success = args->GetString(4, supervised_user_id); 317 success = args->GetString(4, supervised_user_id);
317 DCHECK(success); 318 DCHECK(success);
318 } 319 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 GetProfileAttributesStorage().GetAllProfilesAttributes(); 475 GetProfileAttributesStorage().GetAllProfilesAttributes();
475 for (const ProfileAttributesEntry* entry : entries) { 476 for (const ProfileAttributesEntry* entry : entries) {
476 if (existing_supervised_user_id == entry->GetSupervisedUserId()) 477 if (existing_supervised_user_id == entry->GetSupervisedUserId())
477 return false; 478 return false;
478 } 479 }
479 return true; 480 return true;
480 } 481 }
481 #endif 482 #endif
482 483
483 } // namespace options 484 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/create_profile_handler.h ('k') | chrome/browser/ui/webui/options/options_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698