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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 10832019: Speed up custom wallpaper switching time and wallpaper manager code refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "chrome/browser/chromeos/login/user_manager_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/desktop_background/desktop_background_controller.h" 10 #include "ash/desktop_background/desktop_background_controller.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/chromeos/chromeos_version.h" 12 #include "base/chromeos/chromeos_version.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/rand_util.h" 20 #include "base/rand_util.h"
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "base/string_number_conversions.h"
23 #include "base/string_util.h"
24 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
25 #include "base/time.h" 23 #include "base/time.h"
26 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
27 #include "base/values.h" 25 #include "base/values.h"
28 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
29 #include "chrome/browser/chromeos/cros/cert_library.h" 27 #include "chrome/browser/chromeos/cros/cert_library.h"
30 #include "chrome/browser/chromeos/cros/cros_library.h" 28 #include "chrome/browser/chromeos/cros/cros_library.h"
31 #include "chrome/browser/chromeos/cros_settings.h" 29 #include "chrome/browser/chromeos/cros_settings.h"
32 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" 30 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h"
33 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 31 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
34 #include "chrome/browser/chromeos/login/default_user_images.h" 32 #include "chrome/browser/chromeos/login/default_user_images.h"
35 #include "chrome/browser/chromeos/login/helper.h" 33 #include "chrome/browser/chromeos/login/helper.h"
36 #include "chrome/browser/chromeos/login/login_display.h" 34 #include "chrome/browser/chromeos/login/login_display.h"
37 #include "chrome/browser/chromeos/login/ownership_service.h" 35 #include "chrome/browser/chromeos/login/ownership_service.h"
38 #include "chrome/browser/chromeos/login/remove_user_delegate.h" 36 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
39 #include "chrome/browser/chromeos/login/user_image.h" 37 #include "chrome/browser/chromeos/login/user_image.h"
40 #include "chrome/browser/chromeos/login/wizard_controller.h"
41 #include "chrome/browser/policy/browser_policy_connector.h" 38 #include "chrome/browser/policy/browser_policy_connector.h"
42 #include "chrome/browser/prefs/pref_service.h" 39 #include "chrome/browser/prefs/pref_service.h"
43 #include "chrome/browser/prefs/scoped_user_pref_update.h" 40 #include "chrome/browser/prefs/scoped_user_pref_update.h"
44 #include "chrome/browser/profiles/profile_downloader.h" 41 #include "chrome/browser/profiles/profile_downloader.h"
45 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
46 #include "chrome/browser/sync/profile_sync_service.h" 43 #include "chrome/browser/sync/profile_sync_service.h"
47 #include "chrome/browser/sync/profile_sync_service_factory.h" 44 #include "chrome/browser/sync/profile_sync_service_factory.h"
48 #include "chrome/browser/ui/webui/web_ui_util.h" 45 #include "chrome/browser/ui/webui/web_ui_util.h"
49 #include "chrome/common/chrome_notification_types.h" 46 #include "chrome/common/chrome_notification_types.h"
50 #include "chrome/common/chrome_paths.h" 47 #include "chrome/common/chrome_paths.h"
(...skipping 13 matching lines...) Expand all
64 61
65 namespace chromeos { 62 namespace chromeos {
66 63
67 namespace { 64 namespace {
68 65
69 // Names of nodes with info about user image. 66 // Names of nodes with info about user image.
70 const char kImagePathNodeName[] = "path"; 67 const char kImagePathNodeName[] = "path";
71 const char kImageIndexNodeName[] = "index"; 68 const char kImageIndexNodeName[] = "index";
72 const char kImageURLNodeName[] = "url"; 69 const char kImageURLNodeName[] = "url";
73 70
74 const char kWallpaperTypeNodeName[] = "type";
75 const char kWallpaperIndexNodeName[] = "index";
76 const char kWallpaperDateNodeName[] = "date";
77
78 // Default wallpaper index used in OOBE (first boot).
79 // Defined here because Chromium default index differs.
80 // Also see ash::WallpaperInfo kDefaultWallpapers in
81 // desktop_background_resources.cc
82 #if defined(GOOGLE_CHROME_BUILD)
83 const int kDefaultOOBEWallpaperIndex = 16; // IDR_AURA_WALLPAPERS_3_URBAN0
84 #else
85 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0
86 #endif
87
88 const int kThumbnailWidth = 128;
89 const int kThumbnailHeight = 80;
90
91 // Delay betweeen user login and attempt to update user's profile data. 71 // Delay betweeen user login and attempt to update user's profile data.
92 const long kProfileDataDownloadDelayMs = 10000; 72 const long kProfileDataDownloadDelayMs = 10000;
93 73
94 // Delay betweeen subsequent profile refresh attempts (24 hrs). 74 // Delay betweeen subsequent profile refresh attempts (24 hrs).
95 const long kProfileRefreshIntervalMs = 24L * 3600 * 1000; 75 const long kProfileRefreshIntervalMs = 24L * 3600 * 1000;
96 76
97 // Enum for reporting histograms about profile picture download. 77 // Enum for reporting histograms about profile picture download.
98 enum ProfileDownloadResult { 78 enum ProfileDownloadResult {
99 kDownloadSuccessChanged, 79 kDownloadSuccessChanged,
100 kDownloadSuccess, 80 kDownloadSuccess,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 185
206 } // namespace 186 } // namespace
207 187
208 UserManagerImpl::UserManagerImpl() 188 UserManagerImpl::UserManagerImpl()
209 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), 189 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)),
210 logged_in_user_(NULL), 190 logged_in_user_(NULL),
211 session_started_(false), 191 session_started_(false),
212 is_current_user_owner_(false), 192 is_current_user_owner_(false),
213 is_current_user_new_(false), 193 is_current_user_new_(false),
214 is_current_user_ephemeral_(false), 194 is_current_user_ephemeral_(false),
215 current_user_wallpaper_type_(User::UNKNOWN),
216 ALLOW_THIS_IN_INITIALIZER_LIST(current_user_wallpaper_index_(
217 ash::GetInvalidWallpaperIndex())),
218 ephemeral_users_enabled_(false), 195 ephemeral_users_enabled_(false),
219 observed_sync_service_(NULL), 196 observed_sync_service_(NULL),
220 last_image_set_async_(false), 197 last_image_set_async_(false),
221 downloaded_profile_image_data_url_(chrome::kAboutBlankURL), 198 downloaded_profile_image_data_url_(chrome::kAboutBlankURL),
222 downloading_profile_image_(false) { 199 downloading_profile_image_(false) {
223 // UserManager instance should be used only on UI thread. 200 // UserManager instance should be used only on UI thread.
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
225 202
226 MigrateWallpaperData(); 203 MigrateWallpaperData();
227 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, 204 registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 logged_in_user_ = *logged_in_user; 268 logged_in_user_ = *logged_in_user;
292 users_.erase(logged_in_user); 269 users_.erase(logged_in_user);
293 } 270 }
294 // This user must be in the front of the user list. 271 // This user must be in the front of the user list.
295 users_.insert(users_.begin(), logged_in_user_); 272 users_.insert(users_.begin(), logged_in_user_);
296 273
297 if (is_current_user_new_) { 274 if (is_current_user_new_) {
298 SaveUserDisplayName(GetLoggedInUser().email(), 275 SaveUserDisplayName(GetLoggedInUser().email(),
299 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true))); 276 UTF8ToUTF16(GetLoggedInUser().GetAccountName(true)));
300 SetInitialUserImage(email); 277 SetInitialUserImage(email);
301 SetInitialUserWallpaper(email); 278 WallpaperManager::Get()->SetInitialUserWallpaper(email);
302 } else { 279 } else {
303 int image_index = logged_in_user_->image_index(); 280 int image_index = logged_in_user_->image_index();
304 // If current user image is profile image, it needs to be refreshed. 281 // If current user image is profile image, it needs to be refreshed.
305 bool download_profile_image = image_index == User::kProfileImageIndex; 282 bool download_profile_image = image_index == User::kProfileImageIndex;
306 if (download_profile_image) 283 if (download_profile_image)
307 InitDownloadedProfileImage(); 284 InitDownloadedProfileImage();
308 285
309 // Download user's profile data (full name and optionally image) to see if 286 // Download user's profile data (full name and optionally image) to see if
310 // it has changed. 287 // it has changed.
311 BrowserThread::PostDelayedTask( 288 BrowserThread::PostDelayedTask(
(...skipping 21 matching lines...) Expand all
333 kHistogramImagesCount); 310 kHistogramImagesCount);
334 } 311 }
335 312
336 // Set up a repeating timer for refreshing the profile data. 313 // Set up a repeating timer for refreshing the profile data.
337 profile_download_timer_.Start( 314 profile_download_timer_.Start(
338 FROM_HERE, base::TimeDelta::FromMilliseconds(kProfileRefreshIntervalMs), 315 FROM_HERE, base::TimeDelta::FromMilliseconds(kProfileRefreshIntervalMs),
339 this, &UserManagerImpl::DownloadProfileDataScheduled); 316 this, &UserManagerImpl::DownloadProfileDataScheduled);
340 317
341 if (!browser_restart) { 318 if (!browser_restart) {
342 // For GAIA login flow, logged in user wallpaper may not be loaded. 319 // For GAIA login flow, logged in user wallpaper may not be loaded.
343 EnsureLoggedInUserWallpaperLoaded(); 320 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
344 } 321 }
345 322
346 NotifyOnLogin(); 323 NotifyOnLogin();
347 } 324 }
348 325
349 void UserManagerImpl::DemoUserLoggedIn() { 326 void UserManagerImpl::DemoUserLoggedIn() {
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
351 is_current_user_new_ = true; 328 is_current_user_new_ = true;
352 is_current_user_ephemeral_ = true; 329 is_current_user_ephemeral_ = true;
353 logged_in_user_ = CreateUser(kDemoUser, /* is_ephemeral= */ true); 330 logged_in_user_ = CreateUser(kDemoUser, /* is_ephemeral= */ true);
354 SetInitialUserImage(kDemoUser); 331 SetInitialUserImage(kDemoUser);
355 SetInitialUserWallpaper(kDemoUser); 332 WallpaperManager::Get()->SetInitialUserWallpaper(kDemoUser);
356 NotifyOnLogin(); 333 NotifyOnLogin();
357 } 334 }
358 335
359 void UserManagerImpl::GuestUserLoggedIn() { 336 void UserManagerImpl::GuestUserLoggedIn() {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 is_current_user_ephemeral_ = true; 338 is_current_user_ephemeral_ = true;
362 SetInitialUserWallpaper(kGuestUser); 339 WallpaperManager::Get()->SetInitialUserWallpaper(kGuestUser);
363 logged_in_user_ = CreateUser(kGuestUser, /* is_ephemeral= */ true); 340 logged_in_user_ = CreateUser(kGuestUser, /* is_ephemeral= */ true);
364 NotifyOnLogin(); 341 NotifyOnLogin();
365 } 342 }
366 343
367 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) { 344 void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 is_current_user_new_ = true; 346 is_current_user_new_ = true;
370 is_current_user_ephemeral_ = true; 347 is_current_user_ephemeral_ = true;
371 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ true); 348 logged_in_user_ = CreateUser(email, /* is_ephemeral= */ true);
372 SetInitialUserImage(email); 349 SetInitialUserImage(email);
373 SetInitialUserWallpaper(email); 350 WallpaperManager::Get()->SetInitialUserWallpaper(email);
374 NotifyOnLogin(); 351 NotifyOnLogin();
375 } 352 }
376 353
377 void UserManagerImpl::InitializeWallpaper() { 354 void UserManagerImpl::InitializeWallpaper() {
Ivan Korotkov 2012/07/27 23:02:02 Is this method still needed? Why can't caller user
bshe 2012/07/31 14:27:54 Done.
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 355 WallpaperManager::Get()->InitializeWallpaper();
379 if (!IsUserLoggedIn()) {
380 if (!CommandLine::ForCurrentProcess()->HasSwitch(
381 switches::kDisableNewOobe)) {
382 if (!WizardController::IsDeviceRegistered() &&
383 !WizardController::IsZeroDelayEnabled()) {
384 // TODO(nkostylev): Add switch to disable wallpaper transition on OOBE.
385 // Should be used on test images so that they are not slowed down.
386 ash::Shell::GetInstance()->desktop_background_controller()->
387 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
388 } else {
389 bool show_users = true;
390 bool result = CrosSettings::Get()->GetBoolean(
391 kAccountsPrefShowUserNamesOnSignIn, &show_users);
392 DCHECK(result) << "Unable to fetch setting "
393 << kAccountsPrefShowUserNamesOnSignIn;
394 if (!show_users) {
395 ash::Shell::GetInstance()->desktop_background_controller()->
396 SetDefaultWallpaper(ash::GetSolidColorIndex());
397 }
398 }
399 }
400 return;
401 }
402 UserSelected(GetLoggedInUser().email());
403 }
404
405 void UserManagerImpl::UserSelected(const std::string& email) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407 if (IsKnownUser(email)) {
408 User::WallpaperType type;
409 int index;
410 base::Time date;
411 GetUserWallpaperProperties(email, &type, &index, &date);
412 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) {
413 index = ash::GetNextWallpaperIndex(index);
414 SaveUserWallpaperProperties(email, User::DAILY, index);
415 } else if (type == User::CUSTOMIZED) {
416 std::string wallpaper_path =
417 GetWallpaperPathForUser(email, false).value();
418 // In customized mode, we use index pref to save the user selected
419 // wallpaper layout. See function SaveWallpaperToLocalState().
420 ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index);
421 // Load user image asynchronously.
422 image_loader_->Start(
423 wallpaper_path, 0, false,
424 base::Bind(&UserManagerImpl::OnCustomWallpaperLoaded,
425 base::Unretained(this), email, layout));
426 return;
427 }
428 ash::Shell::GetInstance()->desktop_background_controller()->
429 SetDefaultWallpaper(index);
430 WallpaperManager::Get()->SetLastSelectedUser(email);
431 }
432 } 356 }
433 357
434 void UserManagerImpl::SessionStarted() { 358 void UserManagerImpl::SessionStarted() {
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 session_started_ = true; 360 session_started_ = true;
437 content::NotificationService::current()->Notify( 361 content::NotificationService::current()->Notify(
438 chrome::NOTIFICATION_SESSION_STARTED, 362 chrome::NOTIFICATION_SESSION_STARTED,
439 content::NotificationService::AllSources(), 363 content::NotificationService::AllSources(),
440 content::NotificationService::NoDetails()); 364 content::NotificationService::NoDetails());
441 } 365 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // memory. Need a smarter way to solve this. 541 // memory. Need a smarter way to solve this.
618 if (IsCurrentUserEphemeral()) 542 if (IsCurrentUserEphemeral())
619 return; 543 return;
620 const chromeos::User& user = GetLoggedInUser(); 544 const chromeos::User& user = GetLoggedInUser();
621 std::string username = user.email(); 545 std::string username = user.email();
622 DCHECK(!username.empty()); 546 DCHECK(!username.empty());
623 547
624 std::string file_path = GetWallpaperPathForUser(username, false).value(); 548 std::string file_path = GetWallpaperPathForUser(username, false).value();
625 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); 549 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED);
626 // Load wallpaper from file. 550 // Load wallpaper from file.
627 UserSelected(username); 551 WallpaperManager::Get()->UserSelected(username);
628 } 552 }
629 553
630 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, 554 void UserManagerImpl::SaveUserImageFromFile(const std::string& username,
631 const FilePath& path) { 555 const FilePath& path) {
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
633 image_loader_->Start( 557 image_loader_->Start(
634 path.value(), login::kMaxUserImageSize, true, 558 path.value(), login::kMaxUserImageSize, true,
635 base::Bind(&UserManagerImpl::SaveUserImage, 559 base::Bind(&UserManagerImpl::SaveUserImage,
636 base::Unretained(this), username)); 560 base::Unretained(this), username));
637 } 561 }
638 562
639 void UserManagerImpl::SaveUserWallpaperFromFile(
640 const std::string& username,
641 const FilePath& path,
642 ash::WallpaperLayout layout,
643 base::WeakPtr<WallpaperDelegate> delegate) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
645 // For wallpapers, save the image without resizing.
646 image_loader_->Start(
647 path.value(), 0 /* Original size */, false,
648 base::Bind(&UserManagerImpl::SaveUserWallpaperInternal,
649 base::Unretained(this), username, layout, User::CUSTOMIZED,
650 delegate));
651 }
652
653 void UserManagerImpl::SaveUserImageFromProfileImage( 563 void UserManagerImpl::SaveUserImageFromProfileImage(
654 const std::string& username) { 564 const std::string& username) {
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
656 if (!downloaded_profile_image_.empty()) { 566 if (!downloaded_profile_image_.empty()) {
657 // Profile image has already been downloaded, so save it to file right now. 567 // Profile image has already been downloaded, so save it to file right now.
658 DCHECK(profile_image_url_.is_valid()); 568 DCHECK(profile_image_url_.is_valid());
659 SaveUserImageInternal(username, 569 SaveUserImageInternal(username,
660 User::kProfileImageIndex, profile_image_url_, 570 User::kProfileImageIndex, profile_image_url_,
661 UserImage(downloaded_profile_image_)); 571 UserImage(downloaded_profile_image_));
662 } else { 572 } else {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 int user_image_size = GetCurrentUserImageSize(); 735 int user_image_size = GetCurrentUserImageSize();
826 736
827 if (prefs_users) { 737 if (prefs_users) {
828 for (ListValue::const_iterator it = prefs_users->begin(); 738 for (ListValue::const_iterator it = prefs_users->begin();
829 it != prefs_users->end(); ++it) { 739 it != prefs_users->end(); ++it) {
830 std::string email; 740 std::string email;
831 if ((*it)->GetAsString(&email)) { 741 if ((*it)->GetAsString(&email)) {
832 User* user = CreateUser(email, /* is_ephemeral= */ false); 742 User* user = CreateUser(email, /* is_ephemeral= */ false);
833 users_.push_back(user); 743 users_.push_back(user);
834 744
745 WallpaperManager::Get()->CacheIfCustomWallpaper(email);
746
835 if (prefs_images) { 747 if (prefs_images) {
836 // Get account image path. 748 // Get account image path.
837 // TODO(avayvod): Reading image path as a string is here for 749 // TODO(avayvod): Reading image path as a string is here for
838 // backward compatibility. 750 // backward compatibility.
839 std::string image_path; 751 std::string image_path;
840 base::DictionaryValue* image_properties; 752 base::DictionaryValue* image_properties;
841 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { 753 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) {
842 int image_id = User::kInvalidImageIndex; 754 int image_id = User::kInvalidImageIndex;
843 if (IsDefaultImagePath(image_path, &image_id)) { 755 if (IsDefaultImagePath(image_path, &image_id)) {
844 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); 756 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (prefs_display_emails && 813 if (prefs_display_emails &&
902 prefs_display_emails->GetStringWithoutPathExpansion( 814 prefs_display_emails->GetStringWithoutPathExpansion(
903 email, &display_email)) { 815 email, &display_email)) {
904 user->set_display_email(display_email); 816 user->set_display_email(display_email);
905 } 817 }
906 } 818 }
907 } 819 }
908 } 820 }
909 } 821 }
910 822
911 void UserManagerImpl::EnsureLoggedInUserWallpaperLoaded() {
912 User::WallpaperType type;
913 int index;
914 base::Time last_modification_date;
915 GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date);
916
917 if (type != current_user_wallpaper_type_ ||
918 index != current_user_wallpaper_index_)
919 UserSelected(GetLoggedInUser().email());
920 }
921
922 void UserManagerImpl::RetrieveTrustedDevicePolicies() { 823 void UserManagerImpl::RetrieveTrustedDevicePolicies() {
923 ephemeral_users_enabled_ = false; 824 ephemeral_users_enabled_ = false;
924 owner_email_ = ""; 825 owner_email_ = "";
925 826
926 CrosSettings* cros_settings = CrosSettings::Get(); 827 CrosSettings* cros_settings = CrosSettings::Get();
927 // Schedule a callback if device policy has not yet been verified. 828 // Schedule a callback if device policy has not yet been verified.
928 if (CrosSettingsProvider::TRUSTED != cros_settings->PrepareTrustedValues( 829 if (CrosSettingsProvider::TRUSTED != cros_settings->PrepareTrustedValues(
929 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 830 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
930 base::Unretained(this)))) { 831 base::Unretained(this)))) {
931 return; 832 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 base::Bind(&UserManagerImpl::CheckOwnership, 914 base::Bind(&UserManagerImpl::CheckOwnership,
1014 base::Unretained(this))); 915 base::Unretained(this)));
1015 } 916 }
1016 917
1017 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 918 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
1018 // Choose a random default image. 919 // Choose a random default image.
1019 int image_id = base::RandInt(0, kDefaultImagesCount - 1); 920 int image_id = base::RandInt(0, kDefaultImagesCount - 1);
1020 SaveUserDefaultImageIndex(username, image_id); 921 SaveUserDefaultImageIndex(username, image_id);
1021 } 922 }
1022 923
1023 void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) {
1024 current_user_wallpaper_type_ = User::DEFAULT;
1025 // TODO(bshe): Ideally, wallpaper should start to load as soon as user click
1026 // "Add user".
1027 if (username == kGuestUser)
1028 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
1029 else
1030 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
1031 SaveUserWallpaperProperties(username,
1032 current_user_wallpaper_type_,
1033 current_user_wallpaper_index_);
1034
1035 // Some browser tests do not have shell instance. And it is not necessary to
1036 // create a wallpaper for these tests. Add HasInstance check to prevent tests
1037 // crash and speed up the tests by avoid loading wallpaper.
1038 if (ash::Shell::HasInstance()) {
1039 ash::Shell::GetInstance()->desktop_background_controller()->
1040 SetDefaultWallpaper(current_user_wallpaper_index_);
1041 }
1042 }
1043
1044 void UserManagerImpl::MigrateWallpaperData() { 924 void UserManagerImpl::MigrateWallpaperData() {
1045 PrefService* local_state = g_browser_process->local_state(); 925 PrefService* local_state = g_browser_process->local_state();
1046 if (local_state) { 926 if (local_state) {
1047 const DictionaryValue* user_wallpapers = 927 const DictionaryValue* user_wallpapers =
1048 local_state->GetDictionary(kUserWallpapers); 928 local_state->GetDictionary(kUserWallpapers);
1049 int index; 929 int index;
1050 const DictionaryValue* new_user_wallpapers = 930 const DictionaryValue* new_user_wallpapers =
1051 local_state->GetDictionary(kUserWallpapersProperties); 931 local_state->GetDictionary(kUserWallpapersProperties);
1052 if (new_user_wallpapers->empty()) { 932 if (new_user_wallpapers->empty()) {
1053 const UserList& users = GetUsers(); 933 const UserList& users = GetUsers();
1054 for (UserList::const_iterator it = users.begin(); 934 for (UserList::const_iterator it = users.begin();
1055 it != users.end(); 935 it != users.end();
1056 ++it) { 936 ++it) {
1057 std::string username = (*it)->email(); 937 std::string username = (*it)->email();
1058 if (user_wallpapers->GetIntegerWithoutPathExpansion((username), 938 if (user_wallpapers->GetIntegerWithoutPathExpansion((username),
1059 &index)) { 939 &index)) {
1060 DictionaryPrefUpdate prefs_wallpapers_update(local_state, 940 DictionaryPrefUpdate prefs_wallpapers_update(local_state,
1061 kUserWallpapers); 941 kUserWallpapers);
1062 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL); 942 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL);
1063 SaveUserWallpaperProperties(username, User::DEFAULT, index); 943 WallpaperManager::Get()->SaveUserWallpaperProperties(username,
944 User::DEFAULT,
945 index);
1064 } else { 946 } else {
1065 // Before M20, wallpaper index is not saved into LocalState unless 947 // Before M20, wallpaper index is not saved into LocalState unless
1066 // user specifically sets a wallpaper. After M20, the default 948 // user specifically sets a wallpaper. After M20, the default
1067 // wallpaper index is saved to LocalState as soon as a new user login. 949 // wallpaper index is saved to LocalState as soon as a new user login.
1068 // When migrating wallpaper index from M20 to M21, we only migrate 950 // When migrating wallpaper index from M20 to M21, we only migrate
1069 // data that is in LocalState. This cause a problem when users login 951 // data that is in LocalState. This cause a problem when users login
1070 // on a M20 device and then update the device to M21. The default 952 // on a M20 device and then update the device to M21. The default
1071 // wallpaper index failed to migrate because it was not saved into 953 // wallpaper index failed to migrate because it was not saved into
1072 // LocalState. Then we assume that all users have index saved in 954 // LocalState. Then we assume that all users have index saved in
1073 // LocalState in M21. This is not true and it results an empty 955 // LocalState in M21. This is not true and it results an empty
1074 // wallpaper for those users as described in cr/130685. So here we use 956 // wallpaper for those users as described in cr/130685. So here we use
1075 // default wallpaper for users that exist in user list but does not 957 // default wallpaper for users that exist in user list but does not
1076 // have an index saved in LocalState. 958 // have an index saved in LocalState.
1077 SaveUserWallpaperProperties(username, User::DEFAULT, 959 WallpaperManager::Get()->SaveUserWallpaperProperties(username,
1078 ash::GetDefaultWallpaperIndex()); 960 User::DEFAULT, ash::GetDefaultWallpaperIndex());
1079 } 961 }
1080 } 962 }
1081 } 963 }
1082 } 964 }
1083 } 965 }
1084 966
1085 void UserManagerImpl::GetLoggedInUserWallpaperProperties(
1086 User::WallpaperType* type,
1087 int* index,
1088 base::Time* last_modification_date) {
1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1090 DCHECK(logged_in_user_);
1091
1092 if (IsLoggedInAsStub()) {
1093 *type = current_user_wallpaper_type_ = User::DEFAULT;
1094 *index = current_user_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
1095 return;
1096 }
1097
1098 GetUserWallpaperProperties(GetLoggedInUser().email(),
1099 type,
1100 index,
1101 last_modification_date);
1102 }
1103
1104 void UserManagerImpl::SaveLoggedInUserWallpaperProperties( 967 void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
1105 User::WallpaperType type, 968 User::WallpaperType type, int index) {
1106 int index) { 969 WallpaperManager::Get()->SaveUserWallpaperProperties(
1107 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); 970 GetLoggedInUser().email(), type, index);
1108 } 971 }
1109 972
1110 void UserManagerImpl::SetUserImage(const std::string& username, 973 void UserManagerImpl::SetUserImage(const std::string& username,
1111 int image_index, 974 int image_index,
1112 const GURL& image_url, 975 const GURL& image_url,
1113 const UserImage& user_image) { 976 const UserImage& user_image) {
1114 User* user = const_cast<User*>(FindUser(username)); 977 User* user = const_cast<User*>(FindUser(username));
1115 // User may have been removed by now. 978 // User may have been removed by now.
1116 if (user) { 979 if (user) {
1117 // For existing users, a valid image index should have been set upon loading 980 // For existing users, a valid image index should have been set upon loading
(...skipping 14 matching lines...) Expand all
1132 // Unless this is first-time setting with |SetInitialUserImage|, 995 // Unless this is first-time setting with |SetInitialUserImage|,
1133 // send a notification about image change. 996 // send a notification about image change.
1134 content::NotificationService::current()->Notify( 997 content::NotificationService::current()->Notify(
1135 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 998 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
1136 content::Source<UserManagerImpl>(this), 999 content::Source<UserManagerImpl>(this),
1137 content::Details<const User>(user)); 1000 content::Details<const User>(user));
1138 } 1001 }
1139 } 1002 }
1140 } 1003 }
1141 1004
1142 void UserManagerImpl::GetUserWallpaperProperties(const std::string& username,
1143 User::WallpaperType* type,
1144 int* index,
1145 base::Time* last_modification_date) {
1146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1147
1148 // Default to the values cached in memory.
1149 *type = current_user_wallpaper_type_;
1150 *index = current_user_wallpaper_index_;
1151
1152 // Override with values found in local store, if any.
1153 if (!username.empty()) {
1154 const DictionaryValue* user_wallpapers = g_browser_process->local_state()->
1155 GetDictionary(UserManager::kUserWallpapersProperties);
1156 base::DictionaryValue* wallpaper_properties;
1157 if (user_wallpapers->GetDictionaryWithoutPathExpansion(
1158 username,
1159 &wallpaper_properties)) {
1160 *type = User::UNKNOWN;
1161 *index = ash::GetInvalidWallpaperIndex();
1162 wallpaper_properties->GetInteger(kWallpaperTypeNodeName,
1163 reinterpret_cast<int*>(type));
1164 wallpaper_properties->GetInteger(kWallpaperIndexNodeName, index);
1165 std::string date_string;
1166 int64 val;
1167 if (!(wallpaper_properties->GetString(kWallpaperDateNodeName,
1168 &date_string) &&
1169 base::StringToInt64(date_string, &val)))
1170 val = 0;
1171 *last_modification_date = base::Time::FromInternalValue(val);
1172 }
1173 }
1174 }
1175
1176 void UserManagerImpl::SaveUserWallpaperProperties(const std::string& username,
1177 User::WallpaperType type,
1178 int index) {
1179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1180
1181 current_user_wallpaper_type_ = type;
1182 current_user_wallpaper_index_ = index;
1183 // Ephemeral users can not save data to local state. We just cache the index
1184 // in memory for them.
1185 if (IsCurrentUserEphemeral()) {
1186 return;
1187 }
1188
1189 PrefService* local_state = g_browser_process->local_state();
1190 DictionaryPrefUpdate wallpaper_update(local_state,
1191 UserManager::kUserWallpapersProperties);
1192
1193 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
1194 wallpaper_properties->Set(kWallpaperTypeNodeName,
1195 new base::FundamentalValue(type));
1196 wallpaper_properties->Set(kWallpaperIndexNodeName,
1197 new base::FundamentalValue(index));
1198 wallpaper_properties->SetString(kWallpaperDateNodeName,
1199 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
1200 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties);
1201 }
1202
1203 void UserManagerImpl::SaveUserImageInternal(const std::string& username, 1005 void UserManagerImpl::SaveUserImageInternal(const std::string& username,
1204 int image_index, 1006 int image_index,
1205 const GURL& image_url, 1007 const GURL& image_url,
1206 const UserImage& user_image) { 1008 const UserImage& user_image) {
1207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1009 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1208 1010
1209 SetUserImage(username, image_index, image_url, user_image); 1011 SetUserImage(username, image_index, image_url, user_image);
1210 1012
1211 // Ignore for ephemeral users. 1013 // Ignore for ephemeral users.
1212 if (IsEphemeralUser(username)) 1014 if (IsEphemeralUser(username))
1213 return; 1015 return;
1214 1016
1215 FilePath image_path = GetImagePathForUser(username); 1017 FilePath image_path = GetImagePathForUser(username);
1216 DVLOG(1) << "Saving user image to " << image_path.value(); 1018 DVLOG(1) << "Saving user image to " << image_path.value();
1217 1019
1218 last_image_set_async_ = true; 1020 last_image_set_async_ = true;
1219 1021
1220 BrowserThread::PostTask( 1022 BrowserThread::PostTask(
1221 BrowserThread::FILE, 1023 BrowserThread::FILE,
1222 FROM_HERE, 1024 FROM_HERE,
1223 base::Bind(&UserManagerImpl::SaveImageToFile, 1025 base::Bind(&UserManagerImpl::SaveImageToFile,
1224 base::Unretained(this), 1026 base::Unretained(this),
1225 username, user_image, image_path, image_index, image_url)); 1027 username, user_image, image_path, image_index, image_url));
1226 } 1028 }
1227 1029
1228 void UserManagerImpl::SaveUserWallpaperInternal(
1229 const std::string& username,
1230 ash::WallpaperLayout layout,
1231 User::WallpaperType type,
1232 base::WeakPtr<WallpaperDelegate> delegate,
1233 const UserImage& user_image) {
1234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1235
1236 const SkBitmap& wallpaper = user_image.image();
1237 BrowserThread::PostTask(
1238 BrowserThread::FILE,
1239 FROM_HERE,
1240 base::Bind(&UserManagerImpl::GenerateUserWallpaperThumbnail,
1241 base::Unretained(this), username, type, delegate, wallpaper));
1242
1243 ash::Shell::GetInstance()->desktop_background_controller()->
1244 SetCustomWallpaper(wallpaper, layout);
1245
1246 // Ignore for ephemeral users.
1247 if (IsEphemeralUser(username))
1248 return;
1249
1250 FilePath wallpaper_path = GetWallpaperPathForUser(username, false);
1251 DVLOG(1) << "Saving user image to " << wallpaper_path.value();
1252
1253 last_image_set_async_ = true;
1254
1255 BrowserThread::PostTask(
1256 BrowserThread::FILE,
1257 FROM_HERE,
1258 base::Bind(&UserManagerImpl::SaveWallpaperToFile,
1259 base::Unretained(this), username, wallpaper, wallpaper_path,
1260 layout, User::CUSTOMIZED));
1261 }
1262
1263 void UserManagerImpl::OnCustomWallpaperLoaded(const std::string& email,
1264 ash::WallpaperLayout layout,
1265 const UserImage& user_image) {
1266 const SkBitmap& wallpaper = user_image.image();
1267 ash::Shell::GetInstance()->desktop_background_controller()->
1268 SetCustomWallpaper(wallpaper, layout);
1269 // Starting to load wallpaper thumbnail
1270 std::string wallpaper_thumbnail_path =
1271 GetWallpaperPathForUser(email, true).value();
1272 image_loader_->Start(
1273 wallpaper_thumbnail_path, 0, false,
1274 base::Bind(&UserManagerImpl::OnCustomWallpaperThumbnailLoaded,
1275 base::Unretained(this), email));
1276 }
1277
1278 void UserManagerImpl::OnCustomWallpaperThumbnailLoaded(
1279 const std::string& email,
1280 const UserImage& user_image) {
1281 const SkBitmap& wallpaper = user_image.image();
1282 User* user = const_cast<User*>(FindUser(email));
1283 // User may have been removed by now.
1284 if (user && !wallpaper.empty())
1285 user->SetWallpaperThumbnail(wallpaper);
1286 }
1287
1288 void UserManagerImpl::OnThumbnailUpdated(
1289 base::WeakPtr<WallpaperDelegate> delegate) {
1290 if (delegate)
1291 delegate->SetCustomWallpaperThumbnail();
1292 }
1293
1294 void UserManagerImpl::GenerateUserWallpaperThumbnail(
1295 const std::string& username,
1296 User::WallpaperType type,
1297 base::WeakPtr<WallpaperDelegate> delegate,
1298 const SkBitmap& wallpaper) {
1299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1300 SkBitmap thumbnail =
1301 skia::ImageOperations::Resize(wallpaper,
1302 skia::ImageOperations::RESIZE_LANCZOS3,
1303 kThumbnailWidth, kThumbnailHeight);
1304 logged_in_user_->SetWallpaperThumbnail(thumbnail);
1305
1306 // Notify thumbnail is ready.
1307 BrowserThread::PostTask(
1308 BrowserThread::UI,
1309 FROM_HERE,
1310 base::Bind(&UserManagerImpl::OnThumbnailUpdated,
1311 base::Unretained(this), delegate));
1312
1313 // Ignore for ephemeral users.
1314 if (IsEphemeralUser(username))
1315 return;
1316
1317 FilePath thumbnail_path = GetWallpaperPathForUser(username, true);
1318 SaveBitmapToFile(UserImage(thumbnail), thumbnail_path);
1319 }
1320
1321 void UserManagerImpl::SaveImageToFile(const std::string& username, 1030 void UserManagerImpl::SaveImageToFile(const std::string& username,
1322 const UserImage& user_image, 1031 const UserImage& user_image,
1323 const FilePath& image_path, 1032 const FilePath& image_path,
1324 int image_index, 1033 int image_index,
1325 const GURL& image_url) { 1034 const GURL& image_url) {
1326 if (!SaveBitmapToFile(user_image, image_path)) 1035 if (!SaveBitmapToFile(user_image, image_path))
1327 return; 1036 return;
1328 1037
1329 BrowserThread::PostTask( 1038 BrowserThread::PostTask(
1330 BrowserThread::UI, 1039 BrowserThread::UI,
1331 FROM_HERE, 1040 FROM_HERE,
1332 base::Bind(&UserManagerImpl::SaveImageToLocalState, 1041 base::Bind(&UserManagerImpl::SaveImageToLocalState,
1333 base::Unretained(this), 1042 base::Unretained(this),
1334 username, image_path.value(), image_index, image_url, true)); 1043 username, image_path.value(), image_index, image_url, true));
1335 } 1044 }
1336 1045
1337 void UserManagerImpl::SaveWallpaperToFile(const std::string& username,
1338 const SkBitmap& wallpaper,
1339 const FilePath& wallpaper_path,
1340 ash::WallpaperLayout layout,
1341 User::WallpaperType type) {
1342 // TODO(bshe): We should save the original file unchanged instead of
1343 // re-encoding it and saving it.
1344 if (!SaveBitmapToFile(UserImage(wallpaper), wallpaper_path))
1345 return;
1346
1347 BrowserThread::PostTask(
1348 BrowserThread::UI,
1349 FROM_HERE,
1350 base::Bind(&UserManagerImpl::SaveWallpaperToLocalState,
1351 base::Unretained(this),
1352 username, wallpaper_path.value(), layout, type));
1353 }
1354
1355 void UserManagerImpl::SaveImageToLocalState(const std::string& username, 1046 void UserManagerImpl::SaveImageToLocalState(const std::string& username,
1356 const std::string& image_path, 1047 const std::string& image_path,
1357 int image_index, 1048 int image_index,
1358 const GURL& image_url, 1049 const GURL& image_url,
1359 bool is_async) { 1050 bool is_async) {
1360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1051 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1361 1052
1362 // Ignore for ephemeral users. 1053 // Ignore for ephemeral users.
1363 if (IsEphemeralUser(username)) 1054 if (IsEphemeralUser(username))
1364 return; 1055 return;
(...skipping 25 matching lines...) Expand all
1390 DVLOG(1) << "Saving path to user image in Local State."; 1081 DVLOG(1) << "Saving path to user image in Local State.";
1391 1082
1392 NotifyLocalStateChanged(); 1083 NotifyLocalStateChanged();
1393 } 1084 }
1394 1085
1395 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, 1086 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username,
1396 const std::string& wallpaper_path, 1087 const std::string& wallpaper_path,
1397 ash::WallpaperLayout layout, 1088 ash::WallpaperLayout layout,
1398 User::WallpaperType type) { 1089 User::WallpaperType type) {
1399 // TODO(bshe): We probably need to save wallpaper_path instead of index. 1090 // TODO(bshe): We probably need to save wallpaper_path instead of index.
1400 SaveUserWallpaperProperties(username, type, layout); 1091 WallpaperManager::Get()->SaveUserWallpaperProperties(username, type, layout);
1401 } 1092 }
1402 1093
1403 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, 1094 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image,
1404 const FilePath& image_path) { 1095 const FilePath& image_path) {
1405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1096 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1406 1097
1407 const UserImage::RawImage* encoded_image = NULL; 1098 const UserImage::RawImage* encoded_image = NULL;
1408 if (user_image.has_animated_image()) { 1099 if (user_image.has_animated_image()) {
1409 encoded_image = &user_image.animated_image(); 1100 encoded_image = &user_image.animated_image();
1410 } else if (user_image.has_raw_image()) { 1101 } else if (user_image.has_raw_image()) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 BrowserThread::PostTask( 1380 BrowserThread::PostTask(
1690 BrowserThread::FILE, 1381 BrowserThread::FILE,
1691 FROM_HERE, 1382 FROM_HERE,
1692 base::Bind(&UserManagerImpl::DeleteUserImage, 1383 base::Bind(&UserManagerImpl::DeleteUserImage,
1693 base::Unretained(this), 1384 base::Unretained(this),
1694 image_path)); 1385 image_path));
1695 } 1386 }
1696 } 1387 }
1697 1388
1698 } // namespace chromeos 1389 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698