OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/login/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "crypto/nss_util.h" | 20 #include "crypto/nss_util.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chromeos/cros/cros_library.h" | 22 #include "chrome/browser/chromeos/cros/cros_library.h" |
22 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 23 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 } // namespace | 217 } // namespace |
217 | 218 |
218 UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), | 219 UserManager::User::User() : oauth_token_status_(OAUTH_TOKEN_STATUS_UNKNOWN), |
219 is_displayname_unique_(false) { | 220 is_displayname_unique_(false) { |
220 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 221 image_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
221 kDefaultImageResources[0]); | 222 kDefaultImageResources[0]); |
222 } | 223 } |
223 | 224 |
224 UserManager::User::~User() {} | 225 UserManager::User::~User() {} |
225 | 226 |
227 void UserManager::User::SetImage(const SkBitmap& image, | |
228 int default_image_index) { | |
229 image_ = image; | |
230 default_image_index_ = default_image_index; | |
231 } | |
232 | |
226 std::string UserManager::User::GetDisplayName() const { | 233 std::string UserManager::User::GetDisplayName() const { |
227 size_t i = email_.find('@'); | 234 size_t i = email_.find('@'); |
228 if (i == 0 || i == std::string::npos) { | 235 if (i == 0 || i == std::string::npos) { |
229 return email_; | 236 return email_; |
230 } | 237 } |
231 return email_.substr(0, i); | 238 return email_.substr(0, i); |
232 } | 239 } |
233 | 240 |
234 bool UserManager::User::NeedsNameTooltip() const { | 241 bool UserManager::User::NeedsNameTooltip() const { |
235 return !is_displayname_unique_; | 242 return !is_displayname_unique_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 } else { | 303 } else { |
297 int oauth_token_status = OAUTH_TOKEN_STATUS_UNKNOWN; | 304 int oauth_token_status = OAUTH_TOKEN_STATUS_UNKNOWN; |
298 if (prefs_oauth_status && | 305 if (prefs_oauth_status && |
299 prefs_oauth_status->GetIntegerWithoutPathExpansion(email, | 306 prefs_oauth_status->GetIntegerWithoutPathExpansion(email, |
300 &oauth_token_status)) { | 307 &oauth_token_status)) { |
301 user.set_oauth_token_status( | 308 user.set_oauth_token_status( |
302 static_cast<OAuthTokenStatus>(oauth_token_status)); | 309 static_cast<OAuthTokenStatus>(oauth_token_status)); |
303 } | 310 } |
304 } | 311 } |
305 | 312 |
306 UserImages::const_iterator image_it = user_images_.find(email); | |
307 std::string image_path; | 313 std::string image_path; |
308 if (image_it == user_images_.end()) { | 314 // Get account image path. |
309 // Get account image path. | 315 if (prefs_images && |
310 if (prefs_images && | 316 prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { |
311 prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { | 317 int default_image_id = kDefaultImagesCount; |
312 int default_image_id = kDefaultImagesCount; | 318 if (IsDefaultImagePath(image_path, &default_image_id)) { |
313 if (IsDefaultImagePath(image_path, &default_image_id)) { | 319 DCHECK(default_image_id >= 0); |
314 DCHECK(default_image_id < kDefaultImagesCount); | 320 DCHECK(default_image_id < kDefaultImagesCount); |
315 int resource_id = kDefaultImageResources[default_image_id]; | 321 int resource_id = kDefaultImageResources[default_image_id]; |
316 user.set_image( | 322 user.SetImage( |
317 *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 323 *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
318 resource_id)); | 324 resource_id), |
319 user_images_[email] = user.image(); | 325 default_image_id); |
320 } else { | 326 } else { |
327 UserImages::const_iterator image_it = user_images_.find(email); | |
328 if (image_it == user_images_.end()) { | |
321 // Insert the default image so we don't send another request if | 329 // Insert the default image so we don't send another request if |
322 // GetUsers is called twice. | 330 // GetUsers is called twice. |
323 user_images_[email] = user.image(); | 331 user_images_[email] = user.image(); |
324 image_loader_->Start(email, image_path, false); | 332 image_loader_->Start(email, image_path, false); |
333 } else { | |
334 user.SetImage(image_it->second, -1); | |
325 } | 335 } |
326 } | 336 } |
327 } else { | |
328 user.set_image(image_it->second); | |
329 } | 337 } |
330 | 338 |
331 // Makes table to determine whether displayname is unique. | 339 // Makes table to determine whether displayname is unique. |
332 const std::string& display_name = user.GetDisplayName(); | 340 const std::string& display_name = user.GetDisplayName(); |
333 ++display_name_count[display_name]; | 341 ++display_name_count[display_name]; |
334 | 342 |
335 users.push_back(user); | 343 users.push_back(user); |
336 } | 344 } |
337 } | 345 } |
338 | 346 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 std::string user_email = it->email(); | 390 std::string user_email = it->email(); |
383 // Skip the most recent user. | 391 // Skip the most recent user. |
384 if (email != user_email) { | 392 if (email != user_email) { |
385 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 393 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
386 } else { | 394 } else { |
387 logged_in_user_ = *it; | 395 logged_in_user_ = *it; |
388 } | 396 } |
389 } | 397 } |
390 prefs->SavePersistentPrefs(); | 398 prefs->SavePersistentPrefs(); |
391 NotifyOnLogin(); | 399 NotifyOnLogin(); |
392 if (current_user_is_new_) | 400 if (current_user_is_new_) { |
393 SetDefaultUserImage(email); | 401 SetDefaultUserImage(email); |
402 } else { | |
403 int metric = kDefaultImagesCount; | |
404 if (logged_in_user_.default_image_index() != -1) | |
405 metric = logged_in_user_.default_image_index(); | |
jar (doing other things)
2011/08/10 17:48:52
personal style nit: not critical: I prefer to cal
| |
406 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", | |
407 metric, | |
408 kDefaultImagesCount + 1); | |
409 } | |
394 } | 410 } |
395 | 411 |
396 void UserManager::RemoveUser(const std::string& email, | 412 void UserManager::RemoveUser(const std::string& email, |
397 RemoveUserDelegate* delegate) { | 413 RemoveUserDelegate* delegate) { |
398 // Get a copy of the current users. | 414 // Get a copy of the current users. |
399 std::vector<User> users = GetUsers(); | 415 std::vector<User> users = GetUsers(); |
400 | 416 |
401 // Sanity check: we must not remove single user. This check may seem | 417 // Sanity check: we must not remove single user. This check may seem |
402 // redundant at a first sight because this single user must be an owner and | 418 // redundant at a first sight because this single user must be an owner and |
403 // we perform special check later in order not to remove an owner. However | 419 // we perform special check later in order not to remove an owner. However |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 return image_id; | 589 return image_id; |
574 } | 590 } |
575 | 591 |
576 void UserManager::OnImageLoaded(const std::string& username, | 592 void UserManager::OnImageLoaded(const std::string& username, |
577 const SkBitmap& image, | 593 const SkBitmap& image, |
578 bool should_save_image) { | 594 bool should_save_image) { |
579 DVLOG(1) << "Loaded image for " << username; | 595 DVLOG(1) << "Loaded image for " << username; |
580 user_images_[username] = image; | 596 user_images_[username] = image; |
581 User user; | 597 User user; |
582 user.set_email(username); | 598 user.set_email(username); |
583 user.set_image(image); | 599 user.SetImage(image, -1); |
584 if (logged_in_user_.email() == username) | 600 if (logged_in_user_.email() == username) |
585 logged_in_user_.set_image(image); | 601 logged_in_user_.SetImage(image, -1); |
586 if (should_save_image) | 602 if (should_save_image) |
587 SaveUserImage(username, image); | 603 SaveUserImage(username, image); |
588 NotificationService::current()->Notify( | 604 NotificationService::current()->Notify( |
589 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 605 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
590 Source<UserManager>(this), | 606 Source<UserManager>(this), |
591 Details<const User>(&user)); | 607 Details<const User>(&user)); |
592 } | 608 } |
593 | 609 |
594 bool UserManager::IsLoggedInAsGuest() const { | 610 bool UserManager::IsLoggedInAsGuest() const { |
595 return logged_in_user().email() == kGuestUser; | 611 return logged_in_user().email() == kGuestUser; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 } | 722 } |
707 | 723 |
708 void UserManager::NotifyLocalStateChanged() { | 724 void UserManager::NotifyLocalStateChanged() { |
709 FOR_EACH_OBSERVER( | 725 FOR_EACH_OBSERVER( |
710 Observer, | 726 Observer, |
711 observer_list_, | 727 observer_list_, |
712 LocalStateChanged(this)); | 728 LocalStateChanged(this)); |
713 } | 729 } |
714 | 730 |
715 } // namespace chromeos | 731 } // namespace chromeos |
OLD | NEW |