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/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/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 ~WallpaperPrivateSetWallpaperIfExistsFunction() {} | 286 ~WallpaperPrivateSetWallpaperIfExistsFunction() {} |
287 | 287 |
288 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunImpl() { | 288 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunImpl() { |
289 params = set_wallpaper_if_exists::Params::Create(*args_); | 289 params = set_wallpaper_if_exists::Params::Create(*args_); |
290 EXTENSION_FUNCTION_VALIDATE(params); | 290 EXTENSION_FUNCTION_VALIDATE(params); |
291 | 291 |
292 user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email(); | 292 user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email(); |
293 | 293 |
294 base::FilePath wallpaper_path; | 294 base::FilePath wallpaper_path; |
295 base::FilePath fallback_path; | 295 base::FilePath fallback_path; |
296 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> | 296 chromeos::WallpaperManager::WallpaperResolution resolution = |
297 desktop_background_controller()->GetAppropriateResolution(); | 297 chromeos::WallpaperManager::GetAppropriateResolution(); |
298 | 298 |
299 std::string file_name = GURL(params->url).ExtractFileName(); | 299 std::string file_name = GURL(params->url).ExtractFileName(); |
300 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, | 300 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, |
301 &wallpaper_path)); | 301 &wallpaper_path)); |
302 fallback_path = wallpaper_path.Append(file_name); | 302 fallback_path = wallpaper_path.Append(file_name); |
303 if (params->layout != wallpaper_private::WALLPAPER_LAYOUT_STRETCH && | 303 if (params->layout != wallpaper_private::WALLPAPER_LAYOUT_STRETCH && |
304 resolution == ash::WALLPAPER_RESOLUTION_SMALL) { | 304 resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) { |
305 file_name = base::FilePath(file_name).InsertBeforeExtension( | 305 file_name = base::FilePath(file_name).InsertBeforeExtension( |
306 chromeos::kSmallWallpaperSuffix).value(); | 306 chromeos::kSmallWallpaperSuffix).value(); |
307 } | 307 } |
308 wallpaper_path = wallpaper_path.Append(file_name); | 308 wallpaper_path = wallpaper_path.Append(file_name); |
309 | 309 |
310 sequence_token_ = BrowserThread::GetBlockingPool()-> | 310 sequence_token_ = BrowserThread::GetBlockingPool()-> |
311 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); | 311 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); |
312 scoped_refptr<base::SequencedTaskRunner> task_runner = | 312 scoped_refptr<base::SequencedTaskRunner> task_runner = |
313 BrowserThread::GetBlockingPool()-> | 313 BrowserThread::GetBlockingPool()-> |
314 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 314 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 base::FilePath file_path = wallpaper_dir.Append( | 437 base::FilePath file_path = wallpaper_dir.Append( |
438 file_name).InsertBeforeExtension(chromeos::kSmallWallpaperSuffix); | 438 file_name).InsertBeforeExtension(chromeos::kSmallWallpaperSuffix); |
439 if (base::PathExists(file_path)) | 439 if (base::PathExists(file_path)) |
440 return; | 440 return; |
441 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to | 441 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to |
442 // maintain the aspect ratio after resize. | 442 // maintain the aspect ratio after resize. |
443 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( | 443 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( |
444 wallpaper, | 444 wallpaper, |
445 file_path, | 445 file_path, |
446 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 446 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
447 ash::kSmallWallpaperMaxWidth, | 447 chromeos::kSmallWallpaperMaxWidth, |
448 ash::kSmallWallpaperMaxHeight); | 448 chromeos::kSmallWallpaperMaxHeight, |
| 449 NULL); |
449 } else { | 450 } else { |
450 std::string error = base::StringPrintf( | 451 std::string error = base::StringPrintf( |
451 "Failed to create/write wallpaper to %s.", file_name.c_str()); | 452 "Failed to create/write wallpaper to %s.", file_name.c_str()); |
452 BrowserThread::PostTask( | 453 BrowserThread::PostTask( |
453 BrowserThread::UI, FROM_HERE, | 454 BrowserThread::UI, FROM_HERE, |
454 base::Bind(&WallpaperPrivateSetWallpaperFunction::OnFailure, | 455 base::Bind(&WallpaperPrivateSetWallpaperFunction::OnFailure, |
455 this, error)); | 456 this, error)); |
456 } | 457 } |
457 } | 458 } |
458 | 459 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 580 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
580 sequence_token_)); | 581 sequence_token_)); |
581 chromeos::UserImage wallpaper(*image.get()); | 582 chromeos::UserImage wallpaper(*image.get()); |
582 if (!base::PathExists(thumbnail_path.DirName())) | 583 if (!base::PathExists(thumbnail_path.DirName())) |
583 base::CreateDirectory(thumbnail_path.DirName()); | 584 base::CreateDirectory(thumbnail_path.DirName()); |
584 | 585 |
585 scoped_refptr<base::RefCountedBytes> data; | 586 scoped_refptr<base::RefCountedBytes> data; |
586 chromeos::WallpaperManager::Get()->ResizeWallpaper( | 587 chromeos::WallpaperManager::Get()->ResizeWallpaper( |
587 wallpaper, | 588 wallpaper, |
588 ash::WALLPAPER_LAYOUT_STRETCH, | 589 ash::WALLPAPER_LAYOUT_STRETCH, |
589 ash::kWallpaperThumbnailWidth, | 590 chromeos::kWallpaperThumbnailWidth, |
590 ash::kWallpaperThumbnailHeight, | 591 chromeos::kWallpaperThumbnailHeight, |
591 &data); | 592 &data, |
| 593 NULL); |
592 BrowserThread::PostTask( | 594 BrowserThread::PostTask( |
593 BrowserThread::UI, FROM_HERE, | 595 BrowserThread::UI, FROM_HERE, |
594 base::Bind( | 596 base::Bind( |
595 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, | 597 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, |
596 this, data)); | 598 this, data)); |
597 } | 599 } |
598 | 600 |
599 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( | 601 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( |
600 base::RefCountedBytes* data) { | 602 base::RefCountedBytes* data) { |
601 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( | 603 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 this, file_list)); | 851 this, file_list)); |
850 } | 852 } |
851 | 853 |
852 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 854 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
853 const std::vector<std::string>& file_list) { | 855 const std::vector<std::string>& file_list) { |
854 base::ListValue* results = new base::ListValue(); | 856 base::ListValue* results = new base::ListValue(); |
855 results->AppendStrings(file_list); | 857 results->AppendStrings(file_list); |
856 SetResult(results); | 858 SetResult(results); |
857 SendResponse(true); | 859 SendResponse(true); |
858 } | 860 } |
OLD | NEW |