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" |
(...skipping 12 matching lines...) Expand all Loading... | |
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 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 |
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 Loading... | |
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() |
212 desktop_background_controller()-> | 225 ->desktop_background_controller() |
213 SetCustomWallpaper(user_wallpaper_, info_.layout); | 226 ->SetWallpaperImage(user_wallpaper_, info_.layout); |
214 } else if (!wallpaper_path_.empty()) { | 227 } else if (!wallpaper_path_.empty()) { |
215 manager->task_runner_->PostTask( | 228 manager->task_runner_->PostTask( |
216 FROM_HERE, | 229 FROM_HERE, |
217 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 230 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
218 base::Unretained(manager), | 231 base::Unretained(manager), |
219 user_id_, | 232 user_id_, |
220 info_, | 233 info_, |
221 wallpaper_path_, | 234 wallpaper_path_, |
222 true /* update wallpaper */, | 235 true /* update wallpaper */, |
223 base::Passed(on_finish_.Pass()))); | 236 base::Passed(on_finish_.Pass()))); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 g_wallpaper_manager = new WallpaperManager(); | 312 g_wallpaper_manager = new WallpaperManager(); |
300 return g_wallpaper_manager; | 313 return g_wallpaper_manager; |
301 } | 314 } |
302 | 315 |
303 WallpaperManager::WallpaperManager() | 316 WallpaperManager::WallpaperManager() |
304 : loaded_wallpapers_(0), | 317 : loaded_wallpapers_(0), |
305 command_line_for_testing_(NULL), | 318 command_line_for_testing_(NULL), |
306 should_cache_wallpaper_(false), | 319 should_cache_wallpaper_(false), |
307 weak_factory_(this), | 320 weak_factory_(this), |
308 pending_inactive_(NULL) { | 321 pending_inactive_(NULL) { |
322 SetDefaultWallpaperPathsFromCommandLine( | |
323 base::CommandLine::ForCurrentProcess()); | |
309 registrar_.Add(this, | 324 registrar_.Add(this, |
310 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 325 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
311 content::NotificationService::AllSources()); | 326 content::NotificationService::AllSources()); |
312 registrar_.Add(this, | 327 registrar_.Add(this, |
313 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 328 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
314 content::NotificationService::AllSources()); | 329 content::NotificationService::AllSources()); |
315 registrar_.Add(this, | 330 registrar_.Add(this, |
316 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 331 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
317 content::NotificationService::AllSources()); | 332 content::NotificationService::AllSources()); |
318 sequence_token_ = BrowserThread::GetBlockingPool()-> | 333 sequence_token_ = BrowserThread::GetBlockingPool()-> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 } | 440 } |
426 | 441 |
427 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 442 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
428 info); | 443 info); |
429 } | 444 } |
430 | 445 |
431 void WallpaperManager::InitializeWallpaper() { | 446 void WallpaperManager::InitializeWallpaper() { |
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
433 UserManager* user_manager = UserManager::Get(); | 448 UserManager* user_manager = UserManager::Get(); |
434 | 449 |
435 CommandLine* command_line = GetComandLine(); | 450 CommandLine* command_line = GetCommandLine(); |
436 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 451 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
437 // Guest wallpaper should be initialized when guest login. | 452 // Guest wallpaper should be initialized when guest login. |
438 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 453 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
439 // used here to determine if current user is guest. | 454 // used here to determine if current user is guest. |
440 return; | 455 return; |
441 } | 456 } |
442 | 457 |
443 if (command_line->HasSwitch(::switches::kTestType)) | 458 if (command_line->HasSwitch(::switches::kTestType)) |
444 WizardController::SetZeroDelays(); | 459 WizardController::SetZeroDelays(); |
445 | 460 |
(...skipping 24 matching lines...) Expand all Loading... | |
470 ClearDisposableWallpaperCache(); | 485 ClearDisposableWallpaperCache(); |
471 BrowserThread::PostDelayedTask( | 486 BrowserThread::PostDelayedTask( |
472 BrowserThread::UI, | 487 BrowserThread::UI, |
473 FROM_HERE, | 488 FROM_HERE, |
474 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper, | 489 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper, |
475 weak_factory_.GetWeakPtr()), | 490 weak_factory_.GetWeakPtr()), |
476 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds)); | 491 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds)); |
477 break; | 492 break; |
478 } | 493 } |
479 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 494 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
480 if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) { | 495 if (!GetCommandLine()->HasSwitch(switches::kDisableBootAnimation)) { |
481 BrowserThread::PostDelayedTask( | 496 BrowserThread::PostDelayedTask( |
482 BrowserThread::UI, FROM_HERE, | 497 BrowserThread::UI, FROM_HERE, |
483 base::Bind(&WallpaperManager::CacheUsersWallpapers, | 498 base::Bind(&WallpaperManager::CacheUsersWallpapers, |
484 weak_factory_.GetWeakPtr()), | 499 weak_factory_.GetWeakPtr()), |
485 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); | 500 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
486 } else { | 501 } else { |
487 should_cache_wallpaper_ = true; | 502 should_cache_wallpaper_ = true; |
488 } | 503 } |
489 break; | 504 break; |
490 } | 505 } |
(...skipping 22 matching lines...) Expand all Loading... | |
513 prefs::kUsersWallpaperInfo); | 528 prefs::kUsersWallpaperInfo); |
514 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); | 529 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); |
515 DeleteUserWallpapers(user_id, info.file); | 530 DeleteUserWallpapers(user_id, info.file); |
516 } | 531 } |
517 | 532 |
518 bool WallpaperManager::ResizeWallpaper( | 533 bool WallpaperManager::ResizeWallpaper( |
519 const UserImage& wallpaper, | 534 const UserImage& wallpaper, |
520 ash::WallpaperLayout layout, | 535 ash::WallpaperLayout layout, |
521 int preferred_width, | 536 int preferred_width, |
522 int preferred_height, | 537 int preferred_height, |
523 scoped_refptr<base::RefCountedBytes>* output) const { | 538 scoped_refptr<base::RefCountedBytes>* output, |
539 gfx::ImageSkia* output_skia) const { | |
524 DCHECK(BrowserThread::GetBlockingPool()-> | 540 DCHECK(BrowserThread::GetBlockingPool()-> |
525 IsRunningSequenceOnCurrentThread(sequence_token_)); | 541 IsRunningSequenceOnCurrentThread(sequence_token_)); |
526 int width = wallpaper.image().width(); | 542 int width = wallpaper.image().width(); |
527 int height = wallpaper.image().height(); | 543 int height = wallpaper.image().height(); |
528 int resized_width; | 544 int resized_width; |
529 int resized_height; | 545 int resized_height; |
530 *output = new base::RefCountedBytes(); | 546 *output = new base::RefCountedBytes(); |
531 | 547 |
532 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { | 548 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { |
533 // Do not resize custom wallpaper if it is smaller than preferred size. | 549 // Do not resize custom wallpaper if it is smaller than preferred size. |
(...skipping 26 matching lines...) Expand all Loading... | |
560 | 576 |
561 SkBitmap image = *(resized_image.bitmap()); | 577 SkBitmap image = *(resized_image.bitmap()); |
562 SkAutoLockPixels lock_input(image); | 578 SkAutoLockPixels lock_input(image); |
563 gfx::JPEGCodec::Encode( | 579 gfx::JPEGCodec::Encode( |
564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 580 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
565 gfx::JPEGCodec::FORMAT_SkBitmap, | 581 gfx::JPEGCodec::FORMAT_SkBitmap, |
566 image.width(), | 582 image.width(), |
567 image.height(), | 583 image.height(), |
568 image.width() * image.bytesPerPixel(), | 584 image.width() * image.bytesPerPixel(), |
569 kDefaultEncodingQuality, &(*output)->data()); | 585 kDefaultEncodingQuality, &(*output)->data()); |
586 | |
587 if (output_skia) { | |
588 resized_image.MakeThreadSafe(); | |
589 *output_skia = resized_image; | |
590 } | |
591 | |
570 return true; | 592 return true; |
571 } | 593 } |
572 | 594 |
573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, | 595 bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
574 const base::FilePath& path, | 596 const base::FilePath& path, |
575 ash::WallpaperLayout layout, | 597 ash::WallpaperLayout layout, |
576 int preferred_width, | 598 int preferred_width, |
577 int preferred_height) const { | 599 int preferred_height, |
600 gfx::ImageSkia* result) const { | |
578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 601 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 602 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
580 if (base::PathExists(path)) | 603 if (base::PathExists(path)) |
581 base::DeleteFile(path, false); | 604 base::DeleteFile(path, false); |
582 return; | 605 return false; |
583 } | 606 } |
584 scoped_refptr<base::RefCountedBytes> data; | 607 scoped_refptr<base::RefCountedBytes> data; |
585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, | 608 if (ResizeWallpaper(wallpaper, |
586 &data)) { | 609 layout, |
587 SaveWallpaperInternal(path, | 610 preferred_width, |
588 reinterpret_cast<const char*>(data->front()), | 611 preferred_height, |
589 data->size()); | 612 &data, |
613 result)) { | |
614 return SaveWallpaperInternal( | |
615 path, reinterpret_cast<const char*>(data->front()), data->size()); | |
590 } | 616 } |
617 return false; | |
591 } | 618 } |
592 | 619 |
593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { | 620 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
594 chromeos::WallpaperInfo info; | 621 chromeos::WallpaperInfo info; |
595 if (!GetUserWallpaperInfo(user_id, &info)) | 622 if (!GetUserWallpaperInfo(user_id, &info)) |
596 return false; | 623 return false; |
597 return info.type == chromeos::User::POLICY; | 624 return info.type == chromeos::User::POLICY; |
598 } | 625 } |
599 | 626 |
600 void WallpaperManager::OnPolicySet(const std::string& policy, | 627 void WallpaperManager::OnPolicySet(const std::string& policy, |
(...skipping 20 matching lines...) Expand all Loading... | |
621 return; | 648 return; |
622 | 649 |
623 wallpaper_loader_->Start( | 650 wallpaper_loader_->Start( |
624 data.Pass(), | 651 data.Pass(), |
625 0, // Do not crop. | 652 0, // Do not crop. |
626 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, | 653 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, |
627 weak_factory_.GetWeakPtr(), | 654 weak_factory_.GetWeakPtr(), |
628 user_id)); | 655 user_id)); |
629 } | 656 } |
630 | 657 |
658 // static | |
659 WallpaperManager::WallpaperResolution | |
660 WallpaperManager::GetAppropriateResolution() { | |
bshe
2014/04/07 15:49:16
nit: I believe we should have 4 space indent when
oshima
2014/04/07 17:16:11
I believe this is fine. The recommended way nowada
| |
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
662 gfx::Size size = | |
663 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); | |
664 return (size.width() > kSmallWallpaperMaxWidth || | |
665 size.height() > kSmallWallpaperMaxHeight) | |
666 ? WALLPAPER_RESOLUTION_LARGE | |
667 : WALLPAPER_RESOLUTION_SMALL; | |
668 } | |
669 | |
631 void WallpaperManager::SetPolicyControlledWallpaper( | 670 void WallpaperManager::SetPolicyControlledWallpaper( |
632 const std::string& user_id, | 671 const std::string& user_id, |
633 const UserImage& wallpaper) { | 672 const UserImage& wallpaper) { |
634 const User *user = chromeos::UserManager::Get()->FindUser(user_id); | 673 const User *user = chromeos::UserManager::Get()->FindUser(user_id); |
635 if (!user) { | 674 if (!user) { |
636 NOTREACHED() << "Unknown user."; | 675 NOTREACHED() << "Unknown user."; |
637 return; | 676 return; |
638 } | 677 } |
639 SetCustomWallpaper(user_id, | 678 SetCustomWallpaper(user_id, |
640 user->username_hash(), | 679 user->username_hash(), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 // There is no visible background in kiosk mode. | 774 // There is no visible background in kiosk mode. |
736 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 775 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
737 return; | 776 return; |
738 current_wallpaper_path_.clear(); | 777 current_wallpaper_path_.clear(); |
739 wallpaper_cache_.erase(user_id); | 778 wallpaper_cache_.erase(user_id); |
740 // Some browser tests do not have a shell instance. As no wallpaper is needed | 779 // 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 | 780 // in these tests anyway, avoid loading one, preventing crashes and speeding |
742 // up the tests. | 781 // up the tests. |
743 if (!ash::Shell::HasInstance()) | 782 if (!ash::Shell::HasInstance()) |
744 return; | 783 return; |
745 if (ash::Shell::GetInstance()->desktop_background_controller()-> | 784 |
746 SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) | 785 WallpaperResolution resolution = GetAppropriateResolution(); |
747 loaded_wallpapers_++; | 786 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
787 | |
788 const base::FilePath* file = NULL; | |
789 | |
790 if (UserManager::Get()->IsLoggedInAsGuest()) { | |
791 file = | |
792 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; | |
793 } else { | |
794 file = use_small ? &default_small_wallpaper_file_ | |
795 : &default_large_wallpaper_file_; | |
796 } | |
797 DCHECK(file); | |
798 if (!default_wallpaper_image_.get() || | |
799 default_wallpaper_image_->url().spec() != file->value()) { | |
800 default_wallpaper_image_.reset(); | |
801 if (!file->empty()) { | |
802 loaded_wallpapers_++; | |
803 StartLoadAndSetDefaultWallpaper( | |
804 *file, &default_wallpaper_image_, on_finish.Pass()); | |
805 return; | |
806 } | |
807 | |
bshe
2014/04/07 15:49:16
Should we fallback to resource wallpaper in OnDefa
Alexander Alekseev
2014/04/08 13:18:49
This is different to the way it works now (I don't
Daniel Erat
2014/04/08 14:11:16
i wouldn't recommend spending any more time on the
bshe
2014/04/08 15:00:39
I believe the original behavior is to fallback to
Daniel Erat
2014/04/08 16:27:45
the resource file is just a solid gray color. the
| |
808 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL | |
809 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; | |
810 | |
811 loaded_wallpapers_ += | |
812 ash::Shell::GetInstance() | |
813 ->desktop_background_controller() | |
814 ->SetWallpaperResource(resource_id, ash::WALLPAPER_LAYOUT_TILE); | |
815 return; | |
816 } | |
817 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | |
818 default_wallpaper_image_->image(), ash::WALLPAPER_LAYOUT_STRETCH); | |
bshe
2014/04/07 15:49:16
I believe for small resolution wallpaper, we shoul
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
748 } | 819 } |
749 | 820 |
750 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, | 821 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, |
751 bool is_persistent) { | 822 bool is_persistent) { |
752 current_user_wallpaper_info_.file = ""; | 823 current_user_wallpaper_info_.file = ""; |
753 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 824 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
754 current_user_wallpaper_info_.type = User::DEFAULT; | 825 current_user_wallpaper_info_.type = User::DEFAULT; |
755 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 826 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
756 | 827 |
757 WallpaperInfo info = current_user_wallpaper_info_; | 828 WallpaperInfo info = current_user_wallpaper_info_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 GetUserWallpaperInfo(user_id, &info); | 893 GetUserWallpaperInfo(user_id, &info); |
823 } | 894 } |
824 | 895 |
825 gfx::ImageSkia user_wallpaper; | 896 gfx::ImageSkia user_wallpaper; |
826 current_user_wallpaper_info_ = info; | 897 current_user_wallpaper_info_ = info; |
827 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { | 898 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { |
828 GetPendingWallpaper(user_id, delayed) | 899 GetPendingWallpaper(user_id, delayed) |
829 ->ResetSetWallpaperImage(user_wallpaper, info); | 900 ->ResetSetWallpaperImage(user_wallpaper, info); |
830 } else { | 901 } else { |
831 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 902 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
832 ash::WallpaperResolution resolution = | 903 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
833 ash::Shell::GetInstance()-> | |
834 desktop_background_controller()-> | |
835 GetAppropriateResolution(); | |
836 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) | |
837 ? kSmallWallpaperSubDir | |
838 : kLargeWallpaperSubDir; | |
839 | |
840 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. | 904 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. |
841 // Original wallpaper should be used in this case. | 905 // Original wallpaper should be used in this case. |
842 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 906 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
843 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) | 907 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) |
844 sub_dir = kOriginalWallpaperSubDir; | 908 sub_dir = kOriginalWallpaperSubDir; |
845 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 909 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
846 wallpaper_path = wallpaper_path.Append(info.file); | 910 wallpaper_path = wallpaper_path.Append(info.file); |
847 if (current_wallpaper_path_ == wallpaper_path) | 911 if (current_wallpaper_path_ == wallpaper_path) |
848 return; | 912 return; |
849 current_wallpaper_path_ = wallpaper_path; | 913 current_wallpaper_path_ = wallpaper_path; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 if (UserManager::IsMultipleProfilesAllowed()) | 945 if (UserManager::IsMultipleProfilesAllowed()) |
882 wallpaper_cache_[user_id] = wallpaper; | 946 wallpaper_cache_[user_id] = wallpaper; |
883 | 947 |
884 if (update_wallpaper) { | 948 if (update_wallpaper) { |
885 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) | 949 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) |
886 ->ResetSetWallpaperImage(wallpaper, info); | 950 ->ResetSetWallpaperImage(wallpaper, info); |
887 } | 951 } |
888 } | 952 } |
889 | 953 |
890 void WallpaperManager::UpdateWallpaper(bool clear_cache) { | 954 void WallpaperManager::UpdateWallpaper(bool clear_cache) { |
955 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting()); | |
891 if (clear_cache) | 956 if (clear_cache) |
892 wallpaper_cache_.clear(); | 957 wallpaper_cache_.clear(); |
893 current_wallpaper_path_.clear(); | 958 current_wallpaper_path_.clear(); |
894 // For GAIA login flow, the last_selected_user_ may not be set before user | 959 // 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 | 960 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will |
896 // be set. It could result a black screen on external monitors. | 961 // be set. It could result a black screen on external monitors. |
897 // See http://crbug.com/265689 for detail. | 962 // See http://crbug.com/265689 for detail. |
898 if (last_selected_user_.empty()) { | 963 if (last_selected_user_.empty()) { |
899 SetDefaultWallpaperNow(UserManager::kSignInUser); | 964 SetDefaultWallpaperNow(UserManager::kSignInUser); |
900 return; | 965 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
946 } | 1011 } |
947 | 1012 |
948 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { | 1013 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { |
949 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) | 1014 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) |
950 return; | 1015 return; |
951 WallpaperInfo info; | 1016 WallpaperInfo info; |
952 if (GetUserWallpaperInfo(user_id, &info)) { | 1017 if (GetUserWallpaperInfo(user_id, &info)) { |
953 base::FilePath wallpaper_dir; | 1018 base::FilePath wallpaper_dir; |
954 base::FilePath wallpaper_path; | 1019 base::FilePath wallpaper_path; |
955 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 1020 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
956 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> | 1021 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
957 desktop_background_controller()->GetAppropriateResolution(); | |
958 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? | |
959 kSmallWallpaperSubDir : kLargeWallpaperSubDir; | |
960 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 1022 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
961 wallpaper_path = wallpaper_path.Append(info.file); | 1023 wallpaper_path = wallpaper_path.Append(info.file); |
962 task_runner_->PostTask( | 1024 task_runner_->PostTask( |
963 FROM_HERE, | 1025 FROM_HERE, |
964 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 1026 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
965 base::Unretained(this), | 1027 base::Unretained(this), |
966 user_id, | 1028 user_id, |
967 info, | 1029 info, |
968 wallpaper_path, | 1030 wallpaper_path, |
969 false /* do not update wallpaper */, | 1031 false /* do not update wallpaper */, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 1125 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
1064 dir = dir.Append(user_id_hash); | 1126 dir = dir.Append(user_id_hash); |
1065 if (!base::PathExists(dir)) | 1127 if (!base::PathExists(dir)) |
1066 base::CreateDirectory(dir); | 1128 base::CreateDirectory(dir); |
1067 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); | 1129 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); |
1068 dir = dir.Append(user_id_hash); | 1130 dir = dir.Append(user_id_hash); |
1069 if (!base::PathExists(dir)) | 1131 if (!base::PathExists(dir)) |
1070 base::CreateDirectory(dir); | 1132 base::CreateDirectory(dir); |
1071 } | 1133 } |
1072 | 1134 |
1073 CommandLine* WallpaperManager::GetComandLine() { | 1135 void WallpaperManager::set_command_line_for_testing( |
1136 base::CommandLine* command_line) { | |
1137 command_line_for_testing_ = command_line; | |
1138 SetDefaultWallpaperPathsFromCommandLine(command_line); | |
1139 } | |
1140 | |
1141 CommandLine* WallpaperManager::GetCommandLine() { | |
1074 CommandLine* command_line = command_line_for_testing_ ? | 1142 CommandLine* command_line = command_line_for_testing_ ? |
1075 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | 1143 command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
1076 return command_line; | 1144 return command_line; |
1077 } | 1145 } |
1078 | 1146 |
1079 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 1147 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
1080 if (UserManager::Get()->IsUserLoggedIn()) | 1148 if (UserManager::Get()->IsUserLoggedIn()) |
1081 return; | 1149 return; |
1082 | 1150 |
1083 bool disable_boot_animation = GetComandLine()-> | 1151 bool disable_boot_animation = |
1084 HasSwitch(switches::kDisableBootAnimation); | 1152 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
1085 bool show_users = true; | 1153 bool show_users = true; |
1086 bool result = CrosSettings::Get()->GetBoolean( | 1154 bool result = CrosSettings::Get()->GetBoolean( |
1087 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 1155 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
1088 DCHECK(result) << "Unable to fetch setting " | 1156 DCHECK(result) << "Unable to fetch setting " |
1089 << kAccountsPrefShowUserNamesOnSignIn; | 1157 << kAccountsPrefShowUserNamesOnSignIn; |
1090 const chromeos::UserList& users = UserManager::Get()->GetUsers(); | 1158 const chromeos::UserList& users = UserManager::Get()->GetUsers(); |
1091 if (!show_users || users.empty()) { | 1159 if (!show_users || users.empty()) { |
1092 // Boot into sign in form, preload default wallpaper. | 1160 // Boot into sign in form, preload default wallpaper. |
1093 SetDefaultWallpaperDelayed(UserManager::kSignInUser); | 1161 SetDefaultWallpaperDelayed(UserManager::kSignInUser); |
1094 return; | 1162 return; |
1095 } | 1163 } |
1096 | 1164 |
1097 if (!disable_boot_animation) { | 1165 if (!disable_boot_animation) { |
1098 // Normal boot, load user wallpaper. | 1166 // Normal boot, load user wallpaper. |
1099 // If normal boot animation is disabled wallpaper would be set | 1167 // If normal boot animation is disabled wallpaper would be set |
1100 // asynchronously once user pods are loaded. | 1168 // asynchronously once user pods are loaded. |
1101 SetUserWallpaperDelayed(users[0]->email()); | 1169 SetUserWallpaperDelayed(users[0]->email()); |
1102 } | 1170 } |
1103 } | 1171 } |
1104 | 1172 |
1105 void WallpaperManager::LoadWallpaper(const std::string& user_id, | 1173 void WallpaperManager::LoadWallpaper(const std::string& user_id, |
1106 const WallpaperInfo& info, | 1174 const WallpaperInfo& info, |
1107 bool update_wallpaper, | 1175 bool update_wallpaper, |
1108 MovableOnDestroyCallbackHolder on_finish) { | 1176 MovableOnDestroyCallbackHolder on_finish) { |
1109 base::FilePath wallpaper_dir; | 1177 base::FilePath wallpaper_dir; |
1110 base::FilePath wallpaper_path; | 1178 base::FilePath wallpaper_path; |
1111 if (info.type == User::ONLINE) { | 1179 if (info.type == User::ONLINE) { |
1112 std::string file_name = GURL(info.file).ExtractFileName(); | 1180 std::string file_name = GURL(info.file).ExtractFileName(); |
1113 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> | 1181 WallpaperResolution resolution = GetAppropriateResolution(); |
1114 desktop_background_controller()->GetAppropriateResolution(); | |
1115 // Only solid color wallpapers have stretch layout and they have only one | 1182 // Only solid color wallpapers have stretch layout and they have only one |
1116 // resolution. | 1183 // resolution. |
1117 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && | 1184 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && |
1118 resolution == ash::WALLPAPER_RESOLUTION_SMALL) { | 1185 resolution == WALLPAPER_RESOLUTION_SMALL) { |
1119 file_name = base::FilePath(file_name).InsertBeforeExtension( | 1186 file_name = base::FilePath(file_name).InsertBeforeExtension( |
1120 kSmallWallpaperSuffix).value(); | 1187 kSmallWallpaperSuffix).value(); |
1121 } | 1188 } |
1122 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); | 1189 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); |
1123 wallpaper_path = wallpaper_dir.Append(file_name); | 1190 wallpaper_path = wallpaper_dir.Append(file_name); |
1124 if (current_wallpaper_path_ == wallpaper_path) | 1191 if (current_wallpaper_path_ == wallpaper_path) |
1125 return; | 1192 return; |
1126 | 1193 |
1127 if (update_wallpaper) | 1194 if (update_wallpaper) |
1128 current_wallpaper_path_ = wallpaper_path; | 1195 current_wallpaper_path_ = wallpaper_path; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 return; | 1381 return; |
1315 } | 1382 } |
1316 | 1383 |
1317 // Only cache the user wallpaper at login screen and for multi profile users. | 1384 // Only cache the user wallpaper at login screen and for multi profile users. |
1318 if (!UserManager::Get()->IsUserLoggedIn() || | 1385 if (!UserManager::Get()->IsUserLoggedIn() || |
1319 UserManager::IsMultipleProfilesAllowed()) { | 1386 UserManager::IsMultipleProfilesAllowed()) { |
1320 wallpaper_cache_[user_id] = wallpaper.image(); | 1387 wallpaper_cache_[user_id] = wallpaper.image(); |
1321 } | 1388 } |
1322 | 1389 |
1323 if (update_wallpaper) { | 1390 if (update_wallpaper) { |
1324 ash::Shell::GetInstance()->desktop_background_controller()-> | 1391 ash::Shell::GetInstance() |
1325 SetCustomWallpaper(wallpaper.image(), layout); | 1392 ->desktop_background_controller() |
1393 ->SetWallpaperImage(wallpaper.image(), layout); | |
1326 } | 1394 } |
1327 } | 1395 } |
1328 | 1396 |
1329 void WallpaperManager::ProcessCustomWallpaper( | 1397 void WallpaperManager::ProcessCustomWallpaper( |
1330 const std::string& user_id_hash, | 1398 const std::string& user_id_hash, |
1331 bool persistent, | 1399 bool persistent, |
1332 const WallpaperInfo& info, | 1400 const WallpaperInfo& info, |
1333 scoped_ptr<gfx::ImageSkia> image, | 1401 scoped_ptr<gfx::ImageSkia> image, |
1334 const UserImage::RawImage& raw_image) { | 1402 const UserImage::RawImage& raw_image) { |
1335 DCHECK(BrowserThread::GetBlockingPool()-> | 1403 DCHECK(BrowserThread::GetBlockingPool()-> |
(...skipping 14 matching lines...) Expand all Loading... | |
1350 EnsureCustomWallpaperDirectories(user_id_hash); | 1418 EnsureCustomWallpaperDirectories(user_id_hash); |
1351 std::string file_name = original_path.BaseName().value(); | 1419 std::string file_name = original_path.BaseName().value(); |
1352 base::FilePath small_wallpaper_path = | 1420 base::FilePath small_wallpaper_path = |
1353 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); | 1421 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); |
1354 base::FilePath large_wallpaper_path = | 1422 base::FilePath large_wallpaper_path = |
1355 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); | 1423 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); |
1356 | 1424 |
1357 // Re-encode orginal file to jpeg format and saves the result in case that | 1425 // 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 | 1426 // resized wallpaper is not generated (i.e. chrome shutdown before resized |
1359 // wallpaper is saved). | 1427 // wallpaper is saved). |
1360 ResizeAndSaveWallpaper(wallpaper, original_path, | 1428 ResizeAndSaveWallpaper(wallpaper, |
1429 original_path, | |
1361 ash::WALLPAPER_LAYOUT_STRETCH, | 1430 ash::WALLPAPER_LAYOUT_STRETCH, |
1362 wallpaper.image().width(), | 1431 wallpaper.image().width(), |
1363 wallpaper.image().height()); | 1432 wallpaper.image().height(), |
1433 NULL); | |
1364 DeleteAllExcept(original_path); | 1434 DeleteAllExcept(original_path); |
1365 | 1435 |
1366 ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, | 1436 ResizeAndSaveWallpaper(wallpaper, |
1367 ash::kSmallWallpaperMaxWidth, | 1437 small_wallpaper_path, |
1368 ash::kSmallWallpaperMaxHeight); | 1438 layout, |
1439 kSmallWallpaperMaxWidth, | |
1440 kSmallWallpaperMaxHeight, | |
1441 NULL); | |
1369 DeleteAllExcept(small_wallpaper_path); | 1442 DeleteAllExcept(small_wallpaper_path); |
1370 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, | 1443 ResizeAndSaveWallpaper(wallpaper, |
1371 ash::kLargeWallpaperMaxWidth, | 1444 large_wallpaper_path, |
1372 ash::kLargeWallpaperMaxHeight); | 1445 layout, |
1446 kLargeWallpaperMaxWidth, | |
1447 kLargeWallpaperMaxHeight, | |
1448 NULL); | |
1373 DeleteAllExcept(large_wallpaper_path); | 1449 DeleteAllExcept(large_wallpaper_path); |
1374 } | 1450 } |
1375 | 1451 |
1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1452 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1453 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
1378 User::WALLPAPER_TYPE_COUNT); | 1454 User::WALLPAPER_TYPE_COUNT); |
1379 } | 1455 } |
1380 | 1456 |
1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, | 1457 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
1382 const char* data, | 1458 const char* data, |
1383 int size) const { | 1459 int size) const { |
1384 int written_bytes = base::WriteFile(path, data, size); | 1460 int written_bytes = base::WriteFile(path, data, size); |
1385 DCHECK(written_bytes == size); | 1461 return written_bytes == size; |
1386 } | 1462 } |
1387 | 1463 |
1388 void WallpaperManager::StartLoad(const std::string& user_id, | 1464 void WallpaperManager::StartLoad(const std::string& user_id, |
1389 const WallpaperInfo& info, | 1465 const WallpaperInfo& info, |
1390 bool update_wallpaper, | 1466 bool update_wallpaper, |
1391 const base::FilePath& wallpaper_path, | 1467 const base::FilePath& wallpaper_path, |
1392 MovableOnDestroyCallbackHolder on_finish) { | 1468 MovableOnDestroyCallbackHolder on_finish) { |
1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1470 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
1395 | 1471 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 if (!pending_inactive_) { | 1524 if (!pending_inactive_) { |
1449 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1525 loading_.push_back(new WallpaperManager::PendingWallpaper( |
1450 (delayed ? GetWallpaperLoadDelay() | 1526 (delayed ? GetWallpaperLoadDelay() |
1451 : base::TimeDelta::FromMilliseconds(0)), | 1527 : base::TimeDelta::FromMilliseconds(0)), |
1452 user_id)); | 1528 user_id)); |
1453 pending_inactive_ = loading_.back(); | 1529 pending_inactive_ = loading_.back(); |
1454 } | 1530 } |
1455 return pending_inactive_; | 1531 return pending_inactive_; |
1456 } | 1532 } |
1457 | 1533 |
1534 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( | |
1535 base::CommandLine* command_line) { | |
1536 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | |
1537 ash::switches::kAshDefaultWallpaperSmall); | |
1538 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | |
1539 ash::switches::kAshDefaultWallpaperLarge); | |
1540 guest_small_wallpaper_file_ = | |
1541 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | |
1542 guest_large_wallpaper_file_ = | |
1543 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | |
1544 default_wallpaper_image_.reset(); | |
1545 } | |
1546 | |
1547 void WallpaperManager::OnDefaultWallpaperDecoded( | |
1548 const base::FilePath& path, | |
1549 scoped_ptr<chromeos::UserImage>* result, | |
1550 MovableOnDestroyCallbackHolder on_finish, | |
1551 const UserImage& wallpaper) { | |
1552 result->reset(new UserImage(wallpaper.image())); | |
1553 (*result)->set_url(GURL(path.value())); | |
1554 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | |
1555 wallpaper.image(), ash::WALLPAPER_LAYOUT_STRETCH); | |
1556 } | |
1557 | |
1558 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | |
1559 const base::FilePath& path, | |
1560 scoped_ptr<chromeos::UserImage>* result, | |
1561 MovableOnDestroyCallbackHolder on_finish) { | |
1562 wallpaper_loader_->Start( | |
1563 path.value(), | |
1564 0, // Do not crop. | |
1565 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | |
1566 weak_factory_.GetWeakPtr(), | |
1567 path, | |
1568 base::Unretained(result), | |
1569 base::Passed(on_finish.Pass()))); | |
1570 } | |
1571 | |
1572 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { | |
1573 WallpaperResolution resolution = GetAppropriateResolution(); | |
1574 return (resolution == WALLPAPER_RESOLUTION_SMALL) ? kSmallWallpaperSubDir | |
Daniel Erat
2014/04/07 13:57:00
nit: remove parentheses around return value
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
1575 : kLargeWallpaperSubDir; | |
1576 } | |
1577 | |
1458 } // namespace chromeos | 1578 } // namespace chromeos |
OLD | NEW |