| 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 <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). | 72 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). |
| 73 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
| 74 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. | 74 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. |
| 75 ROBUST_PNG_CODEC, // Restrict decoding to robust PNG codec. | 75 ROBUST_PNG_CODEC, // Restrict decoding to robust PNG codec. |
| 76 #endif // defined(OS_CHROMEOS) | 76 #endif // defined(OS_CHROMEOS) |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and | 79 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and |
| 80 // shrink_to_fit = false. | 80 // shrink_to_fit = false. |
| 81 static void Start(ImageRequest* image_request, | 81 static void Start(ImageRequest* image_request, |
| 82 std::vector<uint8_t> image_data); |
| 83 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. |
| 84 static void Start(ImageRequest* image_request, |
| 82 const std::string& image_data); | 85 const std::string& image_data); |
| 83 | 86 |
| 84 // Starts asynchronous image decoding. Once finished, the callback will be | 87 // Starts asynchronous image decoding. Once finished, the callback will be |
| 85 // posted back to image_request's |task_runner_|. | 88 // posted back to image_request's |task_runner_|. |
| 86 static void StartWithOptions(ImageRequest* image_request, | 89 static void StartWithOptions(ImageRequest* image_request, |
| 90 std::vector<uint8_t> image_data, |
| 91 ImageCodec image_codec, |
| 92 bool shrink_to_fit); |
| 93 // Deprecated. Use std::vector<uint8_t> version to avoid an extra copy. |
| 94 static void StartWithOptions(ImageRequest* image_request, |
| 87 const std::string& image_data, | 95 const std::string& image_data, |
| 88 ImageCodec image_codec, | 96 ImageCodec image_codec, |
| 89 bool shrink_to_fit); | 97 bool shrink_to_fit); |
| 90 | 98 |
| 91 // Removes all instances of |image_request| from |image_request_id_map_|, | 99 // Removes all instances of |image_request| from |image_request_id_map_|, |
| 92 // ensuring callbacks are not made to the image_request after it is destroyed. | 100 // ensuring callbacks are not made to the image_request after it is destroyed. |
| 93 static void Cancel(ImageRequest* image_request); | 101 static void Cancel(ImageRequest* image_request); |
| 94 | 102 |
| 95 private: | 103 private: |
| 96 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; | 104 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; |
| 97 | 105 |
| 98 using RequestMap = std::map<int, ImageRequest*>; | 106 using RequestMap = std::map<int, ImageRequest*>; |
| 99 | 107 |
| 100 ImageDecoder(); | 108 ImageDecoder(); |
| 101 // It's a reference counted object, so destructor is private. | 109 // It's a reference counted object, so destructor is private. |
| 102 ~ImageDecoder() override; | 110 ~ImageDecoder() override; |
| 103 | 111 |
| 104 // Sends a request to the sandboxed process to decode the image. Starts | 112 // Sends a request to the sandboxed process to decode the image. Starts |
| 105 // batch mode if necessary. If the utility process fails to start, | 113 // batch mode if necessary. If the utility process fails to start, |
| 106 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. | 114 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. |
| 107 void DecodeImageInSandbox(int request_id, | 115 void DecodeImageInSandbox(int request_id, |
| 108 const std::vector<unsigned char>& image_data, | 116 std::vector<uint8_t> image_data, |
| 109 ImageCodec image_codec, | 117 ImageCodec image_codec, |
| 110 bool shrink_to_fit); | 118 bool shrink_to_fit); |
| 111 | 119 |
| 112 void StartWithOptionsImpl(ImageRequest* image_request, | 120 void StartWithOptionsImpl(ImageRequest* image_request, |
| 113 const std::string& image_data, | 121 std::vector<uint8_t> image_data, |
| 114 ImageCodec image_codec, | 122 ImageCodec image_codec, |
| 115 bool shrink_to_fit); | 123 bool shrink_to_fit); |
| 116 void CancelImpl(ImageRequest* image_request); | 124 void CancelImpl(ImageRequest* image_request); |
| 117 | 125 |
| 118 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. | 126 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. |
| 119 // If the utility process fails to start, the method resets | 127 // If the utility process fails to start, the method resets |
| 120 // |utility_process_host_| and returns. | 128 // |utility_process_host_| and returns. |
| 121 void StartBatchMode(); | 129 void StartBatchMode(); |
| 122 | 130 |
| 123 // Stops batch mode if no requests have come in since | 131 // Stops batch mode if no requests have come in since |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 std::unique_ptr<base::DelayTimer> batch_mode_timer_; | 166 std::unique_ptr<base::DelayTimer> batch_mode_timer_; |
| 159 | 167 |
| 160 // Mojo service connection. Must always be bound/reset and used on the IO | 168 // Mojo service connection. Must always be bound/reset and used on the IO |
| 161 // thread. | 169 // thread. |
| 162 mojom::ImageDecoderPtr decoder_; | 170 mojom::ImageDecoderPtr decoder_; |
| 163 | 171 |
| 164 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | 172 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); |
| 165 }; | 173 }; |
| 166 | 174 |
| 167 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ | 175 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ |
| OLD | NEW |