| 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/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/window_cycle_controller.h" | 10 #include "ash/wm/window_cycle_controller.h" |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 bool WallpaperPrivateSetCustomWallpaperFunction::RunImpl() { | 518 bool WallpaperPrivateSetCustomWallpaperFunction::RunImpl() { |
| 519 BinaryValue* input = NULL; | 519 BinaryValue* input = NULL; |
| 520 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(0, &input)); | 520 EXTENSION_FUNCTION_VALIDATE(args_->GetBinary(0, &input)); |
| 521 | 521 |
| 522 std::string layout_string; | 522 std::string layout_string; |
| 523 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &layout_string)); | 523 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &layout_string)); |
| 524 EXTENSION_FUNCTION_VALIDATE(!layout_string.empty()); | 524 EXTENSION_FUNCTION_VALIDATE(!layout_string.empty()); |
| 525 layout_ = GetLayoutEnum(layout_string); | 525 layout_ = GetLayoutEnum(layout_string); |
| 526 | 526 |
| 527 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(2, &generate_thumbnail_)); |
| 528 |
| 529 EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &file_name_)); |
| 530 EXTENSION_FUNCTION_VALIDATE(!file_name_.empty()); |
| 531 |
| 527 // Gets email address while at UI thread. | 532 // Gets email address while at UI thread. |
| 528 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email(); | 533 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email(); |
| 529 | 534 |
| 530 image_data_.assign(input->GetBuffer(), input->GetSize()); | 535 image_data_.assign(input->GetBuffer(), input->GetSize()); |
| 531 StartDecode(image_data_); | 536 StartDecode(image_data_); |
| 532 | 537 |
| 533 return true; | 538 return true; |
| 534 } | 539 } |
| 535 | 540 |
| 536 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( | 541 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( |
| 537 const gfx::ImageSkia& wallpaper) { | 542 const gfx::ImageSkia& wallpaper) { |
| 538 chromeos::WallpaperManager* wallpaper_manager = | 543 chromeos::WallpaperManager* wallpaper_manager = |
| 539 chromeos::WallpaperManager::Get(); | 544 chromeos::WallpaperManager::Get(); |
| 540 chromeos::UserImage::RawImage raw_image(image_data_.begin(), | 545 chromeos::UserImage::RawImage raw_image(image_data_.begin(), |
| 541 image_data_.end()); | 546 image_data_.end()); |
| 542 chromeos::UserImage image(wallpaper, raw_image); | 547 chromeos::UserImage image(wallpaper, raw_image); |
| 543 std::string file = base::Int64ToString(base::Time::Now().ToInternalValue()); | |
| 544 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( | 548 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( |
| 545 chromeos::kThumbnailWallpaperSubDir, email_, file); | 549 chromeos::kThumbnailWallpaperSubDir, email_, file_name_); |
| 546 | 550 |
| 547 sequence_token_ = BrowserThread::GetBlockingPool()-> | 551 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| 548 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); | 552 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); |
| 549 scoped_refptr<base::SequencedTaskRunner> task_runner = | 553 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 550 BrowserThread::GetBlockingPool()-> | 554 BrowserThread::GetBlockingPool()-> |
| 551 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 555 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
| 552 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 556 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 553 | 557 |
| 554 wallpaper.EnsureRepsForSupportedScaleFactors(); | |
| 555 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy()); | |
| 556 // Generates thumbnail before call api function callback. We can then request | |
| 557 // thumbnail in the javascript callback. | |
| 558 task_runner->PostTask(FROM_HERE, | |
| 559 base::Bind(&WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, | |
| 560 this, thumbnail_path, base::Passed(&deep_copy))); | |
| 561 | |
| 562 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate | 558 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate |
| 563 // to refresh thumbnail. Uses a null delegate here. | 559 // to refresh thumbnail. Uses a null delegate here. |
| 564 wallpaper_manager->SetCustomWallpaper(email_, file, layout_, | 560 wallpaper_manager->SetCustomWallpaper(email_, file_name_, layout_, |
| 565 chromeos::User::CUSTOMIZED, | 561 chromeos::User::CUSTOMIZED, |
| 566 image); | 562 image); |
| 567 wallpaper_decoder_ = NULL; | 563 wallpaper_decoder_ = NULL; |
| 564 |
| 565 if (generate_thumbnail_) { |
| 566 wallpaper.EnsureRepsForSupportedScaleFactors(); |
| 567 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy()); |
| 568 // Generates thumbnail before call api function callback. We can then |
| 569 // request thumbnail in the javascript callback. |
| 570 task_runner->PostTask(FROM_HERE, |
| 571 base::Bind( |
| 572 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, |
| 573 this, thumbnail_path, base::Passed(&deep_copy))); |
| 574 } else { |
| 575 SendResponse(true); |
| 576 } |
| 568 } | 577 } |
| 569 | 578 |
| 570 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( | 579 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( |
| 571 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 580 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { |
| 572 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 581 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 573 sequence_token_)); | 582 sequence_token_)); |
| 574 chromeos::UserImage wallpaper(*image.get()); | 583 chromeos::UserImage wallpaper(*image.get()); |
| 575 if (!file_util::PathExists(thumbnail_path.DirName())) | 584 if (!file_util::PathExists(thumbnail_path.DirName())) |
| 576 file_util::CreateDirectory(thumbnail_path.DirName()); | 585 file_util::CreateDirectory(thumbnail_path.DirName()); |
| 577 | 586 |
| 578 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( | 587 scoped_refptr<base::RefCountedBytes> data; |
| 588 chromeos::WallpaperManager::Get()->ResizeWallpaper( |
| 579 wallpaper, | 589 wallpaper, |
| 580 thumbnail_path, | |
| 581 ash::WALLPAPER_LAYOUT_STRETCH, | 590 ash::WALLPAPER_LAYOUT_STRETCH, |
| 582 ash::kWallpaperThumbnailWidth, | 591 ash::kWallpaperThumbnailWidth, |
| 583 ash::kWallpaperThumbnailHeight); | 592 ash::kWallpaperThumbnailHeight, |
| 584 std::string file_name = thumbnail_path.BaseName().value(); | 593 &data); |
| 585 BrowserThread::PostTask( | 594 BrowserThread::PostTask( |
| 586 BrowserThread::UI, FROM_HERE, | 595 BrowserThread::UI, FROM_HERE, |
| 587 base::Bind( | 596 base::Bind( |
| 588 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, | 597 &WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated, |
| 589 this, file_name)); | 598 this, data)); |
| 590 } | 599 } |
| 591 | 600 |
| 592 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( | 601 void WallpaperPrivateSetCustomWallpaperFunction::ThumbnailGenerated( |
| 593 const std::string& file_name) { | 602 base::RefCountedBytes* data) { |
| 594 SetResult(new base::StringValue(file_name)); | 603 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( |
| 604 reinterpret_cast<const char*>(data->front()), data->size()); |
| 605 SetResult(result); |
| 595 SendResponse(true); | 606 SendResponse(true); |
| 596 } | 607 } |
| 597 | 608 |
| 598 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 609 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
| 599 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 610 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
| 600 | 611 |
| 601 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 612 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
| 602 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 613 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
| 603 | 614 |
| 604 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunImpl() { | 615 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunImpl() { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 this, file_list)); | 878 this, file_list)); |
| 868 } | 879 } |
| 869 | 880 |
| 870 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 881 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 871 const std::vector<std::string>& file_list) { | 882 const std::vector<std::string>& file_list) { |
| 872 ListValue* results = new ListValue(); | 883 ListValue* results = new ListValue(); |
| 873 results->AppendStrings(file_list); | 884 results->AppendStrings(file_list); |
| 874 SetResult(results); | 885 SetResult(results); |
| 875 SendResponse(true); | 886 SendResponse(true); |
| 876 } | 887 } |
| OLD | NEW |