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

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

Issue 215293003: Move all wallpaper file loading and decoding from DesktopBackgroundController to WallpaperManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WallpaperManager should cache only one default wallpaper. Created 6 years, 8 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
OLDNEW
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"
(...skipping 12 matching lines...) Expand all
32 #include "chrome/browser/chromeos/login/user_manager.h" 34 #include "chrome/browser/chromeos/login/user_manager.h"
33 #include "chrome/browser/chromeos/login/wizard_controller.h" 35 #include "chrome/browser/chromeos/login/wizard_controller.h"
34 #include "chrome/browser/chromeos/settings/cros_settings.h" 36 #include "chrome/browser/chromeos/settings/cros_settings.h"
35 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
36 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
37 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
38 #include "chromeos/chromeos_switches.h" 40 #include "chromeos/chromeos_switches.h"
39 #include "chromeos/dbus/dbus_thread_manager.h" 41 #include "chromeos/dbus/dbus_thread_manager.h"
40 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
44 #include "grit/ash_resources.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
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
132 const int kSmallWallpaperMaxWidth = 1366;
133 const int kSmallWallpaperMaxHeight = 800;
134 const int kLargeWallpaperMaxWidth = 2560;
135 const int kLargeWallpaperMaxHeight = 1700;
136 const int kWallpaperThumbnailWidth = 108;
137 const int kWallpaperThumbnailHeight = 68;
138
129 static WallpaperManager* g_wallpaper_manager = NULL; 139 static WallpaperManager* g_wallpaper_manager = NULL;
130 140
131 // This object is passed between several threads while wallpaper is being 141 // This object is passed between several threads while wallpaper is being
132 // loaded. It will notify callback when last reference to it is removed 142 // loaded. It will notify callback when last reference to it is removed
133 // (thus indicating that the last load action has finished). 143 // (thus indicating that the last load action has finished).
134 class MovableOnDestroyCallback { 144 class MovableOnDestroyCallback {
135 public: 145 public:
136 explicit MovableOnDestroyCallback(const base::Closure& callback) 146 explicit MovableOnDestroyCallback(const base::Closure& callback)
137 : callback_(callback) { 147 : callback_(callback) {
138 } 148 }
139 149
140 ~MovableOnDestroyCallback() { 150 ~MovableOnDestroyCallback() {
141 if (!callback_.is_null()) 151 if (!callback_.is_null())
142 callback_.Run(); 152 callback_.Run();
143 } 153 }
144 154
145 private: 155 private:
146 base::Closure callback_; 156 base::Closure callback_;
147 }; 157 };
148 158
159 void WallpaperManager::Observer::OnUpdateWallpaperForTesting() {
160 }
161
149 WallpaperManager::PendingWallpaper::PendingWallpaper( 162 WallpaperManager::PendingWallpaper::PendingWallpaper(
150 const base::TimeDelta delay, 163 const base::TimeDelta delay,
151 const std::string& user_id) 164 const std::string& user_id)
152 : user_id_(user_id), 165 : user_id_(user_id),
153 default_(false), 166 default_(false),
154 on_finish_(new MovableOnDestroyCallback( 167 on_finish_(new MovableOnDestroyCallback(
155 base::Bind(&WallpaperManager::PendingWallpaper::OnWallpaperSet, 168 base::Bind(&WallpaperManager::PendingWallpaper::OnWallpaperSet,
156 this))) { 169 this))) {
157 timer.Start( 170 timer.Start(
158 FROM_HERE, 171 FROM_HERE,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 214
202 WallpaperManager* manager = WallpaperManager::Get(); 215 WallpaperManager* manager = WallpaperManager::Get();
203 if (manager->pending_inactive_ == this) 216 if (manager->pending_inactive_ == this)
204 manager->pending_inactive_ = NULL; 217 manager->pending_inactive_ = NULL;
205 218
206 started_load_at_ = base::Time::Now(); 219 started_load_at_ = base::Time::Now();
207 220
208 if (default_) { 221 if (default_) {
209 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); 222 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass());
210 } else if (!user_wallpaper_.isNull()) { 223 } else if (!user_wallpaper_.isNull()) {
211 ash::Shell::GetInstance()-> 224 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper(
212 desktop_background_controller()-> 225 user_wallpaper_, info_.layout);
213 SetCustomWallpaper(user_wallpaper_, info_.layout);
214 } else if (!wallpaper_path_.empty()) { 226 } else if (!wallpaper_path_.empty()) {
215 manager->task_runner_->PostTask( 227 manager->task_runner_->PostTask(
216 FROM_HERE, 228 FROM_HERE,
217 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 229 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
218 base::Unretained(manager), 230 base::Unretained(manager),
219 user_id_, 231 user_id_,
220 info_, 232 info_,
221 wallpaper_path_, 233 wallpaper_path_,
222 true /* update wallpaper */, 234 true /* update wallpaper */,
223 base::Passed(on_finish_.Pass()))); 235 base::Passed(on_finish_.Pass())));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 g_wallpaper_manager = new WallpaperManager(); 311 g_wallpaper_manager = new WallpaperManager();
300 return g_wallpaper_manager; 312 return g_wallpaper_manager;
301 } 313 }
302 314
303 WallpaperManager::WallpaperManager() 315 WallpaperManager::WallpaperManager()
304 : loaded_wallpapers_(0), 316 : loaded_wallpapers_(0),
305 command_line_for_testing_(NULL), 317 command_line_for_testing_(NULL),
306 should_cache_wallpaper_(false), 318 should_cache_wallpaper_(false),
307 weak_factory_(this), 319 weak_factory_(this),
308 pending_inactive_(NULL) { 320 pending_inactive_(NULL) {
321 SetDefaultWallpaperPathsFromCommandLine(
322 base::CommandLine::ForCurrentProcess());
309 registrar_.Add(this, 323 registrar_.Add(this,
310 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 324 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
311 content::NotificationService::AllSources()); 325 content::NotificationService::AllSources());
312 registrar_.Add(this, 326 registrar_.Add(this,
313 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, 327 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
314 content::NotificationService::AllSources()); 328 content::NotificationService::AllSources());
315 registrar_.Add(this, 329 registrar_.Add(this,
316 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, 330 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
317 content::NotificationService::AllSources()); 331 content::NotificationService::AllSources());
318 sequence_token_ = BrowserThread::GetBlockingPool()-> 332 sequence_token_ = BrowserThread::GetBlockingPool()->
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 439 }
426 440
427 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), 441 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(),
428 info); 442 info);
429 } 443 }
430 444
431 void WallpaperManager::InitializeWallpaper() { 445 void WallpaperManager::InitializeWallpaper() {
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
433 UserManager* user_manager = UserManager::Get(); 447 UserManager* user_manager = UserManager::Get();
434 448
435 CommandLine* command_line = GetComandLine(); 449 CommandLine* command_line = GetCommandLine();
436 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { 450 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
437 // Guest wallpaper should be initialized when guest login. 451 // Guest wallpaper should be initialized when guest login.
438 // Note: This maybe called before login. So IsLoggedInAsGuest can not be 452 // Note: This maybe called before login. So IsLoggedInAsGuest can not be
439 // used here to determine if current user is guest. 453 // used here to determine if current user is guest.
440 return; 454 return;
441 } 455 }
442 456
443 if (command_line->HasSwitch(::switches::kTestType)) 457 if (command_line->HasSwitch(::switches::kTestType))
444 WizardController::SetZeroDelays(); 458 WizardController::SetZeroDelays();
445 459
(...skipping 24 matching lines...) Expand all
470 ClearDisposableWallpaperCache(); 484 ClearDisposableWallpaperCache();
471 BrowserThread::PostDelayedTask( 485 BrowserThread::PostDelayedTask(
472 BrowserThread::UI, 486 BrowserThread::UI,
473 FROM_HERE, 487 FROM_HERE,
474 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper, 488 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper,
475 weak_factory_.GetWeakPtr()), 489 weak_factory_.GetWeakPtr()),
476 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds)); 490 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds));
477 break; 491 break;
478 } 492 }
479 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { 493 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: {
480 if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) { 494 if (!GetCommandLine()->HasSwitch(switches::kDisableBootAnimation)) {
481 BrowserThread::PostDelayedTask( 495 BrowserThread::PostDelayedTask(
482 BrowserThread::UI, FROM_HERE, 496 BrowserThread::UI, FROM_HERE,
483 base::Bind(&WallpaperManager::CacheUsersWallpapers, 497 base::Bind(&WallpaperManager::CacheUsersWallpapers,
484 weak_factory_.GetWeakPtr()), 498 weak_factory_.GetWeakPtr()),
485 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); 499 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs));
486 } else { 500 } else {
487 should_cache_wallpaper_ = true; 501 should_cache_wallpaper_ = true;
488 } 502 }
489 break; 503 break;
490 } 504 }
(...skipping 22 matching lines...) Expand all
513 prefs::kUsersWallpaperInfo); 527 prefs::kUsersWallpaperInfo);
514 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); 528 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL);
515 DeleteUserWallpapers(user_id, info.file); 529 DeleteUserWallpapers(user_id, info.file);
516 } 530 }
517 531
518 bool WallpaperManager::ResizeWallpaper( 532 bool WallpaperManager::ResizeWallpaper(
519 const UserImage& wallpaper, 533 const UserImage& wallpaper,
520 ash::WallpaperLayout layout, 534 ash::WallpaperLayout layout,
521 int preferred_width, 535 int preferred_width,
522 int preferred_height, 536 int preferred_height,
523 scoped_refptr<base::RefCountedBytes>* output) const { 537 scoped_refptr<base::RefCountedBytes>* output,
538 gfx::ImageSkia* output_skia) const {
524 DCHECK(BrowserThread::GetBlockingPool()-> 539 DCHECK(BrowserThread::GetBlockingPool()->
525 IsRunningSequenceOnCurrentThread(sequence_token_)); 540 IsRunningSequenceOnCurrentThread(sequence_token_));
526 int width = wallpaper.image().width(); 541 int width = wallpaper.image().width();
527 int height = wallpaper.image().height(); 542 int height = wallpaper.image().height();
528 int resized_width; 543 int resized_width;
529 int resized_height; 544 int resized_height;
530 *output = new base::RefCountedBytes(); 545 *output = new base::RefCountedBytes();
531 546
532 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { 547 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) {
533 // Do not resize custom wallpaper if it is smaller than preferred size. 548 // Do not resize custom wallpaper if it is smaller than preferred size.
(...skipping 26 matching lines...) Expand all
560 575
561 SkBitmap image = *(resized_image.bitmap()); 576 SkBitmap image = *(resized_image.bitmap());
562 SkAutoLockPixels lock_input(image); 577 SkAutoLockPixels lock_input(image);
563 gfx::JPEGCodec::Encode( 578 gfx::JPEGCodec::Encode(
564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), 579 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)),
565 gfx::JPEGCodec::FORMAT_SkBitmap, 580 gfx::JPEGCodec::FORMAT_SkBitmap,
566 image.width(), 581 image.width(),
567 image.height(), 582 image.height(),
568 image.width() * image.bytesPerPixel(), 583 image.width() * image.bytesPerPixel(),
569 kDefaultEncodingQuality, &(*output)->data()); 584 kDefaultEncodingQuality, &(*output)->data());
585
586 if (output_skia) {
587 resized_image.MakeThreadSafe();
588 *output_skia = resized_image;
589 }
590
570 return true; 591 return true;
571 } 592 }
572 593
573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, 594 bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper,
574 const base::FilePath& path, 595 const base::FilePath& path,
575 ash::WallpaperLayout layout, 596 ash::WallpaperLayout layout,
576 int preferred_width, 597 int preferred_width,
577 int preferred_height) const { 598 int preferred_height,
599 gfx::ImageSkia* result) const {
578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { 600 if (layout == ash::WALLPAPER_LAYOUT_CENTER) {
579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 601 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
580 if (base::PathExists(path)) 602 if (base::PathExists(path))
581 base::DeleteFile(path, false); 603 base::DeleteFile(path, false);
582 return; 604 return false;
583 } 605 }
584 scoped_refptr<base::RefCountedBytes> data; 606 scoped_refptr<base::RefCountedBytes> data;
585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, 607 if (ResizeWallpaper(wallpaper,
586 &data)) { 608 layout,
587 SaveWallpaperInternal(path, 609 preferred_width,
588 reinterpret_cast<const char*>(data->front()), 610 preferred_height,
589 data->size()); 611 &data,
612 result)) {
613 return SaveWallpaperInternal(
614 path, reinterpret_cast<const char*>(data->front()), data->size());
590 } 615 }
616 return false;
591 } 617 }
592 618
593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { 619 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const {
594 chromeos::WallpaperInfo info; 620 chromeos::WallpaperInfo info;
595 if (!GetUserWallpaperInfo(user_id, &info)) 621 if (!GetUserWallpaperInfo(user_id, &info))
596 return false; 622 return false;
597 return info.type == chromeos::User::POLICY; 623 return info.type == chromeos::User::POLICY;
598 } 624 }
599 625
600 void WallpaperManager::OnPolicySet(const std::string& policy, 626 void WallpaperManager::OnPolicySet(const std::string& policy,
(...skipping 20 matching lines...) Expand all
621 return; 647 return;
622 648
623 wallpaper_loader_->Start( 649 wallpaper_loader_->Start(
624 data.Pass(), 650 data.Pass(),
625 0, // Do not crop. 651 0, // Do not crop.
626 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, 652 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper,
627 weak_factory_.GetWeakPtr(), 653 weak_factory_.GetWeakPtr(),
628 user_id)); 654 user_id));
629 } 655 }
630 656
657 // static
658 WallpaperManager::WallpaperResolution
659 WallpaperManager::GetAppropriateResolution() {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
661 gfx::Size size =
662 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative();
663 return (size.width() > kSmallWallpaperMaxWidth ||
664 size.height() > kSmallWallpaperMaxHeight)
665 ? WALLPAPER_RESOLUTION_LARGE
666 : WALLPAPER_RESOLUTION_SMALL;
667 }
668
631 void WallpaperManager::SetPolicyControlledWallpaper( 669 void WallpaperManager::SetPolicyControlledWallpaper(
632 const std::string& user_id, 670 const std::string& user_id,
633 const UserImage& wallpaper) { 671 const UserImage& wallpaper) {
634 const User *user = chromeos::UserManager::Get()->FindUser(user_id); 672 const User *user = chromeos::UserManager::Get()->FindUser(user_id);
635 if (!user) { 673 if (!user) {
636 NOTREACHED() << "Unknown user."; 674 NOTREACHED() << "Unknown user.";
637 return; 675 return;
638 } 676 }
639 SetCustomWallpaper(user_id, 677 SetCustomWallpaper(user_id,
640 user->username_hash(), 678 user->username_hash(),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 760 }
723 761
724 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) { 762 void WallpaperManager::SetDefaultWallpaperNow(const std::string& user_id) {
725 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper(); 763 GetPendingWallpaper(user_id, false)->ResetSetDefaultWallpaper();
726 } 764 }
727 765
728 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { 766 void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) {
729 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); 767 GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper();
730 } 768 }
731 769
770 void WallpaperManager::OnDefaultWallpaperDecoded(
Daniel Erat 2014/04/04 02:45:49 nit: please make this match its position in the he
Alexander Alekseev 2014/04/05 03:35:13 Done.
771 const base::FilePath& path,
772 scoped_ptr<chromeos::UserImage>* result,
773 MovableOnDestroyCallbackHolder on_finish,
774 const UserImage& wallpaper) {
775 result->reset(new UserImage(wallpaper.image()));
776 (*result)->set_url(GURL(path.value()));
777 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper(
778 wallpaper.image(), ash::WALLPAPER_LAYOUT_STRETCH);
779 }
780
781 void WallpaperManager::StartLoadAndSetDefaultWallpaper(
Daniel Erat 2014/04/04 02:45:49 nit: please make this match its position in the he
Alexander Alekseev 2014/04/05 03:35:13 Done.
782 const base::FilePath& path,
783 scoped_ptr<chromeos::UserImage>* result,
784 MovableOnDestroyCallbackHolder on_finish) {
785 wallpaper_loader_->Start(
786 path.value(),
787 0, // Do not crop.
788 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded,
789 base::Unretained(this),
Daniel Erat 2014/04/04 02:45:49 can you use a weak_ptr here instead, or is this gu
Alexander Alekseev 2014/04/05 03:35:13 Done.
790 path,
791 base::Unretained(result),
792 base::Passed(on_finish.Pass())));
793 }
794
732 void WallpaperManager::DoSetDefaultWallpaper( 795 void WallpaperManager::DoSetDefaultWallpaper(
733 const std::string& user_id, 796 const std::string& user_id,
734 MovableOnDestroyCallbackHolder on_finish) { 797 MovableOnDestroyCallbackHolder on_finish) {
735 // There is no visible background in kiosk mode. 798 // There is no visible background in kiosk mode.
736 if (UserManager::Get()->IsLoggedInAsKioskApp()) 799 if (UserManager::Get()->IsLoggedInAsKioskApp())
737 return; 800 return;
738 current_wallpaper_path_.clear(); 801 current_wallpaper_path_.clear();
739 wallpaper_cache_.erase(user_id); 802 wallpaper_cache_.erase(user_id);
740 // Some browser tests do not have a shell instance. As no wallpaper is needed 803 // 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 804 // in these tests anyway, avoid loading one, preventing crashes and speeding
742 // up the tests. 805 // up the tests.
743 if (!ash::Shell::HasInstance()) 806 if (!ash::Shell::HasInstance())
744 return; 807 return;
745 if (ash::Shell::GetInstance()->desktop_background_controller()-> 808
746 SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) 809 const bool is_guest = UserManager::Get()->IsLoggedInAsGuest();
Daniel Erat 2014/04/04 02:45:49 nit: you don't use this anywhere else, and i don't
Alexander Alekseev 2014/04/05 03:35:13 Done.
747 loaded_wallpapers_++; 810
811 gfx::ImageSkia image;
Daniel Erat 2014/04/04 02:45:49 this doesn't get used anywhere, does it? if not, d
Alexander Alekseev 2014/04/05 03:35:13 Done.
812
813 WallpaperResolution resolution = GetAppropriateResolution();
814 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL);
815
816 const base::FilePath* file = NULL;
817
818 if (is_guest) {
819 file =
820 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_;
821 } else {
822 file = use_small ? &default_small_wallpaper_file_
823 : &default_large_wallpaper_file_;
824 }
825 DCHECK(file);
826 if (!default_wallpaper_image_.get() ||
827 default_wallpaper_image_->url().spec() != file->value()) {
828 default_wallpaper_image_.reset();
829 if (!file->empty()) {
830 loaded_wallpapers_++;
831 StartLoadAndSetDefaultWallpaper(
832 *file, &default_wallpaper_image_, on_finish.Pass());
833 return;
834 }
835
836 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL
837 : IDR_AURA_WALLPAPER_DEFAULT_LARGE;
Daniel Erat 2014/04/04 02:45:49 hmm. so yeah, i think we should just drop support
Alexander Alekseev 2014/04/05 03:35:13 This seems to me too much for this code refactorin
838
839 loaded_wallpapers_ +=
840 ash::Shell::GetInstance()
841 ->desktop_background_controller()
842 ->SetWallpaper(resource_id, ash::WALLPAPER_LAYOUT_TILE);
843 return;
844 }
845 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper(
846 default_wallpaper_image_->image(), ash::WALLPAPER_LAYOUT_STRETCH);
748 } 847 }
749 848
750 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, 849 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id,
751 bool is_persistent) { 850 bool is_persistent) {
752 current_user_wallpaper_info_.file = ""; 851 current_user_wallpaper_info_.file = "";
753 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 852 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
754 current_user_wallpaper_info_.type = User::DEFAULT; 853 current_user_wallpaper_info_.type = User::DEFAULT;
755 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); 854 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
756 855
757 WallpaperInfo info = current_user_wallpaper_info_; 856 WallpaperInfo info = current_user_wallpaper_info_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 GetUserWallpaperInfo(user_id, &info); 921 GetUserWallpaperInfo(user_id, &info);
823 } 922 }
824 923
825 gfx::ImageSkia user_wallpaper; 924 gfx::ImageSkia user_wallpaper;
826 current_user_wallpaper_info_ = info; 925 current_user_wallpaper_info_ = info;
827 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { 926 if (GetWallpaperFromCache(user_id, &user_wallpaper)) {
828 GetPendingWallpaper(user_id, delayed) 927 GetPendingWallpaper(user_id, delayed)
829 ->ResetSetWallpaperImage(user_wallpaper, info); 928 ->ResetSetWallpaperImage(user_wallpaper, info);
830 } else { 929 } else {
831 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { 930 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
832 ash::WallpaperResolution resolution = 931 WallpaperResolution resolution = GetAppropriateResolution();
833 ash::Shell::GetInstance()-> 932 const char* sub_dir = (resolution == WALLPAPER_RESOLUTION_SMALL)
Daniel Erat 2014/04/04 02:45:49 this appears again below -- probably worthwhile to
Alexander Alekseev 2014/04/05 03:35:13 Done.
834 desktop_background_controller()->
835 GetAppropriateResolution();
836 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL)
837 ? kSmallWallpaperSubDir 933 ? kSmallWallpaperSubDir
838 : kLargeWallpaperSubDir; 934 : kLargeWallpaperSubDir;
839 935
840 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. 936 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER.
841 // Original wallpaper should be used in this case. 937 // Original wallpaper should be used in this case.
842 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 938 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
843 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) 939 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER)
844 sub_dir = kOriginalWallpaperSubDir; 940 sub_dir = kOriginalWallpaperSubDir;
845 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 941 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
846 wallpaper_path = wallpaper_path.Append(info.file); 942 wallpaper_path = wallpaper_path.Append(info.file);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 if (UserManager::IsMultipleProfilesAllowed()) 977 if (UserManager::IsMultipleProfilesAllowed())
882 wallpaper_cache_[user_id] = wallpaper; 978 wallpaper_cache_[user_id] = wallpaper;
883 979
884 if (update_wallpaper) { 980 if (update_wallpaper) {
885 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) 981 GetPendingWallpaper(last_selected_user_, false /* Not delayed */)
886 ->ResetSetWallpaperImage(wallpaper, info); 982 ->ResetSetWallpaperImage(wallpaper, info);
887 } 983 }
888 } 984 }
889 985
890 void WallpaperManager::UpdateWallpaper(bool clear_cache) { 986 void WallpaperManager::UpdateWallpaper(bool clear_cache) {
987 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting());
891 if (clear_cache) 988 if (clear_cache)
892 wallpaper_cache_.clear(); 989 wallpaper_cache_.clear();
893 current_wallpaper_path_.clear(); 990 current_wallpaper_path_.clear();
894 // For GAIA login flow, the last_selected_user_ may not be set before user 991 // For GAIA login flow, the last_selected_user_ may not be set before user
895 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will 992 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will
896 // be set. It could result a black screen on external monitors. 993 // be set. It could result a black screen on external monitors.
897 // See http://crbug.com/265689 for detail. 994 // See http://crbug.com/265689 for detail.
898 if (last_selected_user_.empty()) { 995 if (last_selected_user_.empty()) {
899 SetDefaultWallpaperNow(UserManager::kSignInUser); 996 SetDefaultWallpaperNow(UserManager::kSignInUser);
900 return; 997 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } 1043 }
947 1044
948 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { 1045 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) {
949 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) 1046 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end())
950 return; 1047 return;
951 WallpaperInfo info; 1048 WallpaperInfo info;
952 if (GetUserWallpaperInfo(user_id, &info)) { 1049 if (GetUserWallpaperInfo(user_id, &info)) {
953 base::FilePath wallpaper_dir; 1050 base::FilePath wallpaper_dir;
954 base::FilePath wallpaper_path; 1051 base::FilePath wallpaper_path;
955 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { 1052 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
956 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 1053 WallpaperResolution resolution = GetAppropriateResolution();
957 desktop_background_controller()->GetAppropriateResolution(); 1054 const char* sub_dir = (resolution == WALLPAPER_RESOLUTION_SMALL)
958 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? 1055 ? kSmallWallpaperSubDir
959 kSmallWallpaperSubDir : kLargeWallpaperSubDir; 1056 : kLargeWallpaperSubDir;
960 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 1057 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
961 wallpaper_path = wallpaper_path.Append(info.file); 1058 wallpaper_path = wallpaper_path.Append(info.file);
962 task_runner_->PostTask( 1059 task_runner_->PostTask(
963 FROM_HERE, 1060 FROM_HERE,
964 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 1061 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
965 base::Unretained(this), 1062 base::Unretained(this),
966 user_id, 1063 user_id,
967 info, 1064 info,
968 wallpaper_path, 1065 wallpaper_path,
969 false /* do not update wallpaper */, 1066 false /* do not update wallpaper */,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); 1160 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
1064 dir = dir.Append(user_id_hash); 1161 dir = dir.Append(user_id_hash);
1065 if (!base::PathExists(dir)) 1162 if (!base::PathExists(dir))
1066 base::CreateDirectory(dir); 1163 base::CreateDirectory(dir);
1067 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); 1164 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir);
1068 dir = dir.Append(user_id_hash); 1165 dir = dir.Append(user_id_hash);
1069 if (!base::PathExists(dir)) 1166 if (!base::PathExists(dir))
1070 base::CreateDirectory(dir); 1167 base::CreateDirectory(dir);
1071 } 1168 }
1072 1169
1073 CommandLine* WallpaperManager::GetComandLine() { 1170 void WallpaperManager::set_command_line_for_testing(
1171 base::CommandLine* command_line) {
1172 command_line_for_testing_ = command_line;
1173 SetDefaultWallpaperPathsFromCommandLine(command_line);
1174 }
1175
1176 CommandLine* WallpaperManager::GetCommandLine() {
1074 CommandLine* command_line = command_line_for_testing_ ? 1177 CommandLine* command_line = command_line_for_testing_ ?
1075 command_line_for_testing_ : CommandLine::ForCurrentProcess(); 1178 command_line_for_testing_ : CommandLine::ForCurrentProcess();
1076 return command_line; 1179 return command_line;
1077 } 1180 }
1078 1181
1079 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { 1182 void WallpaperManager::InitializeRegisteredDeviceWallpaper() {
1080 if (UserManager::Get()->IsUserLoggedIn()) 1183 if (UserManager::Get()->IsUserLoggedIn())
1081 return; 1184 return;
1082 1185
1083 bool disable_boot_animation = GetComandLine()-> 1186 bool disable_boot_animation =
1084 HasSwitch(switches::kDisableBootAnimation); 1187 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation);
1085 bool show_users = true; 1188 bool show_users = true;
1086 bool result = CrosSettings::Get()->GetBoolean( 1189 bool result = CrosSettings::Get()->GetBoolean(
1087 kAccountsPrefShowUserNamesOnSignIn, &show_users); 1190 kAccountsPrefShowUserNamesOnSignIn, &show_users);
1088 DCHECK(result) << "Unable to fetch setting " 1191 DCHECK(result) << "Unable to fetch setting "
1089 << kAccountsPrefShowUserNamesOnSignIn; 1192 << kAccountsPrefShowUserNamesOnSignIn;
1090 const chromeos::UserList& users = UserManager::Get()->GetUsers(); 1193 const chromeos::UserList& users = UserManager::Get()->GetUsers();
1091 if (!show_users || users.empty()) { 1194 if (!show_users || users.empty()) {
1092 // Boot into sign in form, preload default wallpaper. 1195 // Boot into sign in form, preload default wallpaper.
1093 SetDefaultWallpaperDelayed(UserManager::kSignInUser); 1196 SetDefaultWallpaperDelayed(UserManager::kSignInUser);
1094 return; 1197 return;
1095 } 1198 }
1096 1199
1097 if (!disable_boot_animation) { 1200 if (!disable_boot_animation) {
1098 // Normal boot, load user wallpaper. 1201 // Normal boot, load user wallpaper.
1099 // If normal boot animation is disabled wallpaper would be set 1202 // If normal boot animation is disabled wallpaper would be set
1100 // asynchronously once user pods are loaded. 1203 // asynchronously once user pods are loaded.
1101 SetUserWallpaperDelayed(users[0]->email()); 1204 SetUserWallpaperDelayed(users[0]->email());
1102 } 1205 }
1103 } 1206 }
1104 1207
1105 void WallpaperManager::LoadWallpaper(const std::string& user_id, 1208 void WallpaperManager::LoadWallpaper(const std::string& user_id,
1106 const WallpaperInfo& info, 1209 const WallpaperInfo& info,
1107 bool update_wallpaper, 1210 bool update_wallpaper,
1108 MovableOnDestroyCallbackHolder on_finish) { 1211 MovableOnDestroyCallbackHolder on_finish) {
1109 base::FilePath wallpaper_dir; 1212 base::FilePath wallpaper_dir;
1110 base::FilePath wallpaper_path; 1213 base::FilePath wallpaper_path;
1111 if (info.type == User::ONLINE) { 1214 if (info.type == User::ONLINE) {
1112 std::string file_name = GURL(info.file).ExtractFileName(); 1215 std::string file_name = GURL(info.file).ExtractFileName();
1113 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 1216 WallpaperResolution resolution = GetAppropriateResolution();
1114 desktop_background_controller()->GetAppropriateResolution();
1115 // Only solid color wallpapers have stretch layout and they have only one 1217 // Only solid color wallpapers have stretch layout and they have only one
1116 // resolution. 1218 // resolution.
1117 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && 1219 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH &&
1118 resolution == ash::WALLPAPER_RESOLUTION_SMALL) { 1220 resolution == WALLPAPER_RESOLUTION_SMALL) {
1119 file_name = base::FilePath(file_name).InsertBeforeExtension( 1221 file_name = base::FilePath(file_name).InsertBeforeExtension(
1120 kSmallWallpaperSuffix).value(); 1222 kSmallWallpaperSuffix).value();
1121 } 1223 }
1122 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 1224 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
1123 wallpaper_path = wallpaper_dir.Append(file_name); 1225 wallpaper_path = wallpaper_dir.Append(file_name);
1124 if (current_wallpaper_path_ == wallpaper_path) 1226 if (current_wallpaper_path_ == wallpaper_path)
1125 return; 1227 return;
1126 1228
1127 if (update_wallpaper) 1229 if (update_wallpaper)
1128 current_wallpaper_path_ = wallpaper_path; 1230 current_wallpaper_path_ = wallpaper_path;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 return; 1416 return;
1315 } 1417 }
1316 1418
1317 // Only cache the user wallpaper at login screen and for multi profile users. 1419 // Only cache the user wallpaper at login screen and for multi profile users.
1318 if (!UserManager::Get()->IsUserLoggedIn() || 1420 if (!UserManager::Get()->IsUserLoggedIn() ||
1319 UserManager::IsMultipleProfilesAllowed()) { 1421 UserManager::IsMultipleProfilesAllowed()) {
1320 wallpaper_cache_[user_id] = wallpaper.image(); 1422 wallpaper_cache_[user_id] = wallpaper.image();
1321 } 1423 }
1322 1424
1323 if (update_wallpaper) { 1425 if (update_wallpaper) {
1324 ash::Shell::GetInstance()->desktop_background_controller()-> 1426 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper(
1325 SetCustomWallpaper(wallpaper.image(), layout); 1427 wallpaper.image(), layout);
1326 } 1428 }
1327 } 1429 }
1328 1430
1329 void WallpaperManager::ProcessCustomWallpaper( 1431 void WallpaperManager::ProcessCustomWallpaper(
1330 const std::string& user_id_hash, 1432 const std::string& user_id_hash,
1331 bool persistent, 1433 bool persistent,
1332 const WallpaperInfo& info, 1434 const WallpaperInfo& info,
1333 scoped_ptr<gfx::ImageSkia> image, 1435 scoped_ptr<gfx::ImageSkia> image,
1334 const UserImage::RawImage& raw_image) { 1436 const UserImage::RawImage& raw_image) {
1335 DCHECK(BrowserThread::GetBlockingPool()-> 1437 DCHECK(BrowserThread::GetBlockingPool()->
(...skipping 14 matching lines...) Expand all
1350 EnsureCustomWallpaperDirectories(user_id_hash); 1452 EnsureCustomWallpaperDirectories(user_id_hash);
1351 std::string file_name = original_path.BaseName().value(); 1453 std::string file_name = original_path.BaseName().value();
1352 base::FilePath small_wallpaper_path = 1454 base::FilePath small_wallpaper_path =
1353 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); 1455 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name);
1354 base::FilePath large_wallpaper_path = 1456 base::FilePath large_wallpaper_path =
1355 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); 1457 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name);
1356 1458
1357 // Re-encode orginal file to jpeg format and saves the result in case that 1459 // 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 1460 // resized wallpaper is not generated (i.e. chrome shutdown before resized
1359 // wallpaper is saved). 1461 // wallpaper is saved).
1360 ResizeAndSaveWallpaper(wallpaper, original_path, 1462 ResizeAndSaveWallpaper(wallpaper,
1463 original_path,
1361 ash::WALLPAPER_LAYOUT_STRETCH, 1464 ash::WALLPAPER_LAYOUT_STRETCH,
1362 wallpaper.image().width(), 1465 wallpaper.image().width(),
1363 wallpaper.image().height()); 1466 wallpaper.image().height(),
1467 NULL);
1364 DeleteAllExcept(original_path); 1468 DeleteAllExcept(original_path);
1365 1469
1366 ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, 1470 ResizeAndSaveWallpaper(wallpaper,
1367 ash::kSmallWallpaperMaxWidth, 1471 small_wallpaper_path,
1368 ash::kSmallWallpaperMaxHeight); 1472 layout,
1473 kSmallWallpaperMaxWidth,
1474 kSmallWallpaperMaxHeight,
1475 NULL);
1369 DeleteAllExcept(small_wallpaper_path); 1476 DeleteAllExcept(small_wallpaper_path);
1370 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, 1477 ResizeAndSaveWallpaper(wallpaper,
1371 ash::kLargeWallpaperMaxWidth, 1478 large_wallpaper_path,
1372 ash::kLargeWallpaperMaxHeight); 1479 layout,
1480 kLargeWallpaperMaxWidth,
1481 kLargeWallpaperMaxHeight,
1482 NULL);
1373 DeleteAllExcept(large_wallpaper_path); 1483 DeleteAllExcept(large_wallpaper_path);
1374 } 1484 }
1375 1485
1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { 1486 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const {
1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, 1487 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type,
1378 User::WALLPAPER_TYPE_COUNT); 1488 User::WALLPAPER_TYPE_COUNT);
1379 } 1489 }
1380 1490
1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, 1491 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path,
1382 const char* data, 1492 const char* data,
1383 int size) const { 1493 int size) const {
1384 int written_bytes = base::WriteFile(path, data, size); 1494 int written_bytes = base::WriteFile(path, data, size);
1385 DCHECK(written_bytes == size); 1495 return written_bytes == size;
1386 } 1496 }
1387 1497
1388 void WallpaperManager::StartLoad(const std::string& user_id, 1498 void WallpaperManager::StartLoad(const std::string& user_id,
1389 const WallpaperInfo& info, 1499 const WallpaperInfo& info,
1390 bool update_wallpaper, 1500 bool update_wallpaper,
1391 const base::FilePath& wallpaper_path, 1501 const base::FilePath& wallpaper_path,
1392 MovableOnDestroyCallbackHolder on_finish) { 1502 MovableOnDestroyCallbackHolder on_finish) {
1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); 1504 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this);
1395 1505
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 if (!pending_inactive_) { 1558 if (!pending_inactive_) {
1449 loading_.push_back(new WallpaperManager::PendingWallpaper( 1559 loading_.push_back(new WallpaperManager::PendingWallpaper(
1450 (delayed ? GetWallpaperLoadDelay() 1560 (delayed ? GetWallpaperLoadDelay()
1451 : base::TimeDelta::FromMilliseconds(0)), 1561 : base::TimeDelta::FromMilliseconds(0)),
1452 user_id)); 1562 user_id));
1453 pending_inactive_ = loading_.back(); 1563 pending_inactive_ = loading_.back();
1454 } 1564 }
1455 return pending_inactive_; 1565 return pending_inactive_;
1456 } 1566 }
1457 1567
1568 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine(
Daniel Erat 2014/04/04 02:45:49 nit: please make this match its position in the he
Alexander Alekseev 2014/04/05 03:35:13 Done.
1569 base::CommandLine* command_line) {
1570 default_small_wallpaper_file_ = command_line->GetSwitchValuePath(
1571 ash::switches::kAshDefaultWallpaperSmall);
1572 default_large_wallpaper_file_ = command_line->GetSwitchValuePath(
1573 ash::switches::kAshDefaultWallpaperLarge);
1574 guest_small_wallpaper_file_ =
1575 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall);
1576 guest_large_wallpaper_file_ =
1577 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge);
1578 default_wallpaper_image_.reset();
1579 }
1580
1458 } // namespace chromeos 1581 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698