OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | |
11 #include "ash/desktop_background/desktop_background_controller.h" | |
10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
14 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 18 #include "base/logging.h" |
17 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
18 #include "base/path_service.h" | 20 #include "base/path_service.h" |
19 #include "base/prefs/pref_registry_simple.h" | 21 #include "base/prefs/pref_registry_simple.h" |
20 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
21 #include "base/prefs/scoped_user_pref_update.h" | 23 #include "base/prefs/scoped_user_pref_update.h" |
22 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
24 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
25 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
26 #include "base/time/time.h" | 28 #include "base/time/time.h" |
27 #include "base/values.h" | 29 #include "base/values.h" |
28 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
32 #include "chrome/browser/chromeos/customization_document.h" | |
Daniel Erat
2014/03/31 22:25:46
did you mean to add this include in the next chang
Alexander Alekseev
2014/04/03 19:15:44
Done.
| |
30 #include "chrome/browser/chromeos/login/startup_utils.h" | 33 #include "chrome/browser/chromeos/login/startup_utils.h" |
31 #include "chrome/browser/chromeos/login/user.h" | 34 #include "chrome/browser/chromeos/login/user.h" |
32 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
33 #include "chrome/browser/chromeos/login/wizard_controller.h" | 36 #include "chrome/browser/chromeos/login/wizard_controller.h" |
34 #include "chrome/browser/chromeos/settings/cros_settings.h" | 37 #include "chrome/browser/chromeos/settings/cros_settings.h" |
35 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
38 #include "chromeos/chromeos_switches.h" | 41 #include "chromeos/chromeos_switches.h" |
39 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
40 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
42 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/gfx/codec/jpeg_codec.h" | 46 #include "ui/gfx/codec/jpeg_codec.h" |
44 #include "ui/gfx/image/image_skia_operations.h" | 47 #include "ui/gfx/image/image_skia_operations.h" |
45 #include "ui/gfx/skia_util.h" | 48 #include "ui/gfx/skia_util.h" |
46 | 49 |
47 using content::BrowserThread; | 50 using content::BrowserThread; |
48 | 51 |
52 namespace chromeos { | |
53 | |
49 namespace { | 54 namespace { |
50 | 55 |
51 // The amount of delay before starts to move custom wallpapers to the new place. | 56 // The amount of delay before starts to move custom wallpapers to the new place. |
52 const int kMoveCustomWallpaperDelaySeconds = 30; | 57 const int kMoveCustomWallpaperDelaySeconds = 30; |
53 | 58 |
54 // Default quality for encoding wallpaper. | 59 // Default quality for encoding wallpaper. |
55 const int kDefaultEncodingQuality = 90; | 60 const int kDefaultEncodingQuality = 90; |
56 | 61 |
57 // A dictionary pref that maps usernames to file paths to their wallpapers. | 62 // A dictionary pref that maps usernames to file paths to their wallpapers. |
58 // Deprecated. Will remove this const char after done migration. | 63 // Deprecated. Will remove this const char after done migration. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); | 112 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); |
108 base::FilePath to_path = base_path.Append(user_id_hash); | 113 base::FilePath to_path = base_path.Append(user_id_hash); |
109 base::FilePath from_path = base_path.Append(user_id); | 114 base::FilePath from_path = base_path.Append(user_id); |
110 if (base::PathExists(from_path)) | 115 if (base::PathExists(from_path)) |
111 return base::Move(from_path, to_path); | 116 return base::Move(from_path, to_path); |
112 return false; | 117 return false; |
113 } | 118 } |
114 | 119 |
115 } // namespace | 120 } // namespace |
116 | 121 |
117 namespace chromeos { | |
118 | |
119 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 122 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
120 | 123 |
121 const char kSmallWallpaperSuffix[] = "_small"; | 124 const char kSmallWallpaperSuffix[] = "_small"; |
122 const char kLargeWallpaperSuffix[] = "_large"; | 125 const char kLargeWallpaperSuffix[] = "_large"; |
123 | 126 |
124 const char kSmallWallpaperSubDir[] = "small"; | 127 const char kSmallWallpaperSubDir[] = "small"; |
125 const char kLargeWallpaperSubDir[] = "large"; | 128 const char kLargeWallpaperSubDir[] = "large"; |
126 const char kOriginalWallpaperSubDir[] = "original"; | 129 const char kOriginalWallpaperSubDir[] = "original"; |
127 const char kThumbnailWallpaperSubDir[] = "thumb"; | 130 const char kThumbnailWallpaperSubDir[] = "thumb"; |
128 | 131 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 204 |
202 WallpaperManager* manager = WallpaperManager::Get(); | 205 WallpaperManager* manager = WallpaperManager::Get(); |
203 if (manager->pending_inactive_ == this) | 206 if (manager->pending_inactive_ == this) |
204 manager->pending_inactive_ = NULL; | 207 manager->pending_inactive_ = NULL; |
205 | 208 |
206 started_load_at_ = base::Time::Now(); | 209 started_load_at_ = base::Time::Now(); |
207 | 210 |
208 if (default_) { | 211 if (default_) { |
209 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); | 212 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); |
210 } else if (!user_wallpaper_.isNull()) { | 213 } else if (!user_wallpaper_.isNull()) { |
211 ash::Shell::GetInstance()-> | 214 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
212 desktop_background_controller()-> | 215 user_wallpaper_, info_.layout); |
213 SetCustomWallpaper(user_wallpaper_, info_.layout); | |
214 } else if (!wallpaper_path_.empty()) { | 216 } else if (!wallpaper_path_.empty()) { |
215 manager->task_runner_->PostTask( | 217 manager->task_runner_->PostTask( |
216 FROM_HERE, | 218 FROM_HERE, |
217 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 219 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
218 base::Unretained(manager), | 220 base::Unretained(manager), |
219 user_id_, | 221 user_id_, |
220 info_, | 222 info_, |
221 wallpaper_path_, | 223 wallpaper_path_, |
222 true /* update wallpaper */, | 224 true /* update wallpaper */, |
223 base::Passed(on_finish_.Pass()))); | 225 base::Passed(on_finish_.Pass()))); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 g_wallpaper_manager = new WallpaperManager(); | 301 g_wallpaper_manager = new WallpaperManager(); |
300 return g_wallpaper_manager; | 302 return g_wallpaper_manager; |
301 } | 303 } |
302 | 304 |
303 WallpaperManager::WallpaperManager() | 305 WallpaperManager::WallpaperManager() |
304 : loaded_wallpapers_(0), | 306 : loaded_wallpapers_(0), |
305 command_line_for_testing_(NULL), | 307 command_line_for_testing_(NULL), |
306 should_cache_wallpaper_(false), | 308 should_cache_wallpaper_(false), |
307 weak_factory_(this), | 309 weak_factory_(this), |
308 pending_inactive_(NULL) { | 310 pending_inactive_(NULL) { |
311 SetDefaultWallpaperPathFromCommandLine( | |
312 base::CommandLine::ForCurrentProcess()); | |
309 registrar_.Add(this, | 313 registrar_.Add(this, |
310 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 314 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
311 content::NotificationService::AllSources()); | 315 content::NotificationService::AllSources()); |
312 registrar_.Add(this, | 316 registrar_.Add(this, |
313 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 317 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
314 content::NotificationService::AllSources()); | 318 content::NotificationService::AllSources()); |
315 registrar_.Add(this, | 319 registrar_.Add(this, |
316 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 320 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
317 content::NotificationService::AllSources()); | 321 content::NotificationService::AllSources()); |
318 sequence_token_ = BrowserThread::GetBlockingPool()-> | 322 sequence_token_ = BrowserThread::GetBlockingPool()-> |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 prefs::kUsersWallpaperInfo); | 517 prefs::kUsersWallpaperInfo); |
514 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); | 518 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); |
515 DeleteUserWallpapers(user_id, info.file); | 519 DeleteUserWallpapers(user_id, info.file); |
516 } | 520 } |
517 | 521 |
518 bool WallpaperManager::ResizeWallpaper( | 522 bool WallpaperManager::ResizeWallpaper( |
519 const UserImage& wallpaper, | 523 const UserImage& wallpaper, |
520 ash::WallpaperLayout layout, | 524 ash::WallpaperLayout layout, |
521 int preferred_width, | 525 int preferred_width, |
522 int preferred_height, | 526 int preferred_height, |
523 scoped_refptr<base::RefCountedBytes>* output) const { | 527 scoped_refptr<base::RefCountedBytes>* output, |
528 gfx::ImageSkia* output_skia) const { | |
524 DCHECK(BrowserThread::GetBlockingPool()-> | 529 DCHECK(BrowserThread::GetBlockingPool()-> |
525 IsRunningSequenceOnCurrentThread(sequence_token_)); | 530 IsRunningSequenceOnCurrentThread(sequence_token_)); |
526 int width = wallpaper.image().width(); | 531 int width = wallpaper.image().width(); |
527 int height = wallpaper.image().height(); | 532 int height = wallpaper.image().height(); |
528 int resized_width; | 533 int resized_width; |
529 int resized_height; | 534 int resized_height; |
530 *output = new base::RefCountedBytes(); | 535 *output = new base::RefCountedBytes(); |
531 | 536 |
532 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { | 537 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { |
533 // Do not resize custom wallpaper if it is smaller than preferred size. | 538 // Do not resize custom wallpaper if it is smaller than preferred size. |
(...skipping 26 matching lines...) Expand all Loading... | |
560 | 565 |
561 SkBitmap image = *(resized_image.bitmap()); | 566 SkBitmap image = *(resized_image.bitmap()); |
562 SkAutoLockPixels lock_input(image); | 567 SkAutoLockPixels lock_input(image); |
563 gfx::JPEGCodec::Encode( | 568 gfx::JPEGCodec::Encode( |
564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 569 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
565 gfx::JPEGCodec::FORMAT_SkBitmap, | 570 gfx::JPEGCodec::FORMAT_SkBitmap, |
566 image.width(), | 571 image.width(), |
567 image.height(), | 572 image.height(), |
568 image.width() * image.bytesPerPixel(), | 573 image.width() * image.bytesPerPixel(), |
569 kDefaultEncodingQuality, &(*output)->data()); | 574 kDefaultEncodingQuality, &(*output)->data()); |
575 | |
576 if (output_skia) { | |
577 resized_image.MakeThreadSafe(); | |
578 *output_skia = resized_image; | |
579 } | |
580 | |
570 return true; | 581 return true; |
571 } | 582 } |
572 | 583 |
573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, | 584 bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
574 const base::FilePath& path, | 585 const base::FilePath& path, |
575 ash::WallpaperLayout layout, | 586 ash::WallpaperLayout layout, |
576 int preferred_width, | 587 int preferred_width, |
577 int preferred_height) const { | 588 int preferred_height, |
589 gfx::ImageSkia* result) const { | |
578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 590 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 591 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
580 if (base::PathExists(path)) | 592 if (base::PathExists(path)) |
581 base::DeleteFile(path, false); | 593 base::DeleteFile(path, false); |
582 return; | 594 return false; |
583 } | 595 } |
584 scoped_refptr<base::RefCountedBytes> data; | 596 scoped_refptr<base::RefCountedBytes> data; |
585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, | 597 if (ResizeWallpaper(wallpaper, |
586 &data)) { | 598 layout, |
587 SaveWallpaperInternal(path, | 599 preferred_width, |
588 reinterpret_cast<const char*>(data->front()), | 600 preferred_height, |
589 data->size()); | 601 &data, |
602 result)) { | |
603 return SaveWallpaperInternal( | |
604 path, reinterpret_cast<const char*>(data->front()), data->size()); | |
590 } | 605 } |
606 return false; | |
591 } | 607 } |
592 | 608 |
593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { | 609 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
594 chromeos::WallpaperInfo info; | 610 chromeos::WallpaperInfo info; |
595 if (!GetUserWallpaperInfo(user_id, &info)) | 611 if (!GetUserWallpaperInfo(user_id, &info)) |
596 return false; | 612 return false; |
597 return info.type == chromeos::User::POLICY; | 613 return info.type == chromeos::User::POLICY; |
598 } | 614 } |
599 | 615 |
600 void WallpaperManager::OnPolicySet(const std::string& policy, | 616 void WallpaperManager::OnPolicySet(const std::string& policy, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 } | 738 } |
723 | 739 |
724 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) { | 740 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) { |
725 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper(); | 741 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper(); |
726 } | 742 } |
727 | 743 |
728 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { | 744 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { |
729 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); | 745 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); |
730 } | 746 } |
731 | 747 |
748 void WallpaperManager::OnDefaultWallpaperDecoded( | |
749 const base::FilePath& path, | |
750 scoped_ptr<gfx::ImageSkia>* result, | |
751 MovableOnDestroyCallbackHolder on_finish, | |
752 const UserImage& wallpaper) { | |
753 result->reset(new gfx::ImageSkia); | |
754 (**result) = wallpaper.image(); | |
755 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( | |
756 wallpaper.image(), ash::WALLPAPER_LAYOUT_STRETCH); | |
757 } | |
758 | |
759 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | |
760 const base::FilePath& path, | |
761 scoped_ptr<gfx::ImageSkia>* result, | |
762 MovableOnDestroyCallbackHolder on_finish) { | |
bshe
2014/04/01 15:32:56
I dont see anywhere using wallpaper that packed in
Alexander Alekseev
2014/04/03 19:15:44
Done.
| |
763 wallpaper_loader_->Start( | |
764 path.value(), | |
765 0, // Do not crop. | |
766 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | |
767 base::Unretained(this), | |
768 path, | |
769 base::Unretained(result), | |
770 base::Passed(on_finish.Pass()))); | |
771 } | |
772 | |
732 void WallpaperManager::DoSetDefaultWallpaper( | 773 void WallpaperManager::DoSetDefaultWallpaper( |
733 const std::string& user_id, | 774 const std::string& user_id, |
734 MovableOnDestroyCallbackHolder on_finish) { | 775 MovableOnDestroyCallbackHolder on_finish) { |
735 // There is no visible background in kiosk mode. | 776 // There is no visible background in kiosk mode. |
736 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 777 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
737 return; | 778 return; |
738 current_wallpaper_path_.clear(); | 779 current_wallpaper_path_.clear(); |
739 wallpaper_cache_.erase(user_id); | 780 wallpaper_cache_.erase(user_id); |
740 // Some browser tests do not have a shell instance. As no wallpaper is needed | 781 // Some browser tests do not have a shell instance. As no wallpaper is needed |
741 // in these tests anyway, avoid loading one, preventing crashes and speeding | 782 // in these tests anyway, avoid loading one, preventing crashes and speeding |
742 // up the tests. | 783 // up the tests. |
743 if (!ash::Shell::HasInstance()) | 784 if (!ash::Shell::HasInstance()) |
744 return; | 785 return; |
745 if (ash::Shell::GetInstance()->desktop_background_controller()-> | 786 |
746 SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) | 787 const bool is_guest = UserManager::Get()->IsLoggedInAsGuest(); |
747 loaded_wallpapers_++; | 788 |
789 gfx::ImageSkia image; | |
790 | |
791 ash::WallpaperResolution resolution = ash::Shell::GetInstance() | |
792 ->desktop_background_controller() | |
793 ->GetAppropriateResolution(); | |
794 const bool use_small = (resolution == ash::WALLPAPER_RESOLUTION_SMALL); | |
795 | |
796 if (is_guest) { | |
797 if (use_small) { | |
798 if (guest_default_small_wallpaper_image_.get() == NULL) { | |
Daniel Erat
2014/03/31 22:25:46
nit: just do "if (!guest_default_small_wallpaper_i
Alexander Alekseev
2014/04/03 19:15:44
Done.
| |
799 StartLoadAndSetDefaultWallpaper(guest_default_small_wallpaper_file_, | |
800 &guest_default_small_wallpaper_image_, | |
801 on_finish.Pass()); | |
802 return; | |
803 } | |
804 image = *guest_default_small_wallpaper_image_; | |
805 } else { | |
806 if (guest_default_large_wallpaper_image_.get() == NULL) { | |
Daniel Erat
2014/03/31 22:25:46
there's a lot of duplicated code here. how about d
Alexander Alekseev
2014/04/03 19:15:44
Done.
| |
807 StartLoadAndSetDefaultWallpaper(guest_default_large_wallpaper_file_, | |
808 &guest_default_large_wallpaper_image_, | |
809 on_finish.Pass()); | |
810 return; | |
811 } | |
812 image = *guest_default_large_wallpaper_image_; | |
813 } | |
814 } else { | |
815 // not guest | |
816 if (use_small) { | |
817 if (default_small_wallpaper_image_.get() == NULL) { | |
818 StartLoadAndSetDefaultWallpaper(default_small_wallpaper_file_, | |
819 &default_small_wallpaper_image_, | |
820 on_finish.Pass()); | |
821 return; | |
822 } | |
823 image = *default_small_wallpaper_image_; | |
824 } else { | |
825 if (default_large_wallpaper_image_.get() == NULL) { | |
826 StartLoadAndSetDefaultWallpaper(default_large_wallpaper_file_, | |
827 &default_large_wallpaper_image_, | |
828 on_finish.Pass()); | |
829 return; | |
830 } | |
831 image = *default_large_wallpaper_image_; | |
832 } | |
833 } | |
834 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( | |
835 image, ash::WALLPAPER_LAYOUT_STRETCH); | |
748 } | 836 } |
749 | 837 |
750 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, | 838 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, |
751 bool is_persistent) { | 839 bool is_persistent) { |
752 current_user_wallpaper_info_.file = ""; | 840 current_user_wallpaper_info_.file = ""; |
753 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 841 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
754 current_user_wallpaper_info_.type = User::DEFAULT; | 842 current_user_wallpaper_info_.type = User::DEFAULT; |
755 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 843 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
756 | 844 |
757 WallpaperInfo info = current_user_wallpaper_info_; | 845 WallpaperInfo info = current_user_wallpaper_info_; |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 1151 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
1064 dir = dir.Append(user_id_hash); | 1152 dir = dir.Append(user_id_hash); |
1065 if (!base::PathExists(dir)) | 1153 if (!base::PathExists(dir)) |
1066 base::CreateDirectory(dir); | 1154 base::CreateDirectory(dir); |
1067 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); | 1155 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); |
1068 dir = dir.Append(user_id_hash); | 1156 dir = dir.Append(user_id_hash); |
1069 if (!base::PathExists(dir)) | 1157 if (!base::PathExists(dir)) |
1070 base::CreateDirectory(dir); | 1158 base::CreateDirectory(dir); |
1071 } | 1159 } |
1072 | 1160 |
1161 void WallpaperManager::set_command_line_for_testing( | |
1162 base::CommandLine* command_line) { | |
1163 command_line_for_testing_ = command_line; | |
1164 SetDefaultWallpaperPathFromCommandLine(command_line); | |
1165 } | |
1166 | |
1073 CommandLine* WallpaperManager::GetComandLine() { | 1167 CommandLine* WallpaperManager::GetComandLine() { |
Daniel Erat
2014/03/31 22:25:46
s/Comand/Command/ (please fix this typo elsewhere
Alexander Alekseev
2014/04/03 19:15:44
Done.
| |
1074 CommandLine* command_line = command_line_for_testing_ ? | 1168 CommandLine* command_line = command_line_for_testing_ ? |
1075 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | 1169 command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
1076 return command_line; | 1170 return command_line; |
1077 } | 1171 } |
1078 | 1172 |
1079 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 1173 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
1080 if (UserManager::Get()->IsUserLoggedIn()) | 1174 if (UserManager::Get()->IsUserLoggedIn()) |
1081 return; | 1175 return; |
1082 | 1176 |
1083 bool disable_boot_animation = GetComandLine()-> | 1177 bool disable_boot_animation = GetComandLine()-> |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 return; | 1408 return; |
1315 } | 1409 } |
1316 | 1410 |
1317 // Only cache the user wallpaper at login screen and for multi profile users. | 1411 // Only cache the user wallpaper at login screen and for multi profile users. |
1318 if (!UserManager::Get()->IsUserLoggedIn() || | 1412 if (!UserManager::Get()->IsUserLoggedIn() || |
1319 UserManager::IsMultipleProfilesAllowed()) { | 1413 UserManager::IsMultipleProfilesAllowed()) { |
1320 wallpaper_cache_[user_id] = wallpaper.image(); | 1414 wallpaper_cache_[user_id] = wallpaper.image(); |
1321 } | 1415 } |
1322 | 1416 |
1323 if (update_wallpaper) { | 1417 if (update_wallpaper) { |
1324 ash::Shell::GetInstance()->desktop_background_controller()-> | 1418 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
1325 SetCustomWallpaper(wallpaper.image(), layout); | 1419 wallpaper.image(), layout); |
1326 } | 1420 } |
1327 } | 1421 } |
1328 | 1422 |
1329 void WallpaperManager::ProcessCustomWallpaper( | 1423 void WallpaperManager::ProcessCustomWallpaper( |
1330 const std::string& user_id_hash, | 1424 const std::string& user_id_hash, |
1331 bool persistent, | 1425 bool persistent, |
1332 const WallpaperInfo& info, | 1426 const WallpaperInfo& info, |
1333 scoped_ptr<gfx::ImageSkia> image, | 1427 scoped_ptr<gfx::ImageSkia> image, |
1334 const UserImage::RawImage& raw_image) { | 1428 const UserImage::RawImage& raw_image) { |
1335 DCHECK(BrowserThread::GetBlockingPool()-> | 1429 DCHECK(BrowserThread::GetBlockingPool()-> |
(...skipping 14 matching lines...) Expand all Loading... | |
1350 EnsureCustomWallpaperDirectories(user_id_hash); | 1444 EnsureCustomWallpaperDirectories(user_id_hash); |
1351 std::string file_name = original_path.BaseName().value(); | 1445 std::string file_name = original_path.BaseName().value(); |
1352 base::FilePath small_wallpaper_path = | 1446 base::FilePath small_wallpaper_path = |
1353 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); | 1447 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); |
1354 base::FilePath large_wallpaper_path = | 1448 base::FilePath large_wallpaper_path = |
1355 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); | 1449 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); |
1356 | 1450 |
1357 // Re-encode orginal file to jpeg format and saves the result in case that | 1451 // Re-encode orginal file to jpeg format and saves the result in case that |
1358 // resized wallpaper is not generated (i.e. chrome shutdown before resized | 1452 // resized wallpaper is not generated (i.e. chrome shutdown before resized |
1359 // wallpaper is saved). | 1453 // wallpaper is saved). |
1360 ResizeAndSaveWallpaper(wallpaper, original_path, | 1454 ResizeAndSaveWallpaper(wallpaper, |
1455 original_path, | |
1361 ash::WALLPAPER_LAYOUT_STRETCH, | 1456 ash::WALLPAPER_LAYOUT_STRETCH, |
1362 wallpaper.image().width(), | 1457 wallpaper.image().width(), |
1363 wallpaper.image().height()); | 1458 wallpaper.image().height(), |
1459 NULL); | |
1364 DeleteAllExcept(original_path); | 1460 DeleteAllExcept(original_path); |
1365 | 1461 |
1366 ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, | 1462 ResizeAndSaveWallpaper(wallpaper, |
1463 small_wallpaper_path, | |
1464 layout, | |
1367 ash::kSmallWallpaperMaxWidth, | 1465 ash::kSmallWallpaperMaxWidth, |
1368 ash::kSmallWallpaperMaxHeight); | 1466 ash::kSmallWallpaperMaxHeight, |
1467 NULL); | |
1369 DeleteAllExcept(small_wallpaper_path); | 1468 DeleteAllExcept(small_wallpaper_path); |
1370 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, | 1469 ResizeAndSaveWallpaper(wallpaper, |
1470 large_wallpaper_path, | |
1471 layout, | |
1371 ash::kLargeWallpaperMaxWidth, | 1472 ash::kLargeWallpaperMaxWidth, |
1372 ash::kLargeWallpaperMaxHeight); | 1473 ash::kLargeWallpaperMaxHeight, |
1474 NULL); | |
1373 DeleteAllExcept(large_wallpaper_path); | 1475 DeleteAllExcept(large_wallpaper_path); |
1374 } | 1476 } |
1375 | 1477 |
1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1478 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1479 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
1378 User::WALLPAPER_TYPE_COUNT); | 1480 User::WALLPAPER_TYPE_COUNT); |
1379 } | 1481 } |
1380 | 1482 |
1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, | 1483 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
1382 const char* data, | 1484 const char* data, |
1383 int size) const { | 1485 int size) const { |
1384 int written_bytes = base::WriteFile(path, data, size); | 1486 int written_bytes = base::WriteFile(path, data, size); |
1385 DCHECK(written_bytes == size); | 1487 return written_bytes == size; |
1386 } | 1488 } |
1387 | 1489 |
1388 void WallpaperManager::StartLoad(const std::string& user_id, | 1490 void WallpaperManager::StartLoad(const std::string& user_id, |
1389 const WallpaperInfo& info, | 1491 const WallpaperInfo& info, |
1390 bool update_wallpaper, | 1492 bool update_wallpaper, |
1391 const base::FilePath& wallpaper_path, | 1493 const base::FilePath& wallpaper_path, |
1392 MovableOnDestroyCallbackHolder on_finish) { | 1494 MovableOnDestroyCallbackHolder on_finish) { |
1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1496 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
1395 | 1497 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 if (!pending_inactive_) { | 1550 if (!pending_inactive_) { |
1449 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1551 loading_.push_back(new WallpaperManager::PendingWallpaper( |
1450 (delayed ? GetWallpaperLoadDelay() | 1552 (delayed ? GetWallpaperLoadDelay() |
1451 : base::TimeDelta::FromMilliseconds(0)), | 1553 : base::TimeDelta::FromMilliseconds(0)), |
1452 user_id)); | 1554 user_id)); |
1453 pending_inactive_ = loading_.back(); | 1555 pending_inactive_ = loading_.back(); |
1454 } | 1556 } |
1455 return pending_inactive_; | 1557 return pending_inactive_; |
1456 } | 1558 } |
1457 | 1559 |
1560 void WallpaperManager::SetDefaultWallpaperPathFromCommandLine( | |
1561 base::CommandLine* command_line) { | |
1562 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | |
1563 ash::switches::kAshDefaultWallpaperSmall); | |
1564 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | |
1565 ash::switches::kAshDefaultWallpaperLarge); | |
1566 guest_default_small_wallpaper_file_ = | |
1567 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | |
1568 guest_default_large_wallpaper_file_ = | |
1569 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | |
1570 } | |
1571 | |
1458 } // namespace chromeos | 1572 } // namespace chromeos |
OLD | NEW |