Index: chrome/browser/image_decoder.cc |
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc |
index 7d26e8053b1041e221efa4b2f7a865b535a22215..e454d008f61fc4fa14487810b4010c8f1ce97005 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" |
@@ -55,6 +57,14 @@ ImageDecoder::ImageRequest::~ImageRequest() { |
// static |
void ImageDecoder::Start(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,25 @@ 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; |
+ if (!image_file_path.empty()) { |
+ image_file.Initialize(image_file_path, |
+ base::File::FLAG_OPEN | base::File::FLAG_READ); |
asanka
2015/06/11 03:30:51
Indentation is off.
yoshiki
2015/06/11 08:22:09
Done.
|
+ } |
+ |
int request_id; |
{ |
base::AutoLock lock(map_lock_); |
@@ -87,6 +105,7 @@ void ImageDecoder::StartWithOptionsImpl(ImageRequest* image_request, |
base::Bind( |
&ImageDecoder::DecodeImageInSandbox, |
g_decoder.Pointer(), request_id, |
+ base::Passed(image_file.Pass()), |
std::vector<unsigned char>(image_data.begin(), image_data.end()), |
image_codec, shrink_to_fit)); |
} |
@@ -99,6 +118,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 +153,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)); |
} |
} |