Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3322)

Unified Diff: chrome/browser/image_decoder.cc

Issue 1028543002: Turn the utility process image decoder into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/image_decoder.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/image_decoder.cc
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
index 7d26e8053b1041e221efa4b2f7a865b535a22215..a4b1f0d8a1223f651981963e4c584ff8a1234220 100644
--- a/chrome/browser/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -5,12 +5,17 @@
#include "chrome/browser/image_decoder.h"
#include "base/bind.h"
+#include "base/callback.h"
#include "base/thread_task_runner_handle.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 "components/image_decoder/public/interfaces/image_decoder.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/utility_process_host.h"
+#include "content/public/common/service_registry.h"
+#include "skia/public/type_converters.h"
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
@@ -25,6 +30,21 @@ base::LazyInstance<ImageDecoder>::Leaky g_decoder = LAZY_INSTANCE_INITIALIZER;
// batch mode.
const int kBatchModeTimeoutSeconds = 5;
+void OnDecodeImageDone(
+ base::Callback<void(int)> fail_callback,
+ base::Callback<void(const SkBitmap&, int)> success_callback,
+ int request_id, skia::BitmapPtr image) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (image) {
+ SkBitmap bitmap = image.To<SkBitmap>();
+ if (!bitmap.empty()) {
+ success_callback.Run(bitmap, request_id);
+ return;
+ }
+ }
+ fail_callback.Run(request_id);
+}
+
} // namespace
ImageDecoder::ImageDecoder()
@@ -133,17 +153,33 @@ void ImageDecoder::DecodeImageInSandbox(
}
batch_mode_timer_->Reset();
- switch (image_codec) {
+ if (switches::MojoUtilityServicesEnabled()) {
+ image_decoder::ImageCodec mojo_codec = image_decoder::IMAGE_CODEC_DEFAULT;
+#if defined(OS_CHROMEOS)
+ if (image_codec == ROBUST_JPEG_CODEC)
+ mojo_codec = image_decoder::IMAGE_CODEC_ROBUST_JPEG;
+#endif // defined(OS_CHROMEOS)
+ (*decoder_)->DecodeImage(
+ mojo::Array<uint8_t>::From(image_data),
+ mojo_codec,
+ shrink_to_fit,
+ base::Bind(&OnDecodeImageDone,
+ base::Bind(&ImageDecoder::OnDecodeImageFailed, this),
+ base::Bind(&ImageDecoder::OnDecodeImageSucceeded, this),
+ request_id));
+ } else {
+ 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;
+ }
}
}
@@ -166,9 +202,20 @@ void ImageDecoder::StartBatchMode() {
this, base::ThreadTaskRunnerHandle::Get().get())->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(new image_decoder::ImageDecoderPtr);
+ if (!utility_process_host_->StartMojoMode()) {
+ utility_process_host_.reset();
+ return;
+ }
+ content::ServiceRegistry* service_registry =
+ utility_process_host_->GetServiceRegistry();
+ service_registry->ConnectToRemoteService(mojo::GetProxy(decoder_.get()));
+ } else {
+ if (!utility_process_host_->StartBatchMode()) {
+ utility_process_host_.reset();
+ return;
+ }
}
}
@@ -184,7 +231,14 @@ 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();
+ decoder_.reset();
+ } else {
+ utility_process_host_->EndBatchMode();
+ }
utility_process_host_.reset();
}
}
« no previous file with comments | « chrome/browser/image_decoder.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698