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

Side by Side Diff: chrome/browser/image_decoder.h

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: Clean up and add test. Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_IMAGE_DECODER_H_ 5 #ifndef CHROME_BROWSER_IMAGE_DECODER_H_
6 #define CHROME_BROWSER_IMAGE_DECODER_H_ 6 #define CHROME_BROWSER_IMAGE_DECODER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "content/public/browser/utility_process_host_client.h" 14 #include "content/public/browser/utility_process_host_client.h"
15 #include "services/image_decoder/public/interfaces/image_decoder.mojom.h"
15 16
16 class SkBitmap; 17 class SkBitmap;
17 18
18 // Decodes an image in a sandboxed process. 19 // Decodes an image in a sandboxed process.
19 class ImageDecoder : public content::UtilityProcessHostClient { 20 class ImageDecoder : public content::UtilityProcessHostClient,
21 public mojo::ErrorHandler {
20 public: 22 public:
21 class Delegate { 23 class Delegate {
22 public: 24 public:
23 // Called when image is decoded. 25 // Called when image is decoded.
24 // |decoder| is used to identify the image in case of decoding several 26 // |decoder| is used to identify the image in case of decoding several
25 // images simultaneously. 27 // images simultaneously.
26 virtual void OnImageDecoded(const ImageDecoder* decoder, 28 virtual void OnImageDecoded(const ImageDecoder* decoder,
27 const SkBitmap& decoded_image) = 0; 29 const SkBitmap& decoded_image) = 0;
28 30
29 // Called when decoding image failed. Delegate can do some cleanup in 31 // Called when decoding image failed. Delegate can do some cleanup in
(...skipping 28 matching lines...) Expand all
58 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 60 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
59 void set_shrink_to_fit(bool shrink_to_fit) { shrink_to_fit_ = shrink_to_fit; } 61 void set_shrink_to_fit(bool shrink_to_fit) { shrink_to_fit_ = shrink_to_fit; }
60 62
61 private: 63 private:
62 // It's a reference counted object, so destructor is private. 64 // It's a reference counted object, so destructor is private.
63 ~ImageDecoder() override; 65 ~ImageDecoder() override;
64 66
65 // Overidden from UtilityProcessHostClient: 67 // Overidden from UtilityProcessHostClient:
66 bool OnMessageReceived(const IPC::Message& message) override; 68 bool OnMessageReceived(const IPC::Message& message) override;
67 69
70 // Overidden from mojo::ErrorHandler:
71 void OnConnectionError() override;
72
68 // IPC message handlers. 73 // IPC message handlers.
69 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); 74 void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
70 void OnDecodeImageFailed(); 75 void OnDecodeImageFailed();
71 76
72 // Launches sandboxed process that will decode the image. 77 // Launches sandboxed process that will decode the image.
73 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data); 78 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data);
74 79
80 // Mojo RPC callback.
81 void OnDecodeImageDone(bool success, skia::BitmapPtr image);
sky 2015/04/01 15:00:45 Do we need to distinguish between failure and an e
Anand Mistry (off Chromium) 2015/04/02 04:29:45 Done.
82
75 Delegate* delegate_; 83 Delegate* delegate_;
76 std::vector<unsigned char> image_data_; 84 std::vector<unsigned char> image_data_;
77 const ImageCodec image_codec_; 85 const ImageCodec image_codec_;
78 scoped_refptr<base::SequencedTaskRunner> task_runner_; 86 scoped_refptr<base::SequencedTaskRunner> task_runner_;
79 bool shrink_to_fit_; // if needed for IPC msg size limit 87 bool shrink_to_fit_; // if needed for IPC msg size limit
88 services::ImageDecoderPtr decoder_;
80 89
81 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); 90 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
82 }; 91 };
83 92
84 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ 93 #endif // CHROME_BROWSER_IMAGE_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698