| Index: chrome/browser/image_decoder.cc
|
| diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
|
| index 7d26e8053b1041e221efa4b2f7a865b535a22215..04ce78bf071f86c95b1117c2b8c6f20692d68671 100644
|
| --- a/chrome/browser/image_decoder.cc
|
| +++ b/chrome/browser/image_decoder.cc
|
| @@ -10,6 +10,8 @@
|
| #include "chrome/common/chrome_utility_messages.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/child_process_data.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/utility_process_host.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -54,6 +56,14 @@ ImageDecoder::ImageRequest::~ImageRequest() {
|
| }
|
|
|
| // static
|
| +void ImageDecoder::StartByFilePath(
|
| + ImageRequest* image_request, const base::FilePath& image_file_path) {
|
| + g_decoder.Pointer()->StartWithOptionsImpl(image_request,
|
| + image_file_path, std::string(),
|
| + DEFAULT_CODEC, false);
|
| +}
|
| +
|
| +// static
|
| void ImageDecoder::Start(ImageRequest* image_request,
|
| const std::string& image_data) {
|
| StartWithOptions(image_request, image_data, DEFAULT_CODEC, false);
|
| @@ -64,17 +74,28 @@ void ImageDecoder::StartWithOptions(ImageRequest* image_request,
|
| const std::string& image_data,
|
| ImageCodec image_codec,
|
| bool shrink_to_fit) {
|
| - g_decoder.Pointer()->StartWithOptionsImpl(image_request, image_data,
|
| + g_decoder.Pointer()->StartWithOptionsImpl(image_request,
|
| + base::FilePath(), image_data,
|
| image_codec, shrink_to_fit);
|
| }
|
|
|
| void ImageDecoder::StartWithOptionsImpl(ImageRequest* image_request,
|
| + const base::FilePath& image_file_path,
|
| const std::string& image_data,
|
| ImageCodec image_codec,
|
| bool shrink_to_fit) {
|
| DCHECK(image_request);
|
| DCHECK(image_request->task_runner());
|
|
|
| + base::File image_file;
|
| + std::vector<unsigned char> image_data_vec;
|
| + if (!image_file_path.empty()) {
|
| + image_file.Initialize(image_file_path,
|
| + base::File::FLAG_OPEN | base::File::FLAG_READ);
|
| + } else {
|
| + image_data_vec.assign(image_data.begin(), image_data.end());
|
| + }
|
| +
|
| int request_id;
|
| {
|
| base::AutoLock lock(map_lock_);
|
| @@ -87,8 +108,8 @@ void ImageDecoder::StartWithOptionsImpl(ImageRequest* image_request,
|
| base::Bind(
|
| &ImageDecoder::DecodeImageInSandbox,
|
| g_decoder.Pointer(), request_id,
|
| - std::vector<unsigned char>(image_data.begin(), image_data.end()),
|
| - image_codec, shrink_to_fit));
|
| + base::Passed(image_file.Pass()),
|
| + image_data_vec, image_codec, shrink_to_fit));
|
| }
|
|
|
| // static
|
| @@ -99,6 +120,7 @@ void ImageDecoder::Cancel(ImageRequest* image_request) {
|
|
|
| void ImageDecoder::DecodeImageInSandbox(
|
| int request_id,
|
| + base::File image_file,
|
| const std::vector<unsigned char>& image_data,
|
| ImageCodec image_codec,
|
| bool shrink_to_fit) {
|
| @@ -133,17 +155,32 @@ void ImageDecoder::DecodeImageInSandbox(
|
| }
|
| batch_mode_timer_->Reset();
|
|
|
| - switch (image_codec) {
|
| + if (!image_data.empty()) {
|
| + switch (image_codec) {
|
| #if defined(OS_CHROMEOS)
|
| - case ROBUST_JPEG_CODEC:
|
| - utility_process_host_->Send(new ChromeUtilityMsg_RobustJPEGDecodeImage(
|
| - image_data, request_id));
|
| - break;
|
| + case ROBUST_JPEG_CODEC:
|
| + utility_process_host_->Send(new ChromeUtilityMsg_RobustJPEGDecodeImage(
|
| + image_data, request_id));
|
| + break;
|
| #endif // defined(OS_CHROMEOS)
|
| - case DEFAULT_CODEC:
|
| - utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage(
|
| - image_data, shrink_to_fit, request_id));
|
| - break;
|
| + case DEFAULT_CODEC:
|
| + utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage(
|
| + image_data, shrink_to_fit, request_id));
|
| + break;
|
| + }
|
| + } else if (image_file.IsValid() && image_codec == DEFAULT_CODEC) {
|
| + base::ProcessHandle utility_process =
|
| + content::RenderProcessHost::run_renderer_in_process() ?
|
| + base::GetCurrentProcessHandle() :
|
| + utility_process_host_->GetData().handle;
|
| +
|
| + utility_process_host_->Send(new ChromeUtilityMsg_DecodeImageByHandle(
|
| + IPC::TakeFileHandleForProcess(image_file.Pass(), utility_process),
|
| + shrink_to_fit, request_id));
|
| + } else {
|
| + image_request->task_runner()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&ImageDecoder::RunOnDecodeImageFailed, this, request_id));
|
| }
|
| }
|
|
|
|
|