OLD | NEW |
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 "content/public/browser/browser_thread.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" |
13 #include "content/public/browser/utility_process_host_client.h" | 14 #include "content/public/browser/utility_process_host_client.h" |
14 | 15 |
15 class SkBitmap; | 16 class SkBitmap; |
16 | 17 |
17 // Decodes an image in a sandboxed process. | 18 // Decodes an image in a sandboxed process. |
18 class ImageDecoder : public content::UtilityProcessHostClient { | 19 class ImageDecoder : public content::UtilityProcessHostClient { |
19 public: | 20 public: |
20 class Delegate { | 21 class Delegate { |
21 public: | 22 public: |
22 // Called when image is decoded. | 23 // Called when image is decoded. |
(...skipping 12 matching lines...) Expand all Loading... |
35 | 36 |
36 enum ImageCodec { | 37 enum ImageCodec { |
37 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). | 38 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). |
38 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. | 39 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. |
39 }; | 40 }; |
40 | 41 |
41 ImageDecoder(Delegate* delegate, | 42 ImageDecoder(Delegate* delegate, |
42 const std::string& image_data, | 43 const std::string& image_data, |
43 ImageCodec image_codec); | 44 ImageCodec image_codec); |
44 | 45 |
45 // Starts image decoding. | 46 // Starts image decoding on current thread of |task_runner|. |
46 void Start(); | 47 void Start(scoped_refptr<base::SequencedTaskRunner> task_runner); |
47 | 48 |
48 const std::vector<unsigned char>& get_image_data() const { | 49 const std::vector<unsigned char>& get_image_data() const { |
49 return image_data_; | 50 return image_data_; |
50 } | 51 } |
51 | 52 |
52 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | 53 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
53 | 54 |
54 private: | 55 private: |
55 // It's a reference counted object, so destructor is private. | 56 // It's a reference counted object, so destructor is private. |
56 virtual ~ImageDecoder(); | 57 virtual ~ImageDecoder(); |
57 | 58 |
58 // Overidden from UtilityProcessHostClient: | 59 // Overidden from UtilityProcessHostClient: |
59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
60 | 61 |
61 // IPC message handlers. | 62 // IPC message handlers. |
62 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | 63 void OnDecodeImageSucceeded(const SkBitmap& decoded_image); |
63 void OnDecodeImageFailed(); | 64 void OnDecodeImageFailed(); |
64 | 65 |
65 // Launches sandboxed process that will decode the image. | 66 // Launches sandboxed process that will decode the image. |
66 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data); | 67 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data); |
67 | 68 |
68 Delegate* delegate_; | 69 Delegate* delegate_; |
69 std::vector<unsigned char> image_data_; | 70 std::vector<unsigned char> image_data_; |
70 const ImageCodec image_codec_; | 71 const ImageCodec image_codec_; |
71 content::BrowserThread::ID target_thread_id_; | 72 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
72 | 73 |
73 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | 74 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); |
74 }; | 75 }; |
75 | 76 |
76 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ | 77 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ |
OLD | NEW |