OLD | NEW |
---|---|
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/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/value_conversions.h" | 8 #include "base/value_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/profiles/avatar_menu.h" | |
12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
14 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 13 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
15 #include "chrome/browser/profiles/profile_info_util.h" | 14 #include "chrome/browser/profiles/profile_info_util.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/profiles/profile_window.h" | 16 #include "chrome/browser/profiles/profile_window.h" |
18 #include "chrome/browser/profiles/profiles_state.h" | 17 #include "chrome/browser/profiles/profiles_state.h" |
19 #include "chrome/browser/signin/local_auth.h" | 18 #include "chrome/browser/signin/local_auth.h" |
20 #include "chrome/browser/ui/browser_dialogs.h" | 19 #include "chrome/browser/ui/browser_dialogs.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); | 164 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); |
166 }; | 165 }; |
167 | 166 |
168 // UserManagerScreenHandler --------------------------------------------------- | 167 // UserManagerScreenHandler --------------------------------------------------- |
169 | 168 |
170 UserManagerScreenHandler::UserManagerScreenHandler() | 169 UserManagerScreenHandler::UserManagerScreenHandler() |
171 : desktop_type_(chrome::GetActiveDesktop()) { | 170 : desktop_type_(chrome::GetActiveDesktop()) { |
172 profileInfoCacheObserver_.reset( | 171 profileInfoCacheObserver_.reset( |
173 new UserManagerScreenHandler::ProfileUpdateObserver( | 172 new UserManagerScreenHandler::ProfileUpdateObserver( |
174 g_browser_process->profile_manager(), this)); | 173 g_browser_process->profile_manager(), this)); |
174 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::OPEN_PROFILE_MANAGER); | |
noms (inactive)
2014/01/23 17:00:57
I'm not sure whether this should be in here, or in
bcwhite
2014/01/23 18:14:05
Gotcha. Moved to UserManagerView::Show() for now.
| |
175 } | 175 } |
176 | 176 |
177 UserManagerScreenHandler::~UserManagerScreenHandler() { | 177 UserManagerScreenHandler::~UserManagerScreenHandler() { |
178 } | 178 } |
179 | 179 |
180 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 180 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
181 SendUserList(); | 181 SendUserList(); |
182 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); | 182 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); |
183 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 183 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
184 web_ui()->GetWebContents()->GetView()->GetNativeView()); | 184 web_ui()->GetWebContents()->GetView()->GetNativeView()); |
185 } | 185 } |
186 | 186 |
187 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 187 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
188 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 188 profiles::CreateAndSwitchToNewProfile(desktop_type_, |
189 base::Bind(&chrome::HideUserManager)); | 189 base::Bind(&chrome::HideUserManager)); |
190 ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_MANAGER); | |
190 } | 191 } |
191 | 192 |
192 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 193 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
193 const base::ListValue* args) { | 194 const base::ListValue* args) { |
194 base::string16 email_address; | 195 base::string16 email_address; |
195 if (!args->GetString(0, &email_address)) | 196 if (!args->GetString(0, &email_address)) |
196 return; | 197 return; |
197 | 198 |
198 base::string16 display_name; | 199 base::string16 display_name; |
199 if (!args->GetString(1, &display_name)) | 200 if (!args->GetString(1, &display_name)) |
(...skipping 27 matching lines...) Expand all Loading... | |
227 email_string, | 228 email_string, |
228 password, | 229 password, |
229 GaiaConstants::kSyncService, | 230 GaiaConstants::kSyncService, |
230 std::string(), | 231 std::string(), |
231 std::string(), | 232 std::string(), |
232 GaiaAuthFetcher::HostedAccountsAllowed); | 233 GaiaAuthFetcher::HostedAccountsAllowed); |
233 password_attempt_ = password; | 234 password_attempt_ = password; |
234 return; | 235 return; |
235 } | 236 } |
236 | 237 |
237 ReportAuthenticationResult(true); | 238 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
238 } | 239 } |
239 | 240 |
240 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { | 241 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
241 DCHECK(args); | 242 DCHECK(args); |
242 const base::Value* profile_path_value; | 243 const base::Value* profile_path_value; |
243 if (!args->Get(0, &profile_path_value)) | 244 if (!args->Get(0, &profile_path_value)) |
244 return; | 245 return; |
245 | 246 |
246 base::FilePath profile_path; | 247 base::FilePath profile_path; |
247 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 248 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
248 return; | 249 return; |
249 | 250 |
250 // This handler could have been called in managed mode, for example because | 251 // This handler could have been called in managed mode, for example because |
251 // the user fiddled with the web inspector. Silently return in this case. | 252 // the user fiddled with the web inspector. Silently return in this case. |
252 if (Profile::FromWebUI(web_ui())->IsManaged()) | 253 if (Profile::FromWebUI(web_ui())->IsManaged()) |
253 return; | 254 return; |
254 | 255 |
255 if (!profiles::IsMultipleProfilesEnabled()) | 256 if (!profiles::IsMultipleProfilesEnabled()) |
256 return; | 257 return; |
257 | 258 |
258 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 259 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
259 profile_path, | 260 profile_path, |
260 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 261 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
262 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | |
261 } | 263 } |
262 | 264 |
263 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 265 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
264 profiles::SwitchToGuestProfile(desktop_type_, | 266 profiles::SwitchToGuestProfile(desktop_type_, |
265 base::Bind(&chrome::HideUserManager)); | 267 base::Bind(&chrome::HideUserManager)); |
268 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | |
266 } | 269 } |
267 | 270 |
268 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 271 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
269 base::string16 email_address; | 272 base::string16 email_address; |
270 base::string16 display_name; | 273 base::string16 display_name; |
271 | 274 |
272 if (!args->GetString(0, &email_address) || | 275 if (!args->GetString(0, &email_address) || |
273 !args->GetString(1, &display_name)) { | 276 !args->GetString(1, &display_name)) { |
274 NOTREACHED(); | 277 NOTREACHED(); |
275 return; | 278 return; |
276 } | 279 } |
277 | 280 |
278 ProfileInfoCache& info_cache = | 281 ProfileInfoCache& info_cache = |
279 g_browser_process->profile_manager()->GetProfileInfoCache(); | 282 g_browser_process->profile_manager()->GetProfileInfoCache(); |
280 size_t profile_index = GetIndexOfProfileWithEmailAndName( | 283 size_t profile_index = GetIndexOfProfileWithEmailAndName( |
281 info_cache, email_address, display_name); | 284 info_cache, email_address, display_name); |
282 | 285 |
283 if (profile_index >= info_cache.GetNumberOfProfiles()) { | 286 if (profile_index >= info_cache.GetNumberOfProfiles()) { |
284 NOTREACHED(); | 287 NOTREACHED(); |
285 return; | 288 return; |
286 } | 289 } |
287 | 290 |
288 // It's possible that a user breaks into the user-manager page using the | 291 // It's possible that a user breaks into the user-manager page using the |
289 // JavaScript Inspector and causes a "locked" profile to call this | 292 // JavaScript Inspector and causes a "locked" profile to call this |
290 // unauthenticated version of "launch" instead of the proper one. Thus, | 293 // unauthenticated version of "launch" instead of the proper one. Thus, |
291 // we have to validate in (secure) C++ code that it really is a profile | 294 // we have to validate in (secure) C++ code that it really is a profile |
292 // not needing authentication. If it is, just ignore the "launch" request. | 295 // not needing authentication. If it is, just ignore the "launch" request. |
293 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 296 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
294 return; | 297 return; |
298 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | |
295 | 299 |
296 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 300 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
297 profiles::SwitchToProfile( | 301 profiles::SwitchToProfile( |
298 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); | 302 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); |
303 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_MANAGER); | |
299 } | 304 } |
300 | 305 |
301 void UserManagerScreenHandler::OnClientLoginSuccess( | 306 void UserManagerScreenHandler::OnClientLoginSuccess( |
302 const ClientLoginResult& result) { | 307 const ClientLoginResult& result) { |
303 chrome::SetLocalAuthCredentials(authenticating_profile_index_, | 308 chrome::SetLocalAuthCredentials(authenticating_profile_index_, |
304 password_attempt_); | 309 password_attempt_); |
305 ReportAuthenticationResult(true); | 310 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE); |
306 } | 311 } |
307 | 312 |
308 void UserManagerScreenHandler::OnClientLoginFailure( | 313 void UserManagerScreenHandler::OnClientLoginFailure( |
309 const GoogleServiceAuthError& error) { | 314 const GoogleServiceAuthError& error) { |
310 ReportAuthenticationResult(false); | 315 ReportAuthenticationResult(false, ProfileMetrics::AUTH_ONLINE); |
311 } | 316 } |
312 | 317 |
313 void UserManagerScreenHandler::RegisterMessages() { | 318 void UserManagerScreenHandler::RegisterMessages() { |
314 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, | 319 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, |
315 base::Bind(&UserManagerScreenHandler::HandleInitialize, | 320 base::Bind(&UserManagerScreenHandler::HandleInitialize, |
316 base::Unretained(this))); | 321 base::Unretained(this))); |
317 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, | 322 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, |
318 base::Bind(&UserManagerScreenHandler::HandleAddUser, | 323 base::Bind(&UserManagerScreenHandler::HandleAddUser, |
319 base::Unretained(this))); | 324 base::Unretained(this))); |
320 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, | 325 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 if (is_active_user) | 439 if (is_active_user) |
435 users_list.Insert(0, profile_value); | 440 users_list.Insert(0, profile_value); |
436 else | 441 else |
437 users_list.Append(profile_value); | 442 users_list.Append(profile_value); |
438 } | 443 } |
439 | 444 |
440 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 445 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
441 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); | 446 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); |
442 } | 447 } |
443 | 448 |
444 void UserManagerScreenHandler::ReportAuthenticationResult(bool success) { | 449 void UserManagerScreenHandler::ReportAuthenticationResult( |
450 bool success, ProfileMetrics::ProfileAuth auth) { | |
445 if (success) { | 451 if (success) { |
452 ProfileMetrics::LogProfileAuthResult(auth); | |
446 ProfileInfoCache& info_cache = | 453 ProfileInfoCache& info_cache = |
447 g_browser_process->profile_manager()->GetProfileInfoCache(); | 454 g_browser_process->profile_manager()->GetProfileInfoCache(); |
448 info_cache.SetProfileSigninRequiredAtIndex( | 455 info_cache.SetProfileSigninRequiredAtIndex( |
449 authenticating_profile_index_, false); | 456 authenticating_profile_index_, false); |
450 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 457 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
451 authenticating_profile_index_); | 458 authenticating_profile_index_); |
452 profiles::SwitchToProfile(path, desktop_type_, true, | 459 profiles::SwitchToProfile(path, desktop_type_, true, |
453 base::Bind(&chrome::HideUserManager)); | 460 base::Bind(&chrome::HideUserManager)); |
461 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_UNLOCK); | |
454 } else { | 462 } else { |
463 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_FAILED); | |
455 web_ui()->CallJavascriptFunction( | 464 web_ui()->CallJavascriptFunction( |
456 "cr.ui.Oobe.showSignInError", | 465 "cr.ui.Oobe.showSignInError", |
457 base::FundamentalValue(0), | 466 base::FundamentalValue(0), |
458 base::StringValue( | 467 base::StringValue( |
459 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 468 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
460 base::StringValue(""), | 469 base::StringValue(""), |
461 base::FundamentalValue(0)); | 470 base::FundamentalValue(0)); |
462 } | 471 } |
463 | 472 |
464 password_attempt_.clear(); | 473 password_attempt_.clear(); |
465 } | 474 } |
OLD | NEW |