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

Unified Diff: chrome/browser/image_decoder.h

Issue 2475543003: Introduce the image_decoder service (Closed)
Patch Set: . Created 4 years, 1 month 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/chrome_content_browser_manifest_overlay.json ('k') | chrome/browser/image_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/image_decoder.h
diff --git a/chrome/browser/image_decoder.h b/chrome/browser/image_decoder.h
index 2c8160d6f3989a7e6133937035c3a6d1e9f6ee8b..d8bda97454fab4f214441aa5624a14423f0b330e 100644
--- a/chrome/browser/image_decoder.h
+++ b/chrome/browser/image_decoder.h
@@ -6,35 +6,29 @@
#define CHROME_BROWSER_IMAGE_DECODER_H_
#include <map>
-#include <memory>
#include <string>
#include <vector>
-#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "base/synchronization/lock.h"
-#include "base/timer/timer.h"
-#include "build/build_config.h"
-#include "chrome/common/image_decoder.mojom.h"
-#include "content/public/browser/utility_process_host.h"
-#include "content/public/browser/utility_process_host_client.h"
class SkBitmap;
-// This is a helper class for decoding images safely in a utility process. To
+// This is a helper class for decoding images safely in a sandboxed service. To
// use this, call ImageDecoder::Start(...) or
// ImageDecoder::StartWithOptions(...) on any thread.
//
-// Internally, most of the work happens on the IO thread, and then
-// the callback (ImageRequest::OnImageDecoded or
-// ImageRequest::OnDecodeImageFailed) is posted back to the |task_runner_|
-// associated with the ImageRequest.
-// The Cancel() method runs on whichever thread called it. |map_lock_| is used
-// to protect the data that is accessed from multiple threads.
-class ImageDecoder : public content::UtilityProcessHostClient {
+// ImageRequest::OnImageDecoded or ImageRequest::OnDecodeImageFailed is posted
+// back to the |task_runner_| associated with the ImageRequest.
+//
+// The Cancel() method runs on whichever thread called it.
+//
+// TODO(rockot): Use of this class should be replaced with direct image_decoder
+// client library usage.
+class ImageDecoder {
public:
// ImageRequest objects needs to be created and destroyed on the same
// SequencedTaskRunner.
@@ -52,8 +46,9 @@ class ImageDecoder : public content::UtilityProcessHostClient {
}
protected:
- // Creates an ImageRequest that runs on the thread creating it.
+ // Creates an ImageRequest that runs on the thread which created it.
ImageRequest();
+
// Explicitly pass in |task_runner| if the current thread is part of a
// thread pool.
explicit ImageRequest(
@@ -76,6 +71,9 @@ class ImageDecoder : public content::UtilityProcessHostClient {
#endif // defined(OS_CHROMEOS)
};
+ ImageDecoder();
+ ~ImageDecoder();
+
// Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and
// shrink_to_fit = false.
static void Start(ImageRequest* image_request,
@@ -101,54 +99,19 @@ class ImageDecoder : public content::UtilityProcessHostClient {
static void Cancel(ImageRequest* image_request);
private:
- friend struct base::DefaultLazyInstanceTraits<ImageDecoder>;
-
using RequestMap = std::map<int, ImageRequest*>;
- ImageDecoder();
- // It's a reference counted object, so destructor is private.
- ~ImageDecoder() override;
-
- // Sends a request to the sandboxed process to decode the image. Starts
- // batch mode if necessary. If the utility process fails to start,
- // an OnDecodeImageFailed task is posted to image_request's |task_runner_|.
- void DecodeImageInSandbox(int request_id,
- std::vector<uint8_t> image_data,
- ImageCodec image_codec,
- bool shrink_to_fit);
-
void StartWithOptionsImpl(ImageRequest* image_request,
std::vector<uint8_t> image_data,
ImageCodec image_codec,
bool shrink_to_fit);
- void CancelImpl(ImageRequest* image_request);
-
- // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|.
- // If the utility process fails to start, the method resets
- // |utility_process_host_| and returns.
- void StartBatchMode();
-
- // Stops batch mode if no requests have come in since
- // |kBatchModeTimeoutSeconds|.
- void StopBatchMode();
-
- // Fails all outstanding requests.
- void FailAllRequests();
- // Overidden from UtilityProcessHostClient.
- void OnProcessCrashed(int exit_code) override;
- void OnProcessLaunchFailed(int error_code) override;
- bool OnMessageReceived(const IPC::Message& message) override;
+ void CancelImpl(ImageRequest* image_request);
// IPC message handlers.
void OnDecodeImageSucceeded(const SkBitmap& decoded_image, int request_id);
void OnDecodeImageFailed(int request_id);
- // For the ImageRequest identified by |request_id|, call its OnImageDecoded()
- // or OnDecodeImageFailed() method on its task runner thread.
- void RunOnImageDecoded(const SkBitmap& decoded_image, int request_id);
- void RunOnDecodeImageFailed(int request_id);
-
// id to use for the next Start() request that comes in.
int image_request_id_counter_;
@@ -158,17 +121,6 @@ class ImageDecoder : public content::UtilityProcessHostClient {
// Protects |image_request_id_map_| and |image_request_id_counter_|.
base::Lock map_lock_;
- // The UtilityProcessHost requests are sent to.
- base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
-
- // Calls StopBatchMode() after |kBatchModeTimeoutSeconds| have elapsed,
- // unless a new decoding request resets the timer.
- std::unique_ptr<base::DelayTimer> batch_mode_timer_;
-
- // Mojo service connection. Must always be bound/reset and used on the IO
- // thread.
- mojom::ImageDecoderPtr decoder_;
-
DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
};
« no previous file with comments | « chrome/browser/chrome_content_browser_manifest_overlay.json ('k') | chrome/browser/image_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698