| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // depends on that and it's hard to figure out what). | 72 // depends on that and it's hard to figure out what). |
| 73 const char kGuestUser[] = ""; | 73 const char kGuestUser[] = ""; |
| 74 | 74 |
| 75 // Stub user email (for test paths). | 75 // Stub user email (for test paths). |
| 76 const char kStubUser[] = "stub-user@example.com"; | 76 const char kStubUser[] = "stub-user@example.com"; |
| 77 | 77 |
| 78 // Names of nodes with info about user image. | 78 // Names of nodes with info about user image. |
| 79 const char kImagePathNodeName[] = "path"; | 79 const char kImagePathNodeName[] = "path"; |
| 80 const char kImageIndexNodeName[] = "index"; | 80 const char kImageIndexNodeName[] = "index"; |
| 81 | 81 |
| 82 // Index of the default image used as stub while the real user image is loading | 82 // Index of the default image used for the |kStubUser| user. |
| 83 // from file and for the |kStubUser| user. | |
| 84 const int kStubDefaultImageIndex = 0; | 83 const int kStubDefaultImageIndex = 0; |
| 85 | 84 |
| 86 // Delay betweeen user login and attempt to update user's profile image. | 85 // Delay betweeen user login and attempt to update user's profile image. |
| 87 const long kProfileImageDownloadDelayMs = 10000; | 86 const long kProfileImageDownloadDelayMs = 10000; |
| 88 | 87 |
| 89 base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER; | 88 base::LazyInstance<UserManager> g_user_manager = LAZY_INSTANCE_INITIALIZER; |
| 90 | 89 |
| 91 // Enum for reporting histograms about profile picture download. | 90 // Enum for reporting histograms about profile picture download. |
| 92 enum ProfileDownloadResult { | 91 enum ProfileDownloadResult { |
| 93 kDownloadSuccessChanged, | 92 kDownloadSuccessChanged, |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 // backward compatibility. | 583 // backward compatibility. |
| 585 std::string image_path; | 584 std::string image_path; |
| 586 base::DictionaryValue* image_properties; | 585 base::DictionaryValue* image_properties; |
| 587 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { | 586 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { |
| 588 int image_id = User::kInvalidImageIndex; | 587 int image_id = User::kInvalidImageIndex; |
| 589 if (IsDefaultImagePath(image_path, &image_id)) { | 588 if (IsDefaultImagePath(image_path, &image_id)) { |
| 590 user->SetImage(GetDefaultImage(image_id), image_id); | 589 user->SetImage(GetDefaultImage(image_id), image_id); |
| 591 } else { | 590 } else { |
| 592 int image_index = User::kExternalImageIndex; | 591 int image_index = User::kExternalImageIndex; |
| 593 // Until image has been loaded, use a stub. | 592 // Until image has been loaded, use a stub. |
| 594 user->SetImage(GetDefaultImage(kStubDefaultImageIndex), | 593 user->SetImage(*ResourceBundle::GetSharedInstance(). |
| 594 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING), |
| 595 image_index); | 595 image_index); |
| 596 DCHECK(!image_path.empty()); | 596 DCHECK(!image_path.empty()); |
| 597 // Load user image asynchronously. | 597 // Load user image asynchronously. |
| 598 image_loader_->Start( | 598 image_loader_->Start( |
| 599 image_path, 0, | 599 image_path, 0, |
| 600 base::Bind(&UserManager::SetUserImage, | 600 base::Bind(&UserManager::SetUserImage, |
| 601 base::Unretained(this), email, image_index)); | 601 base::Unretained(this), email, image_index)); |
| 602 } | 602 } |
| 603 } else if (prefs_images->GetDictionaryWithoutPathExpansion( | 603 } else if (prefs_images->GetDictionaryWithoutPathExpansion( |
| 604 email, &image_properties)) { | 604 email, &image_properties)) { |
| 605 int image_index = User::kInvalidImageIndex; | 605 int image_index = User::kInvalidImageIndex; |
| 606 image_properties->GetString(kImagePathNodeName, &image_path); | 606 image_properties->GetString(kImagePathNodeName, &image_path); |
| 607 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 607 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
| 608 if (image_index >= 0 && image_index < kDefaultImagesCount) { | 608 if (image_index >= 0 && image_index < kDefaultImagesCount) { |
| 609 user->SetImage(GetDefaultImage(image_index), image_index); | 609 user->SetImage(GetDefaultImage(image_index), image_index); |
| 610 } else if (image_index == User::kExternalImageIndex || | 610 } else if (image_index == User::kExternalImageIndex || |
| 611 image_index == User::kProfileImageIndex) { | 611 image_index == User::kProfileImageIndex) { |
| 612 // Path may be empty for profile images (meaning that the image | 612 // Path may be empty for profile images (meaning that the image |
| 613 // hasn't been downloaded for the first time yet, in which case a | 613 // hasn't been downloaded for the first time yet, in which case a |
| 614 // download will be scheduled for |kProfileImageDownloadDelayMs| | 614 // download will be scheduled for |kProfileImageDownloadDelayMs| |
| 615 // after user logs in). | 615 // after user logs in). |
| 616 DCHECK(!image_path.empty() || | 616 DCHECK(!image_path.empty() || |
| 617 image_index == User::kProfileImageIndex); | 617 image_index == User::kProfileImageIndex); |
| 618 // Until image has been loaded, use a stub. | 618 // Until image has been loaded, use a gray avatar. |
| 619 user->SetImage(GetDefaultImage(kStubDefaultImageIndex), | 619 user->SetImage(*ResourceBundle::GetSharedInstance(). |
| 620 GetBitmapNamed(IDR_PROFILE_PICTURE_LOADING), |
| 620 image_index); | 621 image_index); |
| 621 if (!image_path.empty()) { | 622 if (!image_path.empty()) { |
| 622 // Load user image asynchronously. | 623 // Load user image asynchronously. |
| 623 image_loader_->Start( | 624 image_loader_->Start( |
| 624 image_path, 0, | 625 image_path, 0, |
| 625 base::Bind(&UserManager::SetUserImage, | 626 base::Bind(&UserManager::SetUserImage, |
| 626 base::Unretained(this), email, image_index)); | 627 base::Unretained(this), email, image_index)); |
| 627 } | 628 } |
| 628 } else { | 629 } else { |
| 629 NOTREACHED(); | 630 NOTREACHED(); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 900 |
| 900 User* UserManager::CreateUser(const std::string& email) const { | 901 User* UserManager::CreateUser(const std::string& email) const { |
| 901 User* user = new User(email); | 902 User* user = new User(email); |
| 902 user->set_oauth_token_status(GetUserOAuthStatus(email)); | 903 user->set_oauth_token_status(GetUserOAuthStatus(email)); |
| 903 // Used to determine whether user's display name is unique. | 904 // Used to determine whether user's display name is unique. |
| 904 ++display_name_count_[user->GetDisplayName()]; | 905 ++display_name_count_[user->GetDisplayName()]; |
| 905 return user; | 906 return user; |
| 906 } | 907 } |
| 907 | 908 |
| 908 } // namespace chromeos | 909 } // namespace chromeos |
| OLD | NEW |