OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/avatar/user_image_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/browser/chromeos/login/helper.h" | 26 #include "chrome/browser/chromeos/login/helper.h" |
27 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" | 27 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" |
28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
29 #include "chrome/browser/profiles/profile_downloader.h" | 29 #include "chrome/browser/profiles/profile_downloader.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/grit/theme_resources.h" | 32 #include "chrome/grit/theme_resources.h" |
33 #include "components/user_manager/user_image/default_user_images.h" | 33 #include "components/user_manager/user_image/default_user_images.h" |
34 #include "components/user_manager/user_image/user_image.h" | 34 #include "components/user_manager/user_image/user_image.h" |
35 #include "components/user_manager/user_manager.h" | 35 #include "components/user_manager/user_manager.h" |
36 #include "components/user_manager/user_type.h" | |
37 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
39 #include "policy/policy_constants.h" | 38 #include "policy/policy_constants.h" |
40 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
42 | 41 |
43 namespace chromeos { | 42 namespace chromeos { |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 } | 602 } |
604 } | 603 } |
605 } | 604 } |
606 } | 605 } |
607 | 606 |
608 // Reset the downloaded profile image as a new user logged in. | 607 // Reset the downloaded profile image as a new user logged in. |
609 downloaded_profile_image_ = gfx::ImageSkia(); | 608 downloaded_profile_image_ = gfx::ImageSkia(); |
610 profile_image_url_ = GURL(); | 609 profile_image_url_ = GURL(); |
611 profile_image_requested_ = false; | 610 profile_image_requested_ = false; |
612 | 611 |
613 if (IsUserLoggedInAndRegular()) { | 612 if (IsUserLoggedInAndHasGaiaAccount()) { |
614 TryToInitDownloadedProfileImage(); | 613 TryToInitDownloadedProfileImage(); |
615 | 614 |
616 // Schedule an initial download of the profile data (full name and | 615 // Schedule an initial download of the profile data (full name and |
617 // optionally image). | 616 // optionally image). |
618 profile_download_one_shot_timer_.Start( | 617 profile_download_one_shot_timer_.Start( |
619 FROM_HERE, | 618 FROM_HERE, |
620 g_ignore_profile_data_download_delay_ ? | 619 g_ignore_profile_data_download_delay_ ? |
621 base::TimeDelta() : | 620 base::TimeDelta() : |
622 base::TimeDelta::FromSeconds(kProfileDataDownloadDelaySec), | 621 base::TimeDelta::FromSeconds(kProfileDataDownloadDelaySec), |
623 base::Bind(&UserImageManagerImpl::DownloadProfileData, | 622 base::Bind(&UserImageManagerImpl::DownloadProfileData, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 // user if it has not been initialized already, the user image is the | 883 // user if it has not been initialized already, the user image is the |
885 // profile image and the user image has been loaded successfully. | 884 // profile image and the user image has been loaded successfully. |
886 VLOG(1) << "Profile image initialized from disk."; | 885 VLOG(1) << "Profile image initialized from disk."; |
887 downloaded_profile_image_ = user->GetImage(); | 886 downloaded_profile_image_ = user->GetImage(); |
888 profile_image_url_ = user->image_url(); | 887 profile_image_url_ = user->image_url(); |
889 } | 888 } |
890 } | 889 } |
891 | 890 |
892 bool UserImageManagerImpl::NeedProfileImage() const { | 891 bool UserImageManagerImpl::NeedProfileImage() const { |
893 const user_manager::User* user = GetUser(); | 892 const user_manager::User* user = GetUser(); |
894 return IsUserLoggedInAndRegular() && | 893 return IsUserLoggedInAndHasGaiaAccount() && |
895 (user->image_index() == user_manager::User::USER_IMAGE_PROFILE || | 894 (user->image_index() == user_manager::User::USER_IMAGE_PROFILE || |
896 profile_image_requested_); | 895 profile_image_requested_); |
897 } | 896 } |
898 | 897 |
899 void UserImageManagerImpl::DownloadProfileData(const std::string& reason) { | 898 void UserImageManagerImpl::DownloadProfileData(const std::string& reason) { |
900 // GAIA profiles exist for regular users only. | 899 if (!IsUserLoggedInAndHasGaiaAccount()) |
901 if (!IsUserLoggedInAndRegular()) | |
902 return; | 900 return; |
903 | 901 |
904 // If a download is already in progress, allow it to continue, with one | 902 // If a download is already in progress, allow it to continue, with one |
905 // exception: If the current download does not include the profile image but | 903 // exception: If the current download does not include the profile image but |
906 // the image has since become necessary, start a new download that includes | 904 // the image has since become necessary, start a new download that includes |
907 // the profile image. | 905 // the profile image. |
908 if (profile_downloader_ && | 906 if (profile_downloader_ && |
909 (downloading_profile_image_ || !NeedProfileImage())) { | 907 (downloading_profile_image_ || !NeedProfileImage())) { |
910 return; | 908 return; |
911 } | 909 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 } | 1010 } |
1013 | 1011 |
1014 const user_manager::User* UserImageManagerImpl::GetUser() const { | 1012 const user_manager::User* UserImageManagerImpl::GetUser() const { |
1015 return user_manager_->FindUser(user_id()); | 1013 return user_manager_->FindUser(user_id()); |
1016 } | 1014 } |
1017 | 1015 |
1018 user_manager::User* UserImageManagerImpl::GetUserAndModify() const { | 1016 user_manager::User* UserImageManagerImpl::GetUserAndModify() const { |
1019 return user_manager_->FindUserAndModify(user_id()); | 1017 return user_manager_->FindUserAndModify(user_id()); |
1020 } | 1018 } |
1021 | 1019 |
1022 bool UserImageManagerImpl::IsUserLoggedInAndRegular() const { | 1020 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { |
1023 const user_manager::User* user = GetUser(); | 1021 const user_manager::User* user = GetUser(); |
1024 if (!user) | 1022 if (!user) |
1025 return false; | 1023 return false; |
1026 return user->is_logged_in() && | 1024 return user->is_logged_in() && user->HasGaiaAccount(); |
1027 user->GetType() == user_manager::USER_TYPE_REGULAR; | |
1028 } | 1025 } |
1029 | 1026 |
1030 } // namespace chromeos | 1027 } // namespace chromeos |
OLD | NEW |