Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, | 279 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, |
| 280 this, "")); | 280 this, "")); |
| 281 LOG(ERROR) << "Failed to create wallpaper directory."; | 281 LOG(ERROR) << "Failed to create wallpaper directory."; |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 std::string file_name = GURL(url_).ExtractFileName(); | 284 std::string file_name = GURL(url_).ExtractFileName(); |
| 285 FilePath file_path = wallpaper_dir.Append(file_name); | 285 FilePath file_path = wallpaper_dir.Append(file_name); |
| 286 if (file_util::PathExists(file_path) || | 286 if (file_util::PathExists(file_path) || |
| 287 file_util::WriteFile(file_path, image_data_.c_str(), | 287 file_util::WriteFile(file_path, image_data_.c_str(), |
| 288 image_data_.size()) != -1 ) { | 288 image_data_.size()) != -1 ) { |
| 289 wallpaper_.EnsureRepsForSupportedScaleFactors(); | |
| 290 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy()); | |
| 291 // ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if | |
| 292 // post to another thread. | |
|
oshima
2012/11/12 16:39:28
I think you don't have to do this IF you make
wall
bshe
2012/11/12 19:12:48
I may understand this wrong. But it looks to me th
oshima
2012/11/13 17:46:42
I see, you're right.
| |
| 289 BrowserThread::PostTask( | 293 BrowserThread::PostTask( |
| 290 BrowserThread::UI, FROM_HERE, | 294 BrowserThread::UI, FROM_HERE, |
| 291 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, | 295 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, |
| 292 this)); | 296 this, base::Passed(&deep_copy))); |
| 293 chromeos::UserImage wallpaper(wallpaper_); | 297 chromeos::UserImage wallpaper(wallpaper_); |
| 294 | 298 |
| 295 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to | 299 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to |
| 296 // maintain the aspect ratio after resize. | 300 // maintain the aspect ratio after resize. |
| 297 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( | 301 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( |
| 298 wallpaper, | 302 wallpaper, |
| 299 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix), | 303 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix), |
| 300 ash::CENTER_CROPPED, | 304 ash::CENTER_CROPPED, |
| 301 ash::kSmallWallpaperMaxWidth, | 305 ash::kSmallWallpaperMaxWidth, |
| 302 ash::kSmallWallpaperMaxHeight); | 306 ash::kSmallWallpaperMaxHeight); |
| 303 } else { | 307 } else { |
| 304 BrowserThread::PostTask( | 308 BrowserThread::PostTask( |
| 305 BrowserThread::UI, FROM_HERE, | 309 BrowserThread::UI, FROM_HERE, |
| 306 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, | 310 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, |
| 307 this, "")); | 311 this, "")); |
| 308 LOG(ERROR) << "Failed to save downloaded wallpaper."; | 312 LOG(ERROR) << "Failed to save downloaded wallpaper."; |
| 309 } | 313 } |
| 310 } | 314 } |
| 311 | 315 |
| 312 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() { | 316 void WallpaperSetWallpaperFunction::SetDecodedWallpaper( |
| 317 scoped_ptr<gfx::ImageSkia> wallpaper) { | |
| 313 chromeos::WallpaperManager* wallpaper_manager = | 318 chromeos::WallpaperManager* wallpaper_manager = |
| 314 chromeos::WallpaperManager::Get(); | 319 chromeos::WallpaperManager::Get(); |
| 315 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_); | 320 wallpaper_manager->SetWallpaperFromImageSkia(*wallpaper.get(), layout_); |
| 316 bool is_persistent = | 321 bool is_persistent = |
| 317 !chromeos::UserManager::Get()->IsCurrentUserEphemeral(); | 322 !chromeos::UserManager::Get()->IsCurrentUserEphemeral(); |
| 318 chromeos::WallpaperInfo info = { | 323 chromeos::WallpaperInfo info = { |
| 319 url_, | 324 url_, |
| 320 layout_, | 325 layout_, |
| 321 chromeos::User::ONLINE, | 326 chromeos::User::ONLINE, |
| 322 base::Time::Now().LocalMidnight() | 327 base::Time::Now().LocalMidnight() |
| 323 }; | 328 }; |
| 324 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); | 329 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); |
| 325 SendResponse(true); | 330 SendResponse(true); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 } | 391 } |
| 387 | 392 |
| 388 WallpaperRestoreMinimizedWindowsFunction:: | 393 WallpaperRestoreMinimizedWindowsFunction:: |
| 389 ~WallpaperRestoreMinimizedWindowsFunction() { | 394 ~WallpaperRestoreMinimizedWindowsFunction() { |
| 390 } | 395 } |
| 391 | 396 |
| 392 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { | 397 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { |
| 393 WindowStateManager::RestoreWindows(); | 398 WindowStateManager::RestoreWindows(); |
| 394 return true; | 399 return true; |
| 395 } | 400 } |
| OLD | NEW |