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

Unified Diff: chrome/browser/image_decoder.cc

Issue 865543002: WIP: Browser image decoding using Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add DecodeImageBase64. Created 5 years, 11 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_utility.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 2f9e83b7ab8953f41eb2d5a4bfc091e8f7e81ce7..af6e3d1e2071ed5e706cbe505efcc4fdb71ca4c5 100644
--- a/chrome/browser/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -6,9 +6,11 @@
#include "base/bind.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/common/chrome_utility_messages.h"
+#include "content/common/image_decoder.mojom.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
+#include "content/public/common/service_registry.h"
using content::BrowserThread;
using content::UtilityProcessHost;
@@ -33,7 +35,9 @@ ImageDecoder::ImageDecoder(Delegate* delegate,
shrink_to_fit_(false) {
}
-ImageDecoder::~ImageDecoder() {}
+ImageDecoder::~ImageDecoder() {
+ LOG(INFO) << "Destorying browser-side ImageDecoder";
+}
void ImageDecoder::Start(scoped_refptr<base::SequencedTaskRunner> task_runner) {
task_runner_ = task_runner;
@@ -42,40 +46,42 @@ void ImageDecoder::Start(scoped_refptr<base::SequencedTaskRunner> task_runner) {
base::Bind(&ImageDecoder::DecodeImageInSandbox, this, image_data_));
}
-bool ImageDecoder::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message)
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded,
- OnDecodeImageSucceeded)
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed,
- OnDecodeImageFailed)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void ImageDecoder::OnDecodeImageSucceeded(const SkBitmap& decoded_image) {
- DCHECK(task_runner_->RunsTasksOnCurrentThread());
- if (delegate_)
- delegate_->OnImageDecoded(this, decoded_image);
-}
-
-void ImageDecoder::OnDecodeImageFailed() {
- DCHECK(task_runner_->RunsTasksOnCurrentThread());
- if (delegate_)
- delegate_->OnDecodeImageFailed(this);
+void ImageDecoder::OnDecodeImageDone(bool success,
+ content::ImageDataPtr image) {
+ LOG(INFO) << "ImageDecoder::OnDecodeImageDone: " << success;
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (delegate_) {
+ if (success && image) {
+ SkBitmap bitmap = image.To<SkBitmap>();
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&Delegate::OnImageDecoded,
+ base::Unretained(delegate_),
+ base::Unretained(this),
+ bitmap));
+ } else {
+ task_runner_->PostTask(FROM_HERE,
+ base::Bind(&Delegate::OnDecodeImageFailed,
+ base::Unretained(delegate_),
+ base::Unretained(this)));
+ }
+ }
+ decoder_.reset();
}
void ImageDecoder::DecodeImageInSandbox(
const std::vector<unsigned char>& image_data) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ LOG(INFO) << "ImageDecoder::DecodeImageInSandbox";
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
UtilityProcessHost* utility_process_host;
- utility_process_host = UtilityProcessHost::Create(this, task_runner_.get());
- if (image_codec_ == ROBUST_JPEG_CODEC) {
- utility_process_host->Send(
- new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data));
- } else {
- utility_process_host->Send(
- new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_));
- }
+ utility_process_host = UtilityProcessHost::Create(
+ scoped_refptr<content::UtilityProcessHostClient>(), task_runner_.get());
+ utility_process_host->StartMojoMode();
+ content::ServiceRegistry* service_registry =
+ utility_process_host->GetServiceRegistry();
+ service_registry->ConnectToRemoteService(&decoder_);
+
+ decoder_->DecodeImage(mojo::Array<uint8_t>::From(image_data),
+ image_codec_ == ROBUST_JPEG_CODEC,
+ shrink_to_fit_,
+ base::Bind(&ImageDecoder::OnDecodeImageDone, this));
}
« no previous file with comments | « chrome/browser/image_decoder.h ('k') | chrome/chrome_utility.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698