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

Side by Side Diff: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc

Issue 132453004: Add Profile metric counting to new User Manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed minor formatting comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 178
180 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { 179 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) {
181 SendUserList(); 180 SendUserList();
182 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); 181 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen");
183 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( 182 desktop_type_ = chrome::GetHostDesktopTypeForNativeView(
184 web_ui()->GetWebContents()->GetView()->GetNativeView()); 183 web_ui()->GetWebContents()->GetView()->GetNativeView());
185 } 184 }
186 185
187 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { 186 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
188 profiles::CreateAndSwitchToNewProfile(desktop_type_, 187 profiles::CreateAndSwitchToNewProfile(desktop_type_,
189 base::Bind(&chrome::HideUserManager)); 188 base::Bind(&chrome::HideUserManager),
189 ProfileMetrics::ADD_NEW_USER_MANAGER);
190 } 190 }
191 191
192 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( 192 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
193 const base::ListValue* args) { 193 const base::ListValue* args) {
194 base::string16 email_address; 194 base::string16 email_address;
195 if (!args->GetString(0, &email_address)) 195 if (!args->GetString(0, &email_address))
196 return; 196 return;
197 197
198 base::string16 display_name; 198 base::string16 display_name;
199 if (!args->GetString(1, &display_name)) 199 if (!args->GetString(1, &display_name))
(...skipping 27 matching lines...) Expand all
227 email_string, 227 email_string,
228 password, 228 password,
229 GaiaConstants::kSyncService, 229 GaiaConstants::kSyncService,
230 std::string(), 230 std::string(),
231 std::string(), 231 std::string(),
232 GaiaAuthFetcher::HostedAccountsAllowed); 232 GaiaAuthFetcher::HostedAccountsAllowed);
233 password_attempt_ = password; 233 password_attempt_ = password;
234 return; 234 return;
235 } 235 }
236 236
237 ReportAuthenticationResult(true); 237 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL);
238 } 238 }
239 239
240 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { 240 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) {
241 DCHECK(args); 241 DCHECK(args);
242 const base::Value* profile_path_value; 242 const base::Value* profile_path_value;
243 if (!args->Get(0, &profile_path_value)) 243 if (!args->Get(0, &profile_path_value))
244 return; 244 return;
245 245
246 base::FilePath profile_path; 246 base::FilePath profile_path;
247 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) 247 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path))
248 return; 248 return;
249 249
250 // This handler could have been called in managed mode, for example because 250 // 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. 251 // the user fiddled with the web inspector. Silently return in this case.
252 if (Profile::FromWebUI(web_ui())->IsManaged()) 252 if (Profile::FromWebUI(web_ui())->IsManaged())
253 return; 253 return;
254 254
255 if (!profiles::IsMultipleProfilesEnabled()) 255 if (!profiles::IsMultipleProfilesEnabled())
256 return; 256 return;
257 257
258 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 258 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
259 profile_path, 259 profile_path,
260 base::Bind(&OpenNewWindowForProfile, desktop_type_)); 260 base::Bind(&OpenNewWindowForProfile, desktop_type_));
261 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED);
261 } 262 }
262 263
263 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { 264 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
264 profiles::SwitchToGuestProfile(desktop_type_, 265 profiles::SwitchToGuestProfile(desktop_type_,
265 base::Bind(&chrome::HideUserManager)); 266 base::Bind(&chrome::HideUserManager));
267 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
266 } 268 }
267 269
268 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { 270 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
269 base::string16 email_address; 271 base::string16 email_address;
270 base::string16 display_name; 272 base::string16 display_name;
271 273
272 if (!args->GetString(0, &email_address) || 274 if (!args->GetString(0, &email_address) ||
273 !args->GetString(1, &display_name)) { 275 !args->GetString(1, &display_name)) {
274 NOTREACHED(); 276 NOTREACHED();
275 return; 277 return;
276 } 278 }
277 279
278 ProfileInfoCache& info_cache = 280 ProfileInfoCache& info_cache =
279 g_browser_process->profile_manager()->GetProfileInfoCache(); 281 g_browser_process->profile_manager()->GetProfileInfoCache();
280 size_t profile_index = GetIndexOfProfileWithEmailAndName( 282 size_t profile_index = GetIndexOfProfileWithEmailAndName(
281 info_cache, email_address, display_name); 283 info_cache, email_address, display_name);
282 284
283 if (profile_index >= info_cache.GetNumberOfProfiles()) { 285 if (profile_index >= info_cache.GetNumberOfProfiles()) {
284 NOTREACHED(); 286 NOTREACHED();
285 return; 287 return;
286 } 288 }
287 289
288 // It's possible that a user breaks into the user-manager page using the 290 // 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 291 // JavaScript Inspector and causes a "locked" profile to call this
290 // unauthenticated version of "launch" instead of the proper one. Thus, 292 // 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 293 // 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. 294 // not needing authentication. If it is, just ignore the "launch" request.
293 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) 295 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index))
294 return; 296 return;
297 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY);
295 298
296 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); 299 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index);
297 profiles::SwitchToProfile( 300 profiles::SwitchToProfile(path,
298 path, desktop_type_, true, base::Bind(&chrome::HideUserManager)); 301 desktop_type_,
302 true,
303 base::Bind(&chrome::HideUserManager),
304 ProfileMetrics::SWITCH_PROFILE_MANAGER);
299 } 305 }
300 306
301 void UserManagerScreenHandler::OnClientLoginSuccess( 307 void UserManagerScreenHandler::OnClientLoginSuccess(
302 const ClientLoginResult& result) { 308 const ClientLoginResult& result) {
303 chrome::SetLocalAuthCredentials(authenticating_profile_index_, 309 chrome::SetLocalAuthCredentials(authenticating_profile_index_,
304 password_attempt_); 310 password_attempt_);
305 ReportAuthenticationResult(true); 311 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE);
306 } 312 }
307 313
308 void UserManagerScreenHandler::OnClientLoginFailure( 314 void UserManagerScreenHandler::OnClientLoginFailure(
309 const GoogleServiceAuthError& error) { 315 const GoogleServiceAuthError& error) {
310 ReportAuthenticationResult(false); 316 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED);
311 } 317 }
312 318
313 void UserManagerScreenHandler::RegisterMessages() { 319 void UserManagerScreenHandler::RegisterMessages() {
314 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize, 320 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize,
315 base::Bind(&UserManagerScreenHandler::HandleInitialize, 321 base::Bind(&UserManagerScreenHandler::HandleInitialize,
316 base::Unretained(this))); 322 base::Unretained(this)));
317 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser, 323 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser,
318 base::Bind(&UserManagerScreenHandler::HandleAddUser, 324 base::Bind(&UserManagerScreenHandler::HandleAddUser,
319 base::Unretained(this))); 325 base::Unretained(this)));
320 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser, 326 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (is_active_user) 440 if (is_active_user)
435 users_list.Insert(0, profile_value); 441 users_list.Insert(0, profile_value);
436 else 442 else
437 users_list.Append(profile_value); 443 users_list.Append(profile_value);
438 } 444 }
439 445
440 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", 446 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
441 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); 447 users_list, base::FundamentalValue(false), base::FundamentalValue(true));
442 } 448 }
443 449
444 void UserManagerScreenHandler::ReportAuthenticationResult(bool success) { 450 void UserManagerScreenHandler::ReportAuthenticationResult(
451 bool success,
452 ProfileMetrics::ProfileAuth auth) {
445 if (success) { 453 if (success) {
446 ProfileInfoCache& info_cache = 454 ProfileInfoCache& info_cache =
447 g_browser_process->profile_manager()->GetProfileInfoCache(); 455 g_browser_process->profile_manager()->GetProfileInfoCache();
448 info_cache.SetProfileSigninRequiredAtIndex( 456 info_cache.SetProfileSigninRequiredAtIndex(
449 authenticating_profile_index_, false); 457 authenticating_profile_index_, false);
450 base::FilePath path = info_cache.GetPathOfProfileAtIndex( 458 base::FilePath path = info_cache.GetPathOfProfileAtIndex(
451 authenticating_profile_index_); 459 authenticating_profile_index_);
452 profiles::SwitchToProfile(path, desktop_type_, true, 460 profiles::SwitchToProfile(path, desktop_type_, true,
453 base::Bind(&chrome::HideUserManager)); 461 base::Bind(&chrome::HideUserManager),
462 ProfileMetrics::SWITCH_PROFILE_UNLOCK);
454 } else { 463 } else {
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
473 ProfileMetrics::LogProfileAuthResult(auth);
464 password_attempt_.clear(); 474 password_attempt_.clear();
465 } 475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698