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/shell.h" | 10 #include "ash/shell.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
42 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/gfx/codec/jpeg_codec.h" | 43 #include "ui/gfx/codec/jpeg_codec.h" |
44 #include "ui/gfx/image/image_skia_operations.h" | 44 #include "ui/gfx/image/image_skia_operations.h" |
45 #include "ui/gfx/skia_util.h" | 45 #include "ui/gfx/skia_util.h" |
46 | 46 |
47 using content::BrowserThread; | 47 using content::BrowserThread; |
48 | 48 |
49 namespace chromeos { | |
50 | |
bshe
2014/03/24 21:30:49
nit: these should implemented before testApi class
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
51 class WallpaperManager::CustomizedWallpaperRescaledFiles { | |
bshe
2014/03/24 21:30:49
nit: can you move the definition to .h file. Also,
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
52 public: | |
53 CustomizedWallpaperRescaledFiles(const base::FilePath& path_rescaled_original, | |
54 const base::FilePath& path_rescaled_small, | |
55 const base::FilePath& path_rescaled_large); | |
56 | |
57 base::FilePath path_rescaled_original; | |
bshe
2014/03/24 21:30:49
nit: the name is misleading. The original file is
Alexander Alekseev
2014/03/25 14:38:29
The original file is rescaled to get safe image:
| |
58 base::FilePath path_rescaled_small; | |
59 base::FilePath path_rescaled_large; | |
60 }; | |
61 | |
62 WallpaperManager::CustomizedWallpaperRescaledFiles:: | |
63 CustomizedWallpaperRescaledFiles( | |
64 const base::FilePath& path_rescaled_original, | |
65 const base::FilePath& path_rescaled_small, | |
66 const base::FilePath& path_rescaled_large) | |
67 : path_rescaled_original(path_rescaled_original), | |
68 path_rescaled_small(path_rescaled_small), | |
69 path_rescaled_large(path_rescaled_large) { | |
70 } | |
71 | |
72 class WallpaperManager::CustomizedWallpaperFilesExist { | |
73 public: | |
74 CustomizedWallpaperFilesExist(); | |
75 | |
76 bool AllRescaledExist() const; | |
77 | |
78 bool dowloaded; | |
79 bool rescaled_original; | |
80 bool rescaled_small; | |
81 bool rescaled_large; | |
82 }; | |
83 | |
84 WallpaperManager::CustomizedWallpaperFilesExist::CustomizedWallpaperFilesExist() | |
85 : dowloaded(false), | |
86 rescaled_original(false), | |
87 rescaled_small(false), | |
88 rescaled_large(false) { | |
89 } | |
90 | |
91 bool WallpaperManager::CustomizedWallpaperFilesExist::AllRescaledExist() const { | |
92 return rescaled_original && rescaled_small && rescaled_large; | |
93 } | |
94 | |
49 namespace { | 95 namespace { |
50 | 96 |
51 // The amount of delay before starts to move custom wallpapers to the new place. | 97 // The amount of delay before starts to move custom wallpapers to the new place. |
52 const int kMoveCustomWallpaperDelaySeconds = 30; | 98 const int kMoveCustomWallpaperDelaySeconds = 30; |
53 | 99 |
54 // Default quality for encoding wallpaper. | 100 // Default quality for encoding wallpaper. |
55 const int kDefaultEncodingQuality = 90; | 101 const int kDefaultEncodingQuality = 90; |
56 | 102 |
57 // A dictionary pref that maps usernames to file paths to their wallpapers. | 103 // A dictionary pref that maps usernames to file paths to their wallpapers. |
58 // Deprecated. Will remove this const char after done migration. | 104 // Deprecated. Will remove this const char after done migration. |
(...skipping 22 matching lines...) Expand all Loading... | |
81 | 127 |
82 // Minimum delay between wallpaper loads, milliseconds. | 128 // Minimum delay between wallpaper loads, milliseconds. |
83 const unsigned kLoadMinDelayMs = 50; | 129 const unsigned kLoadMinDelayMs = 50; |
84 | 130 |
85 // Default wallpaper load delay, milliseconds. | 131 // Default wallpaper load delay, milliseconds. |
86 const unsigned kLoadDefaultDelayMs = 200; | 132 const unsigned kLoadDefaultDelayMs = 200; |
87 | 133 |
88 // Maximum wallpaper load delay, milliseconds. | 134 // Maximum wallpaper load delay, milliseconds. |
89 const unsigned kLoadMaxDelayMs = 2000; | 135 const unsigned kLoadMaxDelayMs = 2000; |
90 | 136 |
137 // Customized wallpaer is rescaled and resized to three versions | |
138 // with given suffixes: | |
139 const char kCustomizedWallpaperOriginalFileSuffix[] = ".original.jpg"; | |
140 const char kCustomizedWallpaperSmallFileSuffix[] = ".small.jpg"; | |
141 const char kCustomizedWallpaperLargeFileSuffix[] = ".large.jpg"; | |
bshe
2014/03/24 21:30:49
nit: can you reuse kSmallWallpaperSuffix and kLarg
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
142 | |
91 // For our scaling ratios we need to round positive numbers. | 143 // For our scaling ratios we need to round positive numbers. |
92 int RoundPositive(double x) { | 144 int RoundPositive(double x) { |
93 return static_cast<int>(floor(x + 0.5)); | 145 return static_cast<int>(floor(x + 0.5)); |
94 } | 146 } |
95 | 147 |
96 // Returns custom wallpaper directory by appending corresponding |sub_dir|. | 148 // Returns custom wallpaper directory by appending corresponding |sub_dir|. |
97 base::FilePath GetCustomWallpaperDir(const char* sub_dir) { | 149 base::FilePath GetCustomWallpaperDir(const char* sub_dir) { |
98 base::FilePath custom_wallpaper_dir; | 150 base::FilePath custom_wallpaper_dir; |
99 CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS, | 151 CHECK(PathService::Get(chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS, |
100 &custom_wallpaper_dir)); | 152 &custom_wallpaper_dir)); |
101 return custom_wallpaper_dir.Append(sub_dir); | 153 return custom_wallpaper_dir.Append(sub_dir); |
102 } | 154 } |
103 | 155 |
104 bool MoveCustomWallpaperDirectory(const char* sub_dir, | 156 bool MoveCustomWallpaperDirectory(const char* sub_dir, |
105 const std::string& user_id, | 157 const std::string& user_id, |
106 const std::string& user_id_hash) { | 158 const std::string& user_id_hash) { |
107 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); | 159 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); |
108 base::FilePath to_path = base_path.Append(user_id_hash); | 160 base::FilePath to_path = base_path.Append(user_id_hash); |
109 base::FilePath from_path = base_path.Append(user_id); | 161 base::FilePath from_path = base_path.Append(user_id); |
110 if (base::PathExists(from_path)) | 162 if (base::PathExists(from_path)) |
111 return base::Move(from_path, to_path); | 163 return base::Move(from_path, to_path); |
112 return false; | 164 return false; |
113 } | 165 } |
114 | 166 |
167 void CheckCustomizedWallpaperFilesExist( | |
168 const base::FilePath& downloaded_file, | |
169 const WallpaperManager::CustomizedWallpaperRescaledFiles* rescaled_files, | |
170 WallpaperManager::CustomizedWallpaperFilesExist* exist) { | |
171 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
bshe
2014/03/24 21:30:49
nit: worker pool thread instead of FILE?
Alexander Alekseev
2014/03/25 14:38:29
Do you know simple way to check for worker pool?
| |
172 DCHECK(rescaled_files); | |
173 DCHECK(exist); | |
174 exist->dowloaded = base::PathExists(downloaded_file); | |
175 exist->rescaled_original = | |
176 base::PathExists(rescaled_files->path_rescaled_original); | |
177 exist->rescaled_small = base::PathExists(rescaled_files->path_rescaled_small); | |
178 exist->rescaled_large = base::PathExists(rescaled_files->path_rescaled_large); | |
179 } | |
180 | |
115 } // namespace | 181 } // namespace |
116 | 182 |
117 namespace chromeos { | 183 // namespace chromeos |
118 | |
119 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 184 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
120 | 185 |
121 const char kSmallWallpaperSuffix[] = "_small"; | 186 const char kSmallWallpaperSuffix[] = "_small"; |
122 const char kLargeWallpaperSuffix[] = "_large"; | 187 const char kLargeWallpaperSuffix[] = "_large"; |
123 | 188 |
124 const char kSmallWallpaperSubDir[] = "small"; | 189 const char kSmallWallpaperSubDir[] = "small"; |
125 const char kLargeWallpaperSubDir[] = "large"; | 190 const char kLargeWallpaperSubDir[] = "large"; |
126 const char kOriginalWallpaperSubDir[] = "original"; | 191 const char kOriginalWallpaperSubDir[] = "original"; |
127 const char kThumbnailWallpaperSubDir[] = "thumb"; | 192 const char kThumbnailWallpaperSubDir[] = "thumb"; |
128 | 193 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 gfx::JPEGCodec::Encode( | 628 gfx::JPEGCodec::Encode( |
564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 629 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
565 gfx::JPEGCodec::FORMAT_SkBitmap, | 630 gfx::JPEGCodec::FORMAT_SkBitmap, |
566 image.width(), | 631 image.width(), |
567 image.height(), | 632 image.height(), |
568 image.width() * image.bytesPerPixel(), | 633 image.width() * image.bytesPerPixel(), |
569 kDefaultEncodingQuality, &(*output)->data()); | 634 kDefaultEncodingQuality, &(*output)->data()); |
570 return true; | 635 return true; |
571 } | 636 } |
572 | 637 |
573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, | 638 bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
574 const base::FilePath& path, | 639 const base::FilePath& path, |
575 ash::WallpaperLayout layout, | 640 ash::WallpaperLayout layout, |
576 int preferred_width, | 641 int preferred_width, |
577 int preferred_height) const { | 642 int preferred_height) const { |
578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 643 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 644 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
580 if (base::PathExists(path)) | 645 if (base::PathExists(path)) |
581 base::DeleteFile(path, false); | 646 base::DeleteFile(path, false); |
582 return; | 647 return false; |
583 } | 648 } |
584 scoped_refptr<base::RefCountedBytes> data; | 649 scoped_refptr<base::RefCountedBytes> data; |
585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, | 650 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, |
586 &data)) { | 651 &data)) { |
587 SaveWallpaperInternal(path, | 652 return SaveWallpaperInternal( |
588 reinterpret_cast<const char*>(data->front()), | 653 path, reinterpret_cast<const char*>(data->front()), data->size()); |
589 data->size()); | |
590 } | 654 } |
655 return false; | |
591 } | 656 } |
592 | 657 |
593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { | 658 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
594 chromeos::WallpaperInfo info; | 659 chromeos::WallpaperInfo info; |
595 if (!GetUserWallpaperInfo(user_id, &info)) | 660 if (!GetUserWallpaperInfo(user_id, &info)) |
596 return false; | 661 return false; |
597 return info.type == chromeos::User::POLICY; | 662 return info.type == chromeos::User::POLICY; |
598 } | 663 } |
599 | 664 |
600 void WallpaperManager::OnPolicySet(const std::string& policy, | 665 void WallpaperManager::OnPolicySet(const std::string& policy, |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1371 ash::kLargeWallpaperMaxWidth, | 1436 ash::kLargeWallpaperMaxWidth, |
1372 ash::kLargeWallpaperMaxHeight); | 1437 ash::kLargeWallpaperMaxHeight); |
1373 DeleteAllExcept(large_wallpaper_path); | 1438 DeleteAllExcept(large_wallpaper_path); |
1374 } | 1439 } |
1375 | 1440 |
1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1441 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1442 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
1378 User::WALLPAPER_TYPE_COUNT); | 1443 User::WALLPAPER_TYPE_COUNT); |
1379 } | 1444 } |
1380 | 1445 |
1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, | 1446 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
1382 const char* data, | 1447 const char* data, |
1383 int size) const { | 1448 int size) const { |
1384 int written_bytes = base::WriteFile(path, data, size); | 1449 int written_bytes = base::WriteFile(path, data, size); |
1385 DCHECK(written_bytes == size); | 1450 DCHECK(written_bytes == size); |
bshe
2014/03/24 21:30:49
nit: DCHECK is probably not necessary in this case
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1451 return written_bytes == size; | |
1386 } | 1452 } |
1387 | 1453 |
1388 void WallpaperManager::StartLoad(const std::string& user_id, | 1454 void WallpaperManager::StartLoad(const std::string& user_id, |
1389 const WallpaperInfo& info, | 1455 const WallpaperInfo& info, |
1390 bool update_wallpaper, | 1456 bool update_wallpaper, |
1391 const base::FilePath& wallpaper_path, | 1457 const base::FilePath& wallpaper_path, |
1392 MovableOnDestroyCallbackHolder on_finish) { | 1458 MovableOnDestroyCallbackHolder on_finish) { |
1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1460 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
1395 | 1461 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 if (!pending_inactive_) { | 1514 if (!pending_inactive_) { |
1449 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1515 loading_.push_back(new WallpaperManager::PendingWallpaper( |
1450 (delayed ? GetWallpaperLoadDelay() | 1516 (delayed ? GetWallpaperLoadDelay() |
1451 : base::TimeDelta::FromMilliseconds(0)), | 1517 : base::TimeDelta::FromMilliseconds(0)), |
1452 user_id)); | 1518 user_id)); |
1453 pending_inactive_ = loading_.back(); | 1519 pending_inactive_ = loading_.back(); |
1454 } | 1520 } |
1455 return pending_inactive_; | 1521 return pending_inactive_; |
1456 } | 1522 } |
1457 | 1523 |
1524 // static | |
bshe
2014/03/24 21:30:49
GetCustomizedWallpaperDefaultRescaledSmallFileName
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1525 base::FilePath | |
1526 WallpaperManager::GetCustomizedWallpaperDefaultRescaledSmallFileName() { | |
bshe
2014/03/24 21:30:49
nit: 4 space indent please
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1527 const base::FilePath default_downloaded_file_name = | |
1528 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | |
1529 const base::FilePath default_cache_dir = | |
1530 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | |
1531 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | |
1532 return base::FilePath(); | |
1533 return default_cache_dir.Append( | |
1534 default_downloaded_file_name.BaseName().value() + | |
1535 kCustomizedWallpaperSmallFileSuffix); | |
1536 } | |
1537 | |
1538 // static | |
1539 base::FilePath | |
1540 WallpaperManager::GetCustomizedWallpaperDefaultRescaledLargeFileName() { | |
bshe
2014/03/24 21:30:49
nit: 4 space indent please
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1541 const base::FilePath default_downloaded_file_name = | |
1542 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | |
1543 const base::FilePath default_cache_dir = | |
1544 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | |
1545 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | |
1546 return base::FilePath(); | |
1547 return default_cache_dir.Append( | |
1548 default_downloaded_file_name.BaseName().value() + | |
1549 kCustomizedWallpaperLargeFileSuffix); | |
1550 } | |
1551 | |
1552 void WallpaperManager::SetCustomizedDefaultWallpaper( | |
1553 const GURL& wallpaper_url, | |
1554 const base::FilePath& downloaded_file, | |
1555 const base::FilePath& resized_directory) { | |
1556 // Should fail if this ever happens in tests. | |
1557 DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty()); | |
bshe
2014/03/24 21:30:49
nit: you shouldn't need to handle failed DCHECK ca
Alexander Alekseev
2014/03/25 14:38:29
This is one of a few cases when we should fail in
| |
1558 if (!wallpaper_url.is_valid()) { | |
1559 if (!wallpaper_url.is_empty()) { | |
1560 LOG(WARNING) << "Invalid Customized Wallpaper URL."; | |
1561 } | |
1562 return; | |
1563 } | |
1564 std::string downloaded_file_name = downloaded_file.BaseName().value(); | |
1565 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( | |
1566 new CustomizedWallpaperRescaledFiles( | |
1567 resized_directory.Append(downloaded_file_name + | |
1568 kCustomizedWallpaperOriginalFileSuffix), | |
1569 resized_directory.Append(downloaded_file_name + | |
1570 kCustomizedWallpaperSmallFileSuffix), | |
1571 resized_directory.Append(downloaded_file_name + | |
1572 kCustomizedWallpaperLargeFileSuffix))); | |
1573 scoped_ptr<CustomizedWallpaperFilesExist> exist( | |
1574 new CustomizedWallpaperFilesExist); | |
1575 | |
1576 base::Closure check_file_exists = | |
1577 base::Bind(&CheckCustomizedWallpaperFilesExist, | |
1578 downloaded_file, | |
1579 base::Unretained(rescaled_files.get()), | |
1580 base::Unretained(exist.get())); | |
1581 base::Closure on_checked_closure = | |
1582 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck, | |
1583 weak_factory_.GetWeakPtr(), | |
1584 wallpaper_url, | |
1585 downloaded_file, | |
1586 base::Passed(rescaled_files.Pass()), | |
1587 base::Passed(exist.Pass())); | |
1588 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | |
1589 FROM_HERE, check_file_exists, on_checked_closure)) { | |
1590 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist."; | |
1591 } | |
1592 } | |
1593 | |
1594 void WallpaperManager::ResizeCustomizedDefaultWallpaper( | |
1595 scoped_ptr<gfx::ImageSkia> image, | |
1596 const UserImage::RawImage& raw_image, | |
1597 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
1598 bool* success) { | |
1599 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | |
1600 sequence_token_)); | |
1601 UserImage wallpaper(*image.get(), raw_image); | |
1602 | |
1603 *success = false; | |
1604 | |
1605 // Re-encode orginal file to jpeg format and saves the result in case that | |
1606 // resized wallpaper is not generated (i.e. chrome shutdown before resized | |
1607 // wallpaper is saved). | |
1608 *success |= ResizeAndSaveWallpaper(wallpaper, | |
1609 rescaled_files->path_rescaled_original, | |
1610 ash::WALLPAPER_LAYOUT_STRETCH, | |
1611 wallpaper.image().width(), | |
1612 wallpaper.image().height()); | |
1613 | |
1614 *success |= ResizeAndSaveWallpaper(wallpaper, | |
1615 rescaled_files->path_rescaled_small, | |
1616 ash::WALLPAPER_LAYOUT_STRETCH, | |
1617 ash::kSmallWallpaperMaxWidth, | |
1618 ash::kSmallWallpaperMaxHeight); | |
1619 | |
1620 *success |= ResizeAndSaveWallpaper(wallpaper, | |
1621 rescaled_files->path_rescaled_large, | |
1622 ash::WALLPAPER_LAYOUT_STRETCH, | |
1623 ash::kLargeWallpaperMaxWidth, | |
1624 ash::kLargeWallpaperMaxHeight); | |
1625 } | |
1626 | |
1627 void WallpaperManager::OnCustomizedDefaultWallpaperResized( | |
1628 const GURL& wallpaper_url, | |
1629 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1630 scoped_ptr<bool> success) { | |
1631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1632 DCHECK(rescaled_files.get()); | |
1633 DCHECK(success.get()); | |
1634 if (!*success) { | |
1635 LOG(WARNING) << "Failed to save Resized Customized Default Wallpaper"; | |
1636 return; | |
1637 } | |
1638 PrefService* prefService = g_browser_process->local_state(); | |
1639 DCHECK(prefService); | |
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
remove redundant DCHECK
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1640 prefService->SetString(prefs::kCustomizationDefaultWallpaperURL, | |
1641 wallpaper_url.spec()); | |
1642 ash::Shell::GetInstance() | |
1643 ->desktop_background_controller() | |
1644 ->SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
1645 rescaled_files->path_rescaled_large); | |
1646 VLOG(1) << "Customized Default Wallpaper applied."; | |
1647 } | |
1648 | |
1649 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( | |
1650 const GURL& wallpaper_url, | |
1651 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1652 const UserImage& wallpaper) { | |
1653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1654 | |
1655 // If decoded wallpaper is empty, we have probably failed to decode the file. | |
1656 if (wallpaper.image().isNull()) { | |
1657 LOG(WARNING) << "Failed to decode customized wallpaper."; | |
1658 return; | |
1659 } | |
1660 | |
1661 wallpaper.image().EnsureRepsForSupportedScales(); | |
1662 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
1663 | |
1664 scoped_ptr<bool> success(new bool(false)); | |
1665 | |
1666 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | |
1667 base::Closure resize_closure = | |
1668 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, | |
1669 base::Unretained(this), | |
1670 base::Passed(&deep_copy), | |
1671 wallpaper.raw_image(), | |
1672 base::Unretained(rescaled_files.get()), | |
1673 base::Unretained(success.get())); | |
1674 base::Closure on_resized_closure = | |
1675 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, | |
1676 weak_factory_.GetWeakPtr(), | |
1677 wallpaper_url, | |
1678 base::Passed(rescaled_files.Pass()), | |
1679 base::Passed(success.Pass())); | |
1680 | |
1681 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper | |
1682 // that the user selected. | |
1683 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | |
1684 BrowserThread::GetBlockingPool() | |
1685 ->GetSequencedTaskRunnerWithShutdownBehavior( | |
1686 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); | |
1687 | |
1688 if (!blocking_task_runner->PostTaskAndReply( | |
1689 FROM_HERE, resize_closure, on_resized_closure)) { | |
1690 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; | |
1691 } | |
1692 } | |
1693 | |
1694 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( | |
1695 const GURL& wallpaper_url, | |
1696 const base::FilePath& downloaded_file, | |
1697 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1698 scoped_ptr<CustomizedWallpaperFilesExist> exist) { | |
1699 PrefService* prefService = g_browser_process->local_state(); | |
1700 DCHECK(prefService); | |
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
remove redundant DCHECK
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1701 | |
1702 std::string current_url = | |
1703 prefService->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
1704 if ((current_url != wallpaper_url.spec()) || (!exist->AllRescaledExist())) { | |
1705 DCHECK(exist->dowloaded); | |
1706 // Need rescale | |
1707 wallpaper_loader_->Start( | |
1708 downloaded_file.value(), | |
1709 0, // Do not crop. | |
1710 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, | |
1711 weak_factory_.GetWeakPtr(), | |
1712 wallpaper_url, | |
1713 base::Passed(rescaled_files.Pass()))); | |
1714 } else { | |
1715 ash::Shell::GetInstance() | |
1716 ->desktop_background_controller() | |
bshe
2014/03/24 21:30:49
nit: this line seems can fit to the previous line
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1717 ->SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
1718 rescaled_files->path_rescaled_large); | |
1719 } | |
1720 } | |
1721 | |
1722 // static | |
1723 bool WallpaperManager::ShouldUseCustomizedDefaultWallpaper() { | |
1724 PrefService* prefService = g_browser_process->local_state(); | |
1725 DCHECK(prefService); | |
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
remove redundant DCHECK
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1726 | |
1727 const std::string current_url = | |
1728 prefService->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
1729 return !current_url.empty(); | |
Mattias Nissler (ping if slow)
2014/03/24 20:38:54
Is this supposed to be "if not set"? If so, consid
Alexander Alekseev
2014/03/25 14:38:29
Done.
| |
1730 } | |
1731 | |
1458 } // namespace chromeos | 1732 } // namespace chromeos |
OLD | NEW |