OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/signin/signin_create_profile_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 #include <string> |
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.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | |
16 #include "base/task_runner_util.h" | |
17 #include "base/threading/thread_restrictions.h" | |
15 #include "base/value_conversions.h" | 18 #include "base/value_conversions.h" |
16 #include "base/values.h" | 19 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
19 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/browser/profiles/profile_metrics.h" | 23 #include "chrome/browser/profiles/profile_metrics.h" |
23 #include "chrome/browser/profiles/profiles_state.h" | 24 #include "chrome/browser/profiles/profiles_state.h" |
25 #include "chrome/browser/signin/signin_manager_factory.h" | |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 27 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
26 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | |
27 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
28 #include "components/browser_sync/browser/profile_sync_service.h" | 31 #include "components/browser_sync/browser/profile_sync_service.h" |
29 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
33 #include "components/strings/grit/components_strings.h" | |
34 #include "content/public/browser/browser_thread.h" | |
30 #include "content/public/browser/web_ui.h" | 35 #include "content/public/browser/web_ui.h" |
31 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
32 | 37 |
33 #if defined(ENABLE_SUPERVISED_USERS) | 38 #if defined(ENABLE_SUPERVISED_USERS) |
34 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h" | 39 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h" |
35 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" | 40 #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" | 41 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h" |
37 #include "chrome/browser/supervised_user/supervised_user_service.h" | 42 #include "chrome/browser/supervised_user/supervised_user_service.h" |
38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 43 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
39 #endif | 44 #endif |
40 | 45 |
41 namespace options { | 46 SigninCreateProfileHandler::SigninCreateProfileHandler() |
47 : profile_creation_type_(NO_CREATION_IN_PROGRESS), | |
48 weak_ptr_factory_(this) {} | |
42 | 49 |
43 CreateProfileHandler::CreateProfileHandler() | 50 SigninCreateProfileHandler::~SigninCreateProfileHandler() { |
44 : profile_creation_type_(NO_CREATION_IN_PROGRESS), | |
45 weak_ptr_factory_(this) { | |
46 } | |
47 | |
48 CreateProfileHandler::~CreateProfileHandler() { | |
49 #if defined(ENABLE_SUPERVISED_USERS) | 51 #if defined(ENABLE_SUPERVISED_USERS) |
50 // Cancellation is only supported for supervised users. | 52 // Cancellation is only supported for supervised users. |
51 CancelProfileRegistration(false); | 53 CancelProfileRegistration(false); |
52 #endif | 54 #endif |
53 } | 55 } |
54 | 56 |
55 void CreateProfileHandler::GetLocalizedValues( | 57 void SigninCreateProfileHandler::GetLocalizedValues( |
56 base::DictionaryValue* localized_strings) { | 58 base::DictionaryValue* localized_strings) { |
59 localized_strings->SetString( | |
60 "manageProfilesSupervisedNotSignedIn", | |
61 l10n_util::GetStringUTF16( | |
62 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML)); | |
63 localized_strings->SetString("createProfileConfirm", | |
64 l10n_util::GetStringUTF16(IDS_SAVE)); | |
65 localized_strings->SetString("learnMore", | |
66 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | |
67 localized_strings->SetString( | |
68 "createProfileTitle", | |
69 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); | |
70 | |
71 localized_strings->SetString( | |
72 "supervisedUserLearnMoreTitle", | |
73 l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); | |
Dan Beam
2016/02/25 01:04:40
why are you adding another use of a _LEGACY_ strin
Moe
2016/02/25 16:03:02
I'm reusing the strings that haven't changed in th
| |
74 localized_strings->SetString( | |
75 "supervisedUserLearnMoreDone", | |
76 l10n_util::GetStringUTF16( | |
77 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); | |
78 localized_strings->SetString( | |
79 "supervisedUserLearnMoreText", | |
80 l10n_util::GetStringFUTF16( | |
81 IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, | |
82 base::ASCIIToUTF16( | |
83 chrome::kLegacySupervisedUserManagementDisplayURL))); | |
Dan Beam
2016/02/25 01:04:40
what does legacy mean here as well?
Moe
2016/02/25 16:03:03
This is another existing string. I don't know why
| |
57 } | 84 } |
58 | 85 |
59 void CreateProfileHandler::RegisterMessages() { | 86 void SigninCreateProfileHandler::RegisterMessages() { |
60 #if defined(ENABLE_SUPERVISED_USERS) | 87 #if defined(ENABLE_SUPERVISED_USERS) |
61 // Cancellation is only supported for supervised users. | 88 // Cancellation is only supported for supervised users. |
62 web_ui()->RegisterMessageCallback( | 89 web_ui()->RegisterMessageCallback( |
63 "cancelCreateProfile", | 90 "cancelCreateProfile", |
64 base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, | 91 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, |
65 base::Unretained(this))); | 92 base::Unretained(this))); |
66 #endif | 93 #endif |
67 web_ui()->RegisterMessageCallback( | 94 web_ui()->RegisterMessageCallback( |
68 "createProfile", | 95 "createProfile", base::Bind(&SigninCreateProfileHandler::CreateProfile, |
69 base::Bind(&CreateProfileHandler::CreateProfile, | 96 base::Unretained(this))); |
97 | |
98 web_ui()->RegisterMessageCallback( | |
99 "requestDefaultProfileIcons", | |
100 base::Bind(&SigninCreateProfileHandler::RequestDefaultProfileIcons, | |
101 base::Unretained(this))); | |
102 | |
103 web_ui()->RegisterMessageCallback( | |
104 "requestSignedInProfiles", | |
105 base::Bind(&SigninCreateProfileHandler::RequestSignedInProfiles, | |
70 base::Unretained(this))); | 106 base::Unretained(this))); |
71 } | 107 } |
72 | 108 |
73 void CreateProfileHandler::CreateProfile(const base::ListValue* args) { | 109 void SigninCreateProfileHandler::RequestDefaultProfileIcons( |
74 #if defined(ENABLE_SUPERVISED_USERS) | 110 const base::ListValue* args) { |
75 // This handler could have been called for a supervised user, for example | 111 base::ListValue image_url_list; |
76 // because the user fiddled with the web inspector. Silently return. | |
77 if (Profile::FromWebUI(web_ui())->IsSupervised()) | |
78 return; | |
79 #endif | |
80 | 112 |
113 // Add the default avatar icons. | |
114 size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); | |
115 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && | |
116 i != placeholder_avatar_index; | |
117 i++) { | |
118 std::string url = profiles::GetDefaultAvatarIconUrl(i); | |
119 image_url_list.AppendString(url); | |
120 } | |
121 | |
122 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateAvailableIcons", | |
123 image_url_list); | |
124 } | |
125 | |
126 void SigninCreateProfileHandler::RequestSignedInProfiles( | |
127 const base::ListValue* args) { | |
128 base::ListValue user_info_list; | |
129 ProfileInfoCache& cache = | |
130 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
131 std::vector<ProfileAttributesEntry*> entries = | |
132 cache.GetAllProfilesAttributes(); | |
133 for (auto& entry : entries) { | |
134 base::string16 username = entry->GetUserName(); | |
135 if (username.empty()) | |
136 continue; | |
137 base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); | |
138 base::DictionaryValue* user_info = new base::DictionaryValue(); | |
Dan Beam
2016/02/25 01:04:40
nit: can you use scoped_ptr<base::DictionaryValue>
Moe
2016/02/25 16:03:02
Done.
| |
139 user_info->SetString("username", username); | |
140 user_info->SetString("profilePath", profile_path); | |
141 | |
142 user_info_list.Append(user_info); | |
143 } | |
144 web_ui()->CallJavascriptFunction("signin.ProfileApi.updateSignedInUsers", | |
145 user_info_list); | |
146 } | |
147 | |
148 void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { | |
81 if (!profiles::IsMultipleProfilesEnabled()) | 149 if (!profiles::IsMultipleProfilesEnabled()) |
82 return; | 150 return; |
83 | 151 |
84 // We can have only one in progress profile creation | 152 // We can have only one in progress profile creation |
85 // at any given moment, if new ones are initiated just | 153 // at any given moment, if new ones are initiated just |
86 // ignore them until we are done with the old one. | 154 // ignore them until we are done with the old one. |
87 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) | 155 if (profile_creation_type_ != NO_CREATION_IN_PROGRESS) |
88 return; | 156 return; |
89 | 157 |
90 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; | 158 profile_creation_type_ = NON_SUPERVISED_PROFILE_CREATION; |
91 | 159 |
92 DCHECK(profile_path_being_created_.empty()); | 160 DCHECK(profile_path_being_created_.empty()); |
93 profile_creation_start_time_ = base::TimeTicks::Now(); | 161 profile_creation_start_time_ = base::TimeTicks::Now(); |
94 | 162 |
95 base::string16 name; | 163 base::string16 name; |
96 std::string icon_url; | 164 std::string icon_url; |
97 bool create_shortcut = false; | 165 bool create_shortcut = false; |
98 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) { | 166 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) { |
99 DCHECK(base::IsStringASCII(icon_url)); | 167 DCHECK(base::IsStringASCII(icon_url)); |
100 base::TrimWhitespace(name, base::TRIM_ALL, &name); | 168 base::TrimWhitespace(name, base::TRIM_ALL, &name); |
101 CHECK(!name.empty()); | 169 CHECK(!name.empty()); |
102 #ifndef NDEBUG | 170 #ifndef NDEBUG |
103 size_t icon_index; | 171 size_t icon_index; |
104 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); | 172 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); |
105 #endif | 173 #endif |
106 args->GetBoolean(2, &create_shortcut); | 174 args->GetBoolean(2, &create_shortcut); |
107 } | 175 } |
176 #if defined(ENABLE_SUPERVISED_USERS) | |
108 std::string supervised_user_id; | 177 std::string supervised_user_id; |
109 #if defined(ENABLE_SUPERVISED_USERS) | 178 base::FilePath supervisor_profile_path; |
110 if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) | 179 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, |
111 return; | 180 &supervisor_profile_path)) { |
181 // Load supervisor profile. | |
182 g_browser_process->profile_manager()->CreateProfileAsync( | |
183 supervisor_profile_path, | |
184 base::Bind(&SigninCreateProfileHandler::LoadSupervisorProfileCallback, | |
185 weak_ptr_factory_.GetWeakPtr(), name, icon_url, | |
186 create_shortcut, supervised_user_id), | |
187 base::string16(), std::string(), std::string()); | |
188 } else { | |
189 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); | |
190 } | |
191 #else | |
192 DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); | |
112 #endif | 193 #endif |
194 } | |
113 | 195 |
196 void SigninCreateProfileHandler::DoCreateProfile( | |
197 const base::string16& name, | |
198 const std::string& icon_url, | |
199 bool create_shortcut, | |
200 const std::string& supervised_user_id, | |
201 Profile* supervisor_profile) { | |
114 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); | 202 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
115 | 203 |
116 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( | 204 profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
117 name, icon_url, base::Bind(&CreateProfileHandler::OnProfileCreated, | 205 name, icon_url, |
118 weak_ptr_factory_.GetWeakPtr(), | 206 base::Bind(&SigninCreateProfileHandler::OnProfileCreated, |
119 create_shortcut, supervised_user_id), | 207 weak_ptr_factory_.GetWeakPtr(), create_shortcut, |
208 supervised_user_id, supervisor_profile), | |
120 supervised_user_id); | 209 supervised_user_id); |
121 } | 210 } |
122 | 211 |
123 void CreateProfileHandler::OnProfileCreated( | 212 void SigninCreateProfileHandler::OnProfileCreated( |
124 bool create_shortcut, | 213 bool create_shortcut, |
125 const std::string& supervised_user_id, | 214 const std::string& supervised_user_id, |
215 Profile* supervisor_profile, | |
126 Profile* profile, | 216 Profile* profile, |
127 Profile::CreateStatus status) { | 217 Profile::CreateStatus status) { |
128 if (status != Profile::CREATE_STATUS_CREATED) | 218 if (status != Profile::CREATE_STATUS_CREATED) |
129 RecordProfileCreationMetrics(status); | 219 RecordProfileCreationMetrics(status); |
130 | 220 |
131 switch (status) { | 221 switch (status) { |
132 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 222 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
133 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); | 223 ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal()); |
134 break; | 224 break; |
135 } | 225 } |
136 case Profile::CREATE_STATUS_CREATED: { | 226 case Profile::CREATE_STATUS_CREATED: { |
137 // Do nothing for an intermediate status. | 227 // Do nothing for an intermediate status. |
138 break; | 228 break; |
139 } | 229 } |
140 case Profile::CREATE_STATUS_INITIALIZED: { | 230 case Profile::CREATE_STATUS_INITIALIZED: { |
141 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, | 231 HandleProfileCreationSuccess(create_shortcut, supervised_user_id, |
142 profile); | 232 supervisor_profile, profile); |
143 break; | 233 break; |
144 } | 234 } |
145 // User-initiated cancellation is handled in CancelProfileRegistration and | 235 // User-initiated cancellation is handled in CancelProfileRegistration and |
146 // does not call this callback. | 236 // does not call this callback. |
147 case Profile::CREATE_STATUS_CANCELED: | 237 case Profile::CREATE_STATUS_CANCELED: |
148 // Supervised user registration errors are handled in | 238 // Supervised user registration errors are handled in |
149 // OnSupervisedUserRegistered(). | 239 // OnSupervisedUserRegistered(). |
150 case Profile::CREATE_STATUS_REMOTE_FAIL: | 240 case Profile::CREATE_STATUS_REMOTE_FAIL: |
151 case Profile::MAX_CREATE_STATUS: { | 241 case Profile::MAX_CREATE_STATUS: { |
152 NOTREACHED(); | 242 NOTREACHED(); |
153 break; | 243 break; |
154 } | 244 } |
155 } | 245 } |
156 } | 246 } |
157 | 247 |
158 void CreateProfileHandler::HandleProfileCreationSuccess( | 248 void SigninCreateProfileHandler::HandleProfileCreationSuccess( |
159 bool create_shortcut, | 249 bool create_shortcut, |
160 const std::string& supervised_user_id, | 250 const std::string& supervised_user_id, |
251 Profile* supervisor_profile, | |
161 Profile* profile) { | 252 Profile* profile) { |
162 switch (profile_creation_type_) { | 253 switch (profile_creation_type_) { |
163 case NON_SUPERVISED_PROFILE_CREATION: { | 254 case NON_SUPERVISED_PROFILE_CREATION: { |
164 DCHECK(supervised_user_id.empty()); | 255 DCHECK(supervised_user_id.empty()); |
165 CreateShortcutAndShowSuccess(create_shortcut, profile); | 256 CreateShortcutAndShowSuccess(create_shortcut, profile); |
166 break; | 257 break; |
167 } | 258 } |
168 #if defined(ENABLE_SUPERVISED_USERS) | 259 #if defined(ENABLE_SUPERVISED_USERS) |
169 case SUPERVISED_PROFILE_CREATION: | 260 case SUPERVISED_PROFILE_CREATION: |
170 case SUPERVISED_PROFILE_IMPORT: | 261 case SUPERVISED_PROFILE_IMPORT: |
171 RegisterSupervisedUser(create_shortcut, supervised_user_id, profile); | 262 RegisterSupervisedUser(create_shortcut, supervised_user_id, |
263 supervisor_profile, profile); | |
172 break; | 264 break; |
173 #endif | 265 #endif |
174 case NO_CREATION_IN_PROGRESS: | 266 case NO_CREATION_IN_PROGRESS: |
175 NOTREACHED(); | 267 NOTREACHED(); |
176 break; | 268 break; |
177 } | 269 } |
178 } | 270 } |
179 | 271 |
180 void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, | 272 void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( |
181 Profile* profile) { | 273 bool create_shortcut, |
274 Profile* profile) { | |
182 if (create_shortcut) { | 275 if (create_shortcut) { |
183 ProfileShortcutManager* shortcut_manager = | 276 ProfileShortcutManager* shortcut_manager = |
184 g_browser_process->profile_manager()->profile_shortcut_manager(); | 277 g_browser_process->profile_manager()->profile_shortcut_manager(); |
185 | 278 |
186 if (shortcut_manager) | 279 if (shortcut_manager) |
187 shortcut_manager->CreateProfileShortcut(profile->GetPath()); | 280 shortcut_manager->CreateProfileShortcut(profile->GetPath()); |
188 } | 281 } |
189 | 282 |
190 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); | 283 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); |
191 profile_path_being_created_.clear(); | 284 profile_path_being_created_.clear(); |
192 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 285 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
193 base::DictionaryValue dict; | 286 base::DictionaryValue dict; |
194 dict.SetString("name", | 287 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); |
195 profile->GetPrefs()->GetString(prefs::kProfileName)); | |
196 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); | 288 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
197 #if defined(ENABLE_SUPERVISED_USERS) | 289 #if defined(ENABLE_SUPERVISED_USERS) |
198 bool is_supervised = | 290 bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
199 profile_creation_type_ == SUPERVISED_PROFILE_CREATION || | 291 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
200 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; | |
201 dict.SetBoolean("isSupervised", is_supervised); | 292 dict.SetBoolean("isSupervised", is_supervised); |
202 #endif | 293 #endif |
203 web_ui()->CallJavascriptFunction( | 294 web_ui()->CallJavascriptFunction( |
204 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); | 295 GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict); |
205 | 296 |
206 // If the new profile is a supervised user, instead of opening a new window | 297 // 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 | 298 // 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 | 299 // 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 | 300 // new non-supervised user profile we don't show any confirmation, so open |
210 // the new window now. | 301 // the new window now. |
211 bool should_open_new_window = true; | 302 bool should_open_new_window = true; |
212 #if defined(ENABLE_SUPERVISED_USERS) | 303 #if defined(ENABLE_SUPERVISED_USERS) |
213 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) | 304 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) |
214 should_open_new_window = false; | 305 should_open_new_window = false; |
215 #endif | 306 #endif |
216 | 307 |
217 if (should_open_new_window) { | 308 if (should_open_new_window) { |
218 // Opening the new window must be the last action, after all callbacks | 309 // 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. | 310 // have been run, to give them a chance to initialize the profile. |
220 helper::OpenNewWindowForProfile(profile, | 311 options::helper::OpenNewWindowForProfile( |
Dan Beam
2016/02/25 01:04:40
can you move this code out of options? seems odd
Moe
2016/02/25 16:03:03
Done.
| |
221 Profile::CREATE_STATUS_INITIALIZED); | 312 profile, Profile::CREATE_STATUS_INITIALIZED); |
222 } | 313 } |
223 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 314 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
224 } | 315 } |
225 | 316 |
226 void CreateProfileHandler::ShowProfileCreationError( | 317 void SigninCreateProfileHandler::ShowProfileCreationError( |
227 Profile* profile, | 318 Profile* profile, |
228 const base::string16& error) { | 319 const base::string16& error) { |
229 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 320 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
230 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 321 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
231 profile_path_being_created_.clear(); | 322 profile_path_being_created_.clear(); |
232 web_ui()->CallJavascriptFunction( | 323 web_ui()->CallJavascriptFunction( |
233 GetJavascriptMethodName(PROFILE_CREATION_ERROR), | 324 GetJavascriptMethodName(PROFILE_CREATION_ERROR), |
234 base::StringValue(error)); | 325 base::StringValue(error)); |
235 // The ProfileManager calls us back with a NULL profile in some cases. | 326 // The ProfileManager calls us back with a NULL profile in some cases. |
236 if (profile) | 327 if (profile) |
237 helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); | 328 options::helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); |
238 } | 329 } |
239 | 330 |
240 void CreateProfileHandler::RecordProfileCreationMetrics( | 331 void SigninCreateProfileHandler::RecordProfileCreationMetrics( |
241 Profile::CreateStatus status) { | 332 Profile::CreateStatus status) { |
242 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", | 333 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, |
243 status, | |
244 Profile::MAX_CREATE_STATUS); | 334 Profile::MAX_CREATE_STATUS); |
245 UMA_HISTOGRAM_MEDIUM_TIMES( | 335 UMA_HISTOGRAM_MEDIUM_TIMES( |
246 "Profile.CreateTimeNoTimeout", | 336 "Profile.CreateTimeNoTimeout", |
247 base::TimeTicks::Now() - profile_creation_start_time_); | 337 base::TimeTicks::Now() - profile_creation_start_time_); |
248 } | 338 } |
249 | 339 |
250 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal() | 340 base::string16 SigninCreateProfileHandler::GetProfileCreationErrorMessageLocal() |
251 const { | 341 const { |
252 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; | 342 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; |
253 #if defined(ENABLE_SUPERVISED_USERS) | 343 #if defined(ENABLE_SUPERVISED_USERS) |
254 // Local errors can occur during supervised profile import. | 344 // Local errors can occur during supervised profile import. |
255 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) | 345 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) |
256 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; | 346 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; |
257 #endif | 347 #endif |
258 return l10n_util::GetStringUTF16(message_id); | 348 return l10n_util::GetStringUTF16(message_id); |
259 } | 349 } |
260 | 350 |
261 #if defined(ENABLE_SUPERVISED_USERS) | 351 #if defined(ENABLE_SUPERVISED_USERS) |
262 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote() | 352 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() |
263 const { | 353 const { |
264 return l10n_util::GetStringUTF16( | 354 return l10n_util::GetStringUTF16( |
265 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? | 355 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
266 IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR : | 356 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR |
267 IDS_PROFILES_CREATE_REMOTE_ERROR); | 357 : IDS_PROFILES_CREATE_REMOTE_ERROR); |
268 } | 358 } |
269 | 359 |
270 base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin() | 360 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin() |
271 const { | 361 const { |
272 return l10n_util::GetStringUTF16( | 362 return l10n_util::GetStringUTF16( |
273 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? | 363 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
274 IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR : | 364 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR |
275 IDS_PROFILES_CREATE_SIGN_IN_ERROR); | 365 : IDS_PROFILES_CREATE_SIGN_IN_ERROR); |
276 } | 366 } |
277 #endif | 367 #endif |
278 | 368 |
279 std::string CreateProfileHandler::GetJavascriptMethodName( | 369 std::string SigninCreateProfileHandler::GetJavascriptMethodName( |
280 ProfileCreationStatus status) const { | 370 ProfileCreationStatus status) const { |
281 switch (profile_creation_type_) { | 371 switch (profile_creation_type_) { |
282 #if defined(ENABLE_SUPERVISED_USERS) | 372 #if defined(ENABLE_SUPERVISED_USERS) |
283 case SUPERVISED_PROFILE_IMPORT: | 373 case SUPERVISED_PROFILE_IMPORT: |
284 switch (status) { | 374 switch (status) { |
285 case PROFILE_CREATION_SUCCESS: | 375 case PROFILE_CREATION_SUCCESS: |
286 return "BrowserOptions.showSupervisedUserImportSuccess"; | 376 return "BrowserOptions.showSupervisedUserImportSuccess"; |
287 case PROFILE_CREATION_ERROR: | 377 case PROFILE_CREATION_ERROR: |
288 return "BrowserOptions.showSupervisedUserImportError"; | 378 return "BrowserOptions.showSupervisedUserImportError"; |
289 } | 379 } |
290 break; | 380 break; |
291 #endif | 381 #endif |
292 default: | 382 default: |
293 switch (status) { | 383 switch (status) { |
294 case PROFILE_CREATION_SUCCESS: | 384 case PROFILE_CREATION_SUCCESS: |
295 return "BrowserOptions.showCreateProfileSuccess"; | 385 return "signin.ProfileApi.onCreateProfileSuccess"; |
296 case PROFILE_CREATION_ERROR: | 386 case PROFILE_CREATION_ERROR: |
297 return "BrowserOptions.showCreateProfileError"; | 387 return "signin.ProfileApi.onCreateProfileError"; |
298 } | 388 } |
299 break; | 389 break; |
300 } | 390 } |
301 | 391 |
302 NOTREACHED(); | 392 NOTREACHED(); |
303 return std::string(); | 393 return std::string(); |
304 } | 394 } |
305 | 395 |
306 #if defined(ENABLE_SUPERVISED_USERS) | 396 #if defined(ENABLE_SUPERVISED_USERS) |
307 bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( | 397 bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( |
308 const base::ListValue* args, std::string* supervised_user_id) { | 398 const base::ListValue* args, |
399 std::string* supervised_user_id, | |
400 base::FilePath* supervisor_profile_path) { | |
309 bool supervised_user = false; | 401 bool supervised_user = false; |
310 if (args->GetSize() >= 5) { | 402 bool success = args->GetBoolean(3, &supervised_user); |
311 bool success = args->GetBoolean(3, &supervised_user); | 403 DCHECK(success); |
312 DCHECK(success); | 404 success = args->GetString(4, supervised_user_id); |
Dan Beam
2016/02/25 01:04:40
should this GetString() for supervised_user_id be
Moe
2016/02/25 16:03:02
Acknowledged.
| |
405 DCHECK(success); | |
406 if (supervised_user) { | |
407 const base::Value* path_value; | |
408 success = args->Get(5, &path_value); | |
409 DCHECK(success); | |
410 success = base::GetValueAsFilePath(*path_value, supervisor_profile_path); | |
411 DCHECK(success); | |
412 } | |
413 return supervised_user && !supervisor_profile_path->empty(); | |
Dan Beam
2016/02/25 01:04:40
bool supervised_user = false;
bool success = args-
Moe
2016/02/25 16:03:02
Done.
| |
414 } | |
313 | 415 |
314 success = args->GetString(4, supervised_user_id); | 416 void SigninCreateProfileHandler::LoadSupervisorProfileCallback( |
315 DCHECK(success); | 417 const base::string16& name, |
418 const std::string& icon_url, | |
419 bool create_shortcut, | |
420 const std::string& supervised_user_id, | |
421 Profile* supervisor_profile, | |
422 Profile::CreateStatus status) { | |
423 // This method gets called once before with Profile::CREATE_STATUS_CREATED. | |
424 switch (status) { | |
425 case Profile::CREATE_STATUS_LOCAL_FAIL: { | |
426 // TODO(mahmadi): see if a better error message is required here. | |
427 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); | |
428 break; | |
429 } | |
430 case Profile::CREATE_STATUS_CREATED: { | |
431 // Ignore the intermediate status. | |
432 break; | |
433 } | |
434 case Profile::CREATE_STATUS_INITIALIZED: { | |
435 // We are only interested in Profile::CREATE_STATUS_INITIALIZED when | |
436 // everything is ready. | |
437 // TODO(mahmadi): display proper error message to the user. | |
438 PrefService* prefs = supervisor_profile->GetPrefs(); | |
439 if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) | |
440 return; | |
441 | |
442 if (!supervised_user_id.empty()) { | |
443 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | |
444 | |
445 SupervisedUserSyncService* supervised_user_sync_service = | |
446 SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); | |
447 if (supervised_user_sync_service) { | |
448 supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( | |
449 &SigninCreateProfileHandler::DoCreateProfileIfPossible, | |
450 weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, | |
451 supervised_user_id, supervisor_profile)); | |
452 } | |
453 } else { | |
454 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | |
455 std::string new_supervised_user_id = | |
456 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | |
457 | |
458 // If sync is not yet fully initialized, the creation may take extra | |
459 // time, so show a message. Import doesn't wait for an acknowledgment, | |
460 // so it won't have the same potential delay. | |
461 ProfileSyncService* sync_service = | |
462 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
463 supervisor_profile); | |
464 ProfileSyncService::SyncStatusSummary status = | |
465 sync_service->QuerySyncStatusSummary(); | |
466 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | |
467 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | |
468 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | |
469 } | |
470 | |
471 DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, | |
472 supervisor_profile); | |
473 } | |
474 break; | |
475 } | |
476 case Profile::CREATE_STATUS_CANCELED: | |
477 case Profile::CREATE_STATUS_REMOTE_FAIL: | |
478 case Profile::MAX_CREATE_STATUS: { | |
479 NOTREACHED(); | |
480 break; | |
481 } | |
482 } | |
483 } | |
484 | |
485 void SigninCreateProfileHandler::DoCreateProfileIfPossible( | |
486 const base::string16& name, | |
487 const std::string& icon_url, | |
488 bool create_shortcut, | |
489 const std::string& supervised_user_id, | |
490 Profile* supervisor_profile, | |
491 const base::DictionaryValue* dict) { | |
492 DCHECK(dict); | |
493 if (!dict->HasKey(supervised_user_id)) | |
494 return; | |
495 | |
496 // Check if this supervised user already exists on this machine. | |
497 ProfileInfoCache& cache = | |
498 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
499 std::vector<ProfileAttributesEntry*> entries = | |
500 cache.GetAllProfilesAttributes(); | |
501 for (auto& entry : entries) { | |
502 if (supervised_user_id == entry->GetSupervisedUserId()) { | |
503 // TODO(mahmadi): see whether we need a more specific error message here. | |
504 ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); | |
505 return; | |
506 } | |
316 } | 507 } |
317 | 508 |
318 if (supervised_user) { | 509 DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, |
319 if (!IsValidExistingSupervisedUserId(*supervised_user_id)) | 510 supervisor_profile); |
320 return false; | |
321 | |
322 profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; | |
323 if (supervised_user_id->empty()) { | |
324 profile_creation_type_ = SUPERVISED_PROFILE_CREATION; | |
325 *supervised_user_id = | |
326 SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); | |
327 | |
328 // If sync is not yet fully initialized, the creation may take extra time, | |
329 // so show a message. Import doesn't wait for an acknowledgment, so it | |
330 // won't have the same potential delay. | |
331 ProfileSyncService* sync_service = | |
332 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | |
333 Profile::FromWebUI(web_ui())); | |
334 ProfileSyncService::SyncStatusSummary status = | |
335 sync_service->QuerySyncStatusSummary(); | |
336 if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { | |
337 ShowProfileCreationWarning(l10n_util::GetStringUTF16( | |
338 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | |
339 } | |
340 } | |
341 } | |
342 return true; | |
343 } | 511 } |
344 | 512 |
345 void CreateProfileHandler::HandleCancelProfileCreation( | 513 void SigninCreateProfileHandler::HandleCancelProfileCreation( |
346 const base::ListValue* args) { | 514 const base::ListValue* args) { |
347 CancelProfileRegistration(true); | 515 CancelProfileRegistration(true); |
348 } | 516 } |
349 | 517 |
350 // Non-supervised user creation cannot be canceled. (Creating a non-supervised | 518 // Non-supervised user creation cannot be canceled. (Creating a non-supervised |
351 // profile shouldn't take significant time, and it can easily be deleted | 519 // profile shouldn't take significant time, and it can easily be deleted |
352 // afterward.) | 520 // afterward.) |
353 void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { | 521 void SigninCreateProfileHandler::CancelProfileRegistration( |
522 bool user_initiated) { | |
354 if (profile_path_being_created_.empty()) | 523 if (profile_path_being_created_.empty()) |
355 return; | 524 return; |
356 | 525 |
357 ProfileManager* manager = g_browser_process->profile_manager(); | 526 ProfileManager* manager = g_browser_process->profile_manager(); |
358 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); | 527 Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_); |
359 if (!new_profile || !new_profile->IsSupervised()) | 528 if (!new_profile || !new_profile->IsSupervised()) |
360 return; | 529 return; |
361 | 530 |
362 DCHECK(supervised_user_registration_utility_.get()); | 531 DCHECK(supervised_user_registration_utility_.get()); |
363 supervised_user_registration_utility_.reset(); | 532 supervised_user_registration_utility_.reset(); |
364 | 533 |
365 if (user_initiated) { | 534 if (user_initiated) { |
366 UMA_HISTOGRAM_MEDIUM_TIMES( | 535 UMA_HISTOGRAM_MEDIUM_TIMES( |
367 "Profile.CreateTimeCanceledNoTimeout", | 536 "Profile.CreateTimeCanceledNoTimeout", |
368 base::TimeTicks::Now() - profile_creation_start_time_); | 537 base::TimeTicks::Now() - profile_creation_start_time_); |
369 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); | 538 RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED); |
370 } | 539 } |
371 | 540 |
372 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); | 541 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
373 profile_creation_type_ = NO_CREATION_IN_PROGRESS; | 542 profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
374 | 543 |
375 // Cancelling registration means the callback passed into | 544 // Canceling registration means the callback passed into |
376 // RegisterAndInitSync() won't be called, so the cleanup must be done here. | 545 // RegisterAndInitSync() won't be called, so the cleanup must be done here. |
377 profile_path_being_created_.clear(); | 546 profile_path_being_created_.clear(); |
378 helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); | 547 options::helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
379 } | 548 } |
380 | 549 |
381 void CreateProfileHandler::RegisterSupervisedUser( | 550 void SigninCreateProfileHandler::RegisterSupervisedUser( |
382 bool create_shortcut, | 551 bool create_shortcut, |
383 const std::string& supervised_user_id, | 552 const std::string& supervised_user_id, |
553 Profile* supervisor_profile, | |
384 Profile* new_profile) { | 554 Profile* new_profile) { |
385 DCHECK_EQ(profile_path_being_created_.value(), | 555 DCHECK_EQ(profile_path_being_created_.value(), |
386 new_profile->GetPath().value()); | 556 new_profile->GetPath().value()); |
387 | 557 |
388 SupervisedUserService* supervised_user_service = | 558 SupervisedUserService* supervised_user_service = |
389 SupervisedUserServiceFactory::GetForProfile(new_profile); | 559 SupervisedUserServiceFactory::GetForProfile(new_profile); |
390 | 560 |
391 // Register the supervised user using the profile of the custodian. | 561 // Register the supervised user using the profile of the custodian. |
392 supervised_user_registration_utility_ = | 562 supervised_user_registration_utility_ = |
393 SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); | 563 SupervisedUserRegistrationUtility::Create(supervisor_profile); |
394 supervised_user_service->RegisterAndInitSync( | 564 supervised_user_service->RegisterAndInitSync( |
395 supervised_user_registration_utility_.get(), | 565 supervised_user_registration_utility_.get(), supervisor_profile, |
396 Profile::FromWebUI(web_ui()), | |
397 supervised_user_id, | 566 supervised_user_id, |
398 base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, | 567 base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, |
399 weak_ptr_factory_.GetWeakPtr(), | 568 weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile)); |
400 create_shortcut, | |
401 new_profile)); | |
402 } | 569 } |
403 | 570 |
404 void CreateProfileHandler::OnSupervisedUserRegistered( | 571 void SigninCreateProfileHandler::OnSupervisedUserRegistered( |
405 bool create_shortcut, | 572 bool create_shortcut, |
406 Profile* profile, | 573 Profile* profile, |
407 const GoogleServiceAuthError& error) { | 574 const GoogleServiceAuthError& error) { |
408 GoogleServiceAuthError::State state = error.state(); | 575 GoogleServiceAuthError::State state = error.state(); |
409 RecordSupervisedProfileCreationMetrics(state); | 576 RecordSupervisedProfileCreationMetrics(state); |
410 if (state == GoogleServiceAuthError::NONE) { | 577 if (state == GoogleServiceAuthError::NONE) { |
411 CreateShortcutAndShowSuccess(create_shortcut, profile); | 578 CreateShortcutAndShowSuccess(create_shortcut, profile); |
412 return; | 579 return; |
413 } | 580 } |
414 | 581 |
415 base::string16 error_msg; | 582 base::string16 error_msg; |
416 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 583 if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
417 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 584 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
418 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 585 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
419 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { | 586 state == GoogleServiceAuthError::ACCOUNT_DISABLED) { |
420 error_msg = GetProfileCreationErrorMessageSignin(); | 587 error_msg = GetProfileCreateErrorMessageSignin(); |
421 } else { | 588 } else { |
422 error_msg = GetProfileCreationErrorMessageRemote(); | 589 error_msg = GetProfileCreateErrorMessageRemote(); |
423 } | 590 } |
424 ShowProfileCreationError(profile, error_msg); | 591 ShowProfileCreationError(profile, error_msg); |
425 } | 592 } |
426 | 593 |
427 void CreateProfileHandler::ShowProfileCreationWarning( | 594 void SigninCreateProfileHandler::ShowProfileCreationWarning( |
428 const base::string16& warning) { | 595 const base::string16& warning) { |
429 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); | 596 DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); |
430 web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning", | 597 web_ui()->CallJavascriptFunction("signin.ProfileApi.onCreateProfileWarning", |
431 base::StringValue(warning)); | 598 base::StringValue(warning)); |
432 } | 599 } |
433 | 600 |
434 void CreateProfileHandler::RecordSupervisedProfileCreationMetrics( | 601 void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
435 GoogleServiceAuthError::State error_state) { | 602 GoogleServiceAuthError::State error_state) { |
436 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { | 603 if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { |
437 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", | 604 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", |
438 error_state, | 605 error_state, GoogleServiceAuthError::NUM_STATES); |
439 GoogleServiceAuthError::NUM_STATES); | |
440 UMA_HISTOGRAM_MEDIUM_TIMES( | 606 UMA_HISTOGRAM_MEDIUM_TIMES( |
441 "Profile.SupervisedProfileTotalCreateTime", | 607 "Profile.SupervisedProfileTotalCreateTime", |
442 base::TimeTicks::Now() - profile_creation_start_time_); | 608 base::TimeTicks::Now() - profile_creation_start_time_); |
443 } else { | 609 } else { |
444 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); | 610 DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); |
445 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", | 611 UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", |
446 error_state, | 612 error_state, GoogleServiceAuthError::NUM_STATES); |
447 GoogleServiceAuthError::NUM_STATES); | |
448 UMA_HISTOGRAM_MEDIUM_TIMES( | 613 UMA_HISTOGRAM_MEDIUM_TIMES( |
449 "Profile.SupervisedProfileTotalImportTime", | 614 "Profile.SupervisedProfileTotalImportTime", |
450 base::TimeTicks::Now() - profile_creation_start_time_); | 615 base::TimeTicks::Now() - profile_creation_start_time_); |
451 } | 616 } |
452 } | 617 } |
453 | 618 |
454 bool CreateProfileHandler::IsValidExistingSupervisedUserId( | |
455 const std::string& existing_supervised_user_id) const { | |
456 if (existing_supervised_user_id.empty()) | |
457 return true; | |
458 | |
459 Profile* profile = Profile::FromWebUI(web_ui()); | |
460 const base::DictionaryValue* dict = | |
461 SupervisedUserSyncServiceFactory::GetForProfile(profile)-> | |
462 GetSupervisedUsers(); | |
463 if (!dict->HasKey(existing_supervised_user_id)) | |
464 return false; | |
465 | |
466 // Check if this supervised user already exists on this machine. | |
467 std::vector<ProfileAttributesEntry*> entries = | |
468 g_browser_process->profile_manager()-> | |
469 GetProfileAttributesStorage().GetAllProfilesAttributes(); | |
470 for (const ProfileAttributesEntry* entry : entries) { | |
471 if (existing_supervised_user_id == entry->GetSupervisedUserId()) | |
472 return false; | |
473 } | |
474 return true; | |
475 } | |
476 #endif | 619 #endif |
477 | |
478 } // namespace options | |
OLD | NEW |