Index: chrome/browser/image_decoder.cc |
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc |
index 17e885754f9b01f0f3f5ccde9832e152e768ef32..23245cf757d3a570a479a2975d72cee30684508f 100644 |
--- a/chrome/browser/image_decoder.cc |
+++ b/chrome/browser/image_decoder.cc |
@@ -8,10 +8,14 @@ |
#include "base/bind.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_utility_messages.h" |
#include "chrome/grit/generated_resources.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/utility_process_host.h" |
+#include "content/public/common/service_registry.h" |
+#include "services/image_decoder/public/interfaces/image_decoder.mojom.h" |
+#include "skia/public/type_converters.h" |
#include "ui/base/l10n/l10n_util.h" |
using content::BrowserThread; |
@@ -217,15 +221,24 @@ void ImageDecoder::DecodeImageInSandbox( |
it->second->SetStarted(); |
} |
- switch (image_codec) { |
- case ROBUST_JPEG_CODEC: |
- utility_process_host_->Send( |
- new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data, request_id)); |
- break; |
- case DEFAULT_CODEC: |
- utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage( |
- image_data, shrink_to_fit, request_id)); |
- break; |
+ if (switches::MojoUtilityServicesEnabled()) { |
+ decoder_->DecodeImage( |
+ mojo::Array<uint8_t>::From(image_data), |
+ image_codec == ROBUST_JPEG_CODEC ? services::IMAGE_CODEC_ROBUST_JPEG |
+ : services::IMAGE_CODEC_DEFAULT, |
+ shrink_to_fit, |
+ base::Bind(&ImageDecoder::OnDecodeImageDone, this, request_id)); |
+ } else { |
+ switch (image_codec) { |
+ case ROBUST_JPEG_CODEC: |
+ utility_process_host_->Send( |
+ new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data, request_id)); |
+ break; |
+ case DEFAULT_CODEC: |
+ utility_process_host_->Send(new ChromeUtilityMsg_DecodeImage( |
+ image_data, shrink_to_fit, request_id)); |
+ break; |
+ } |
} |
} |
@@ -256,9 +269,20 @@ void ImageDecoder::StartBatchMode() { |
->AsWeakPtr(); |
utility_process_host_->SetName(l10n_util::GetStringUTF16( |
IDS_UTILITY_PROCESS_IMAGE_DECODER_NAME)); |
- if (!utility_process_host_->StartBatchMode()) { |
- utility_process_host_.reset(); |
- return; |
+ if (switches::MojoUtilityServicesEnabled()) { |
+ decoder_.reset(); |
+ if (!utility_process_host_->StartMojoMode()) { |
+ utility_process_host_.reset(); |
+ return; |
+ } |
+ content::ServiceRegistry* service_registry = |
+ utility_process_host_->GetServiceRegistry(); |
+ service_registry->ConnectToRemoteService(&decoder_); |
+ } else { |
+ if (!utility_process_host_->StartBatchMode()) { |
+ utility_process_host_.reset(); |
+ return; |
+ } |
} |
batch_mode_timer_.Start( |
FROM_HERE, base::TimeDelta::FromSeconds(kBatchModeTimeoutSeconds), |
@@ -273,8 +297,15 @@ void ImageDecoder::StopBatchMode() { |
} |
if (utility_process_host_) { |
- utility_process_host_->EndBatchMode(); |
+ if (switches::MojoUtilityServicesEnabled()) { |
+ // In Mojo, the utility process needs to be explicitly shut down by |
+ // deleting the host. |
+ delete utility_process_host_.get(); |
+ } else { |
+ utility_process_host_->EndBatchMode(); |
+ } |
utility_process_host_.reset(); |
+ decoder_.reset(); |
Theresa
2015/04/13 18:52:27
nit: decoder_ only needs to be reset if mojo is en
Anand Mistry (off Chromium)
2015/05/01 06:49:03
Done.
|
} |
batch_mode_timer_.Stop(); |
@@ -358,6 +389,18 @@ void ImageDecoder::OnDecodeImageFailed(int request_id) { |
job->NotifyDecodeFailed(); |
} |
+void ImageDecoder::OnDecodeImageDone(int request_id, skia::BitmapPtr image) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ if (image) { |
+ SkBitmap bitmap = image->To<SkBitmap>(); |
+ if (!bitmap.empty()) { |
+ OnDecodeImageSucceeded(bitmap, request_id); |
+ return; |
+ } |
+ } |
+ OnDecodeImageFailed(request_id); |
+} |
+ |
void ImageDecoder::RemoveJob(const scoped_refptr<Job>& job) { |
base::AutoLock lock(map_lock_); |
for (auto it = image_request_id_map_.begin(); |