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

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: Ivan's review Created 8 years, 4 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() {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
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 }
433
434 void UserManagerImpl::SessionStarted() { 354 void UserManagerImpl::SessionStarted() {
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 session_started_ = true; 356 session_started_ = true;
437 content::NotificationService::current()->Notify( 357 content::NotificationService::current()->Notify(
438 chrome::NOTIFICATION_SESSION_STARTED, 358 chrome::NOTIFICATION_SESSION_STARTED,
439 content::NotificationService::AllSources(), 359 content::NotificationService::AllSources(),
440 content::NotificationService::NoDetails()); 360 content::NotificationService::NoDetails());
441 } 361 }
442 362
443 void UserManagerImpl::RemoveUser(const std::string& email, 363 void UserManagerImpl::RemoveUser(const std::string& email,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 534
615 // TODO(bshe): We current disabled the customized wallpaper feature for 535 // TODO(bshe): We current disabled the customized wallpaper feature for
616 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in 536 // Ephemeral user. As we dont want to keep a copy of customized wallpaper in
617 // memory. Need a smarter way to solve this. 537 // memory. Need a smarter way to solve this.
618 if (IsCurrentUserEphemeral()) 538 if (IsCurrentUserEphemeral())
619 return; 539 return;
620 const chromeos::User& user = GetLoggedInUser(); 540 const chromeos::User& user = GetLoggedInUser();
621 std::string username = user.email(); 541 std::string username = user.email();
622 DCHECK(!username.empty()); 542 DCHECK(!username.empty());
623 543
624 std::string file_path = GetWallpaperPathForUser(username, false).value(); 544 std::string file_path = WallpaperManager::Get()->
545 GetWallpaperPathForUser(username, false).value();
625 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED); 546 SaveWallpaperToLocalState(username, file_path, layout, User::CUSTOMIZED);
626 // Load wallpaper from file. 547 // Load wallpaper from file.
627 UserSelected(username); 548 WallpaperManager::Get()->OnUserSelected(username);
628 } 549 }
629 550
630 void UserManagerImpl::SaveUserImageFromFile(const std::string& username, 551 void UserManagerImpl::SaveUserImageFromFile(const std::string& username,
631 const FilePath& path) { 552 const FilePath& path) {
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
633 image_loader_->Start( 554 image_loader_->Start(
634 path.value(), login::kMaxUserImageSize, true, 555 path.value(), login::kMaxUserImageSize, true,
635 base::Bind(&UserManagerImpl::SaveUserImage, 556 base::Bind(&UserManagerImpl::SaveUserImage,
636 base::Unretained(this), username)); 557 base::Unretained(this), username));
637 } 558 }
638 559
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( 560 void UserManagerImpl::SaveUserImageFromProfileImage(
654 const std::string& username) { 561 const std::string& username) {
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
656 if (!downloaded_profile_image_.empty()) { 563 if (!downloaded_profile_image_.empty()) {
657 // Profile image has already been downloaded, so save it to file right now. 564 // Profile image has already been downloaded, so save it to file right now.
658 DCHECK(profile_image_url_.is_valid()); 565 DCHECK(profile_image_url_.is_valid());
659 SaveUserImageInternal(username, 566 SaveUserImageInternal(username,
660 User::kProfileImageIndex, profile_image_url_, 567 User::kProfileImageIndex, profile_image_url_,
661 UserImage(downloaded_profile_image_)); 568 UserImage(downloaded_profile_image_));
662 } else { 569 } else {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 LocalStateChanged(this)); 696 LocalStateChanged(this));
790 } 697 }
791 698
792 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) { 699 FilePath UserManagerImpl::GetImagePathForUser(const std::string& username) {
793 std::string filename = username + ".png"; 700 std::string filename = username + ".png";
794 FilePath user_data_dir; 701 FilePath user_data_dir;
795 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 702 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
796 return user_data_dir.AppendASCII(filename); 703 return user_data_dir.AppendASCII(filename);
797 } 704 }
798 705
799 FilePath UserManagerImpl::GetWallpaperPathForUser(const std::string& username,
800 bool is_thumbnail) {
801 std::string filename = username +
802 (is_thumbnail ? "_wallpaper_thumb.png" : "_wallpaper.png");
803 FilePath user_data_dir;
804 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
805 return user_data_dir.AppendASCII(filename);
806 }
807
808 void UserManagerImpl::EnsureUsersLoaded() { 706 void UserManagerImpl::EnsureUsersLoaded() {
809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
810 if (!users_.empty()) 708 if (!users_.empty())
811 return; 709 return;
812 if (!g_browser_process) 710 if (!g_browser_process)
813 return; 711 return;
814 712
815 PrefService* local_state = g_browser_process->local_state(); 713 PrefService* local_state = g_browser_process->local_state();
816 const ListValue* prefs_users = 714 const ListValue* prefs_users =
817 local_state->GetList(UserManager::kLoggedInUsers); 715 local_state->GetList(UserManager::kLoggedInUsers);
818 const DictionaryValue* prefs_images = 716 const DictionaryValue* prefs_images =
819 local_state->GetDictionary(UserManager::kUserImages); 717 local_state->GetDictionary(UserManager::kUserImages);
820 const DictionaryValue* prefs_display_names = 718 const DictionaryValue* prefs_display_names =
821 local_state->GetDictionary(UserManager::kUserDisplayName); 719 local_state->GetDictionary(UserManager::kUserDisplayName);
822 const DictionaryValue* prefs_display_emails = 720 const DictionaryValue* prefs_display_emails =
823 local_state->GetDictionary(UserManager::kUserDisplayEmail); 721 local_state->GetDictionary(UserManager::kUserDisplayEmail);
824 722
825 int user_image_size = GetCurrentUserImageSize(); 723 int user_image_size = GetCurrentUserImageSize();
826 724
827 if (prefs_users) { 725 if (prefs_users) {
828 for (ListValue::const_iterator it = prefs_users->begin(); 726 for (ListValue::const_iterator it = prefs_users->begin();
829 it != prefs_users->end(); ++it) { 727 it != prefs_users->end(); ++it) {
830 std::string email; 728 std::string email;
831 if ((*it)->GetAsString(&email)) { 729 if ((*it)->GetAsString(&email)) {
832 User* user = CreateUser(email, /* is_ephemeral= */ false); 730 User* user = CreateUser(email, /* is_ephemeral= */ false);
833 users_.push_back(user); 731 users_.push_back(user);
834 732
733 WallpaperManager::Get()->CacheIfCustomWallpaper(email);
734
835 if (prefs_images) { 735 if (prefs_images) {
836 // Get account image path. 736 // Get account image path.
837 // TODO(avayvod): Reading image path as a string is here for 737 // TODO(avayvod): Reading image path as a string is here for
838 // backward compatibility. 738 // backward compatibility.
839 std::string image_path; 739 std::string image_path;
840 const base::DictionaryValue* image_properties; 740 const base::DictionaryValue* image_properties;
841 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) { 741 if (prefs_images->GetStringWithoutPathExpansion(email, &image_path)) {
842 int image_id = User::kInvalidImageIndex; 742 int image_id = User::kInvalidImageIndex;
843 if (IsDefaultImagePath(image_path, &image_id)) { 743 if (IsDefaultImagePath(image_path, &image_id)) {
844 user->SetImage(UserImage(GetDefaultImage(image_id)), image_id); 744 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 && 801 if (prefs_display_emails &&
902 prefs_display_emails->GetStringWithoutPathExpansion( 802 prefs_display_emails->GetStringWithoutPathExpansion(
903 email, &display_email)) { 803 email, &display_email)) {
904 user->set_display_email(display_email); 804 user->set_display_email(display_email);
905 } 805 }
906 } 806 }
907 } 807 }
908 } 808 }
909 } 809 }
910 810
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() { 811 void UserManagerImpl::RetrieveTrustedDevicePolicies() {
923 ephemeral_users_enabled_ = false; 812 ephemeral_users_enabled_ = false;
924 owner_email_ = ""; 813 owner_email_ = "";
925 814
926 CrosSettings* cros_settings = CrosSettings::Get(); 815 CrosSettings* cros_settings = CrosSettings::Get();
927 // Schedule a callback if device policy has not yet been verified. 816 // Schedule a callback if device policy has not yet been verified.
928 if (CrosSettingsProvider::TRUSTED != cros_settings->PrepareTrustedValues( 817 if (CrosSettingsProvider::TRUSTED != cros_settings->PrepareTrustedValues(
929 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, 818 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies,
930 base::Unretained(this)))) { 819 base::Unretained(this)))) {
931 return; 820 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 base::Bind(&UserManagerImpl::CheckOwnership, 902 base::Bind(&UserManagerImpl::CheckOwnership,
1014 base::Unretained(this))); 903 base::Unretained(this)));
1015 } 904 }
1016 905
1017 void UserManagerImpl::SetInitialUserImage(const std::string& username) { 906 void UserManagerImpl::SetInitialUserImage(const std::string& username) {
1018 // Choose a random default image. 907 // Choose a random default image.
1019 int image_id = base::RandInt(0, kDefaultImagesCount - 1); 908 int image_id = base::RandInt(0, kDefaultImagesCount - 1);
1020 SaveUserDefaultImageIndex(username, image_id); 909 SaveUserDefaultImageIndex(username, image_id);
1021 } 910 }
1022 911
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() { 912 void UserManagerImpl::MigrateWallpaperData() {
1045 PrefService* local_state = g_browser_process->local_state(); 913 PrefService* local_state = g_browser_process->local_state();
1046 if (local_state) { 914 if (local_state) {
1047 const DictionaryValue* user_wallpapers = 915 const DictionaryValue* user_wallpapers =
1048 local_state->GetDictionary(kUserWallpapers); 916 local_state->GetDictionary(kUserWallpapers);
1049 int index; 917 int index;
1050 const DictionaryValue* new_user_wallpapers = 918 const DictionaryValue* new_user_wallpapers =
1051 local_state->GetDictionary(kUserWallpapersProperties); 919 local_state->GetDictionary(kUserWallpapersProperties);
1052 if (new_user_wallpapers->empty()) { 920 if (new_user_wallpapers->empty()) {
1053 const UserList& users = GetUsers(); 921 const UserList& users = GetUsers();
1054 for (UserList::const_iterator it = users.begin(); 922 for (UserList::const_iterator it = users.begin();
1055 it != users.end(); 923 it != users.end();
1056 ++it) { 924 ++it) {
1057 std::string username = (*it)->email(); 925 std::string username = (*it)->email();
1058 if (user_wallpapers->GetIntegerWithoutPathExpansion((username), 926 if (user_wallpapers->GetIntegerWithoutPathExpansion((username),
1059 &index)) { 927 &index)) {
1060 DictionaryPrefUpdate prefs_wallpapers_update(local_state, 928 DictionaryPrefUpdate prefs_wallpapers_update(local_state,
1061 kUserWallpapers); 929 kUserWallpapers);
1062 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL); 930 prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL);
1063 SaveUserWallpaperProperties(username, User::DEFAULT, index); 931 WallpaperManager::Get()->SaveUserWallpaperProperties(username,
932 User::DEFAULT,
933 index);
1064 } else { 934 } else {
1065 // Before M20, wallpaper index is not saved into LocalState unless 935 // Before M20, wallpaper index is not saved into LocalState unless
1066 // user specifically sets a wallpaper. After M20, the default 936 // user specifically sets a wallpaper. After M20, the default
1067 // wallpaper index is saved to LocalState as soon as a new user login. 937 // 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 938 // When migrating wallpaper index from M20 to M21, we only migrate
1069 // data that is in LocalState. This cause a problem when users login 939 // 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 940 // 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 941 // wallpaper index failed to migrate because it was not saved into
1072 // LocalState. Then we assume that all users have index saved in 942 // LocalState. Then we assume that all users have index saved in
1073 // LocalState in M21. This is not true and it results an empty 943 // 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 944 // 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 945 // default wallpaper for users that exist in user list but does not
1076 // have an index saved in LocalState. 946 // have an index saved in LocalState.
1077 SaveUserWallpaperProperties(username, User::DEFAULT, 947 WallpaperManager::Get()->SaveUserWallpaperProperties(username,
1078 ash::GetDefaultWallpaperIndex()); 948 User::DEFAULT, ash::GetDefaultWallpaperIndex());
1079 } 949 }
1080 } 950 }
1081 } 951 }
1082 } 952 }
1083 } 953 }
1084 954
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( 955 void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
1105 User::WallpaperType type, 956 User::WallpaperType type, int index) {
1106 int index) { 957 WallpaperManager::Get()->SaveUserWallpaperProperties(
1107 SaveUserWallpaperProperties(GetLoggedInUser().email(), type, index); 958 GetLoggedInUser().email(), type, index);
1108 } 959 }
1109 960
1110 void UserManagerImpl::SetUserImage(const std::string& username, 961 void UserManagerImpl::SetUserImage(const std::string& username,
1111 int image_index, 962 int image_index,
1112 const GURL& image_url, 963 const GURL& image_url,
1113 const UserImage& user_image) { 964 const UserImage& user_image) {
1114 User* user = const_cast<User*>(FindUser(username)); 965 User* user = const_cast<User*>(FindUser(username));
1115 // User may have been removed by now. 966 // User may have been removed by now.
1116 if (user) { 967 if (user) {
1117 // For existing users, a valid image index should have been set upon loading 968 // 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|, 983 // Unless this is first-time setting with |SetInitialUserImage|,
1133 // send a notification about image change. 984 // send a notification about image change.
1134 content::NotificationService::current()->Notify( 985 content::NotificationService::current()->Notify(
1135 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 986 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
1136 content::Source<UserManagerImpl>(this), 987 content::Source<UserManagerImpl>(this),
1137 content::Details<const User>(user)); 988 content::Details<const User>(user));
1138 } 989 }
1139 } 990 }
1140 } 991 }
1141 992
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 const 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, 993 void UserManagerImpl::SaveUserImageInternal(const std::string& username,
1204 int image_index, 994 int image_index,
1205 const GURL& image_url, 995 const GURL& image_url,
1206 const UserImage& user_image) { 996 const UserImage& user_image) {
1207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1208 998
1209 SetUserImage(username, image_index, image_url, user_image); 999 SetUserImage(username, image_index, image_url, user_image);
1210 1000
1211 // Ignore for ephemeral users. 1001 // Ignore for ephemeral users.
1212 if (IsEphemeralUser(username)) 1002 if (IsEphemeralUser(username))
1213 return; 1003 return;
1214 1004
1215 FilePath image_path = GetImagePathForUser(username); 1005 FilePath image_path = GetImagePathForUser(username);
1216 DVLOG(1) << "Saving user image to " << image_path.value(); 1006 DVLOG(1) << "Saving user image to " << image_path.value();
1217 1007
1218 last_image_set_async_ = true; 1008 last_image_set_async_ = true;
1219 1009
1220 BrowserThread::PostTask( 1010 BrowserThread::PostTask(
1221 BrowserThread::FILE, 1011 BrowserThread::FILE,
1222 FROM_HERE, 1012 FROM_HERE,
1223 base::Bind(&UserManagerImpl::SaveImageToFile, 1013 base::Bind(&UserManagerImpl::SaveImageToFile,
1224 base::Unretained(this), 1014 base::Unretained(this),
1225 username, user_image, image_path, image_index, image_url)); 1015 username, user_image, image_path, image_index, image_url));
1226 } 1016 }
1227 1017
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, 1018 void UserManagerImpl::SaveImageToFile(const std::string& username,
1322 const UserImage& user_image, 1019 const UserImage& user_image,
1323 const FilePath& image_path, 1020 const FilePath& image_path,
1324 int image_index, 1021 int image_index,
1325 const GURL& image_url) { 1022 const GURL& image_url) {
1326 if (!SaveBitmapToFile(user_image, image_path)) 1023 if (!SaveBitmapToFile(user_image, image_path))
1327 return; 1024 return;
1328 1025
1329 BrowserThread::PostTask( 1026 BrowserThread::PostTask(
1330 BrowserThread::UI, 1027 BrowserThread::UI,
1331 FROM_HERE, 1028 FROM_HERE,
1332 base::Bind(&UserManagerImpl::SaveImageToLocalState, 1029 base::Bind(&UserManagerImpl::SaveImageToLocalState,
1333 base::Unretained(this), 1030 base::Unretained(this),
1334 username, image_path.value(), image_index, image_url, true)); 1031 username, image_path.value(), image_index, image_url, true));
1335 } 1032 }
1336 1033
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, 1034 void UserManagerImpl::SaveImageToLocalState(const std::string& username,
1356 const std::string& image_path, 1035 const std::string& image_path,
1357 int image_index, 1036 int image_index,
1358 const GURL& image_url, 1037 const GURL& image_url,
1359 bool is_async) { 1038 bool is_async) {
1360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1361 1040
1362 // Ignore for ephemeral users. 1041 // Ignore for ephemeral users.
1363 if (IsEphemeralUser(username)) 1042 if (IsEphemeralUser(username))
1364 return; 1043 return;
(...skipping 25 matching lines...) Expand all
1390 DVLOG(1) << "Saving path to user image in Local State."; 1069 DVLOG(1) << "Saving path to user image in Local State.";
1391 1070
1392 NotifyLocalStateChanged(); 1071 NotifyLocalStateChanged();
1393 } 1072 }
1394 1073
1395 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username, 1074 void UserManagerImpl::SaveWallpaperToLocalState(const std::string& username,
1396 const std::string& wallpaper_path, 1075 const std::string& wallpaper_path,
1397 ash::WallpaperLayout layout, 1076 ash::WallpaperLayout layout,
1398 User::WallpaperType type) { 1077 User::WallpaperType type) {
1399 // TODO(bshe): We probably need to save wallpaper_path instead of index. 1078 // TODO(bshe): We probably need to save wallpaper_path instead of index.
1400 SaveUserWallpaperProperties(username, type, layout); 1079 WallpaperManager::Get()->SaveUserWallpaperProperties(username, type, layout);
1401 } 1080 }
1402 1081
1403 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image, 1082 bool UserManagerImpl::SaveBitmapToFile(const UserImage& user_image,
1404 const FilePath& image_path) { 1083 const FilePath& image_path) {
1405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1406 1085
1407 const UserImage::RawImage* encoded_image = NULL; 1086 const UserImage::RawImage* encoded_image = NULL;
1408 if (user_image.has_animated_image()) { 1087 if (user_image.has_animated_image()) {
1409 encoded_image = &user_image.animated_image(); 1088 encoded_image = &user_image.animated_image();
1410 } else if (user_image.has_raw_image()) { 1089 } else if (user_image.has_raw_image()) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 prefs_users_update->Append(Value::CreateStringValue(user_email)); 1317 prefs_users_update->Append(Value::CreateStringValue(user_email));
1639 else 1318 else
1640 user_to_remove = it; 1319 user_to_remove = it;
1641 } 1320 }
1642 1321
1643 DictionaryPrefUpdate prefs_wallpapers_update(prefs, 1322 DictionaryPrefUpdate prefs_wallpapers_update(prefs,
1644 kUserWallpapersProperties); 1323 kUserWallpapersProperties);
1645 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL); 1324 prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL);
1646 1325
1647 // Remove user wallpaper thumbnail 1326 // Remove user wallpaper thumbnail
1648 FilePath wallpaper_thumb_path = GetWallpaperPathForUser(email, true); 1327 FilePath wallpaper_thumb_path = WallpaperManager::Get()->
1328 GetWallpaperPathForUser(email, true);
1649 BrowserThread::PostTask( 1329 BrowserThread::PostTask(
1650 BrowserThread::FILE, 1330 BrowserThread::FILE,
1651 FROM_HERE, 1331 FROM_HERE,
1652 base::Bind(&UserManagerImpl::DeleteUserImage, 1332 base::Bind(&UserManagerImpl::DeleteUserImage,
1653 base::Unretained(this), 1333 base::Unretained(this),
1654 wallpaper_thumb_path)); 1334 wallpaper_thumb_path));
1655 // Remove user wallpaper 1335 // Remove user wallpaper
1656 FilePath wallpaper_path = GetWallpaperPathForUser(email, false); 1336 FilePath wallpaper_path = WallpaperManager::Get()->
1337 GetWallpaperPathForUser(email, false);
1657 BrowserThread::PostTask( 1338 BrowserThread::PostTask(
1658 BrowserThread::FILE, 1339 BrowserThread::FILE,
1659 FROM_HERE, 1340 FROM_HERE,
1660 base::Bind(&UserManagerImpl::DeleteUserImage, 1341 base::Bind(&UserManagerImpl::DeleteUserImage,
1661 base::Unretained(this), 1342 base::Unretained(this),
1662 wallpaper_path)); 1343 wallpaper_path));
1663 1344
1664 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); 1345 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages);
1665 std::string image_path_string; 1346 std::string image_path_string;
1666 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); 1347 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string);
(...skipping 22 matching lines...) Expand all
1689 BrowserThread::PostTask( 1370 BrowserThread::PostTask(
1690 BrowserThread::FILE, 1371 BrowserThread::FILE,
1691 FROM_HERE, 1372 FROM_HERE,
1692 base::Bind(&UserManagerImpl::DeleteUserImage, 1373 base::Bind(&UserManagerImpl::DeleteUserImage,
1693 base::Unretained(this), 1374 base::Unretained(this),
1694 image_path)); 1375 image_path));
1695 } 1376 }
1696 } 1377 }
1697 1378
1698 } // namespace chromeos 1379 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698