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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file.h" | |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/sequence_checker.h" | 15 #include "base/sequence_checker.h" |
15 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
18 #include "content/public/browser/utility_process_host.h" | 19 #include "content/public/browser/utility_process_host.h" |
19 #include "content/public/browser/utility_process_host_client.h" | 20 #include "content/public/browser/utility_process_host_client.h" |
20 | 21 |
21 class SkBitmap; | 22 class SkBitmap; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 base::SequenceChecker sequence_checker_; | 65 base::SequenceChecker sequence_checker_; |
65 }; | 66 }; |
66 | 67 |
67 enum ImageCodec { | 68 enum ImageCodec { |
68 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). | 69 DEFAULT_CODEC = 0, // Uses WebKit image decoding (via WebImage). |
69 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
70 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. | 71 ROBUST_JPEG_CODEC, // Restrict decoding to robust jpeg codec. |
71 #endif // defined(OS_CHROMEOS) | 72 #endif // defined(OS_CHROMEOS) |
72 }; | 73 }; |
73 | 74 |
75 static void Start(ImageRequest* image_request, | |
76 const base::FilePath& image_file_path); | |
77 | |
74 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and | 78 // Calls StartWithOptions() with ImageCodec::DEFAULT_CODEC and |
75 // shrink_to_fit = false. | 79 // shrink_to_fit = false. |
76 static void Start(ImageRequest* image_request, | 80 static void Start(ImageRequest* image_request, |
77 const std::string& image_data); | 81 const std::string& image_data); |
78 | 82 |
79 // Starts asynchronous image decoding. Once finished, the callback will be | 83 // Starts asynchronous image decoding. Once finished, the callback will be |
80 // posted back to image_request's |task_runner_|. | 84 // posted back to image_request's |task_runner_|. |
81 static void StartWithOptions(ImageRequest* image_request, | 85 static void StartWithOptions(ImageRequest* image_request, |
82 const std::string& image_data, | 86 const std::string& image_data, |
83 ImageCodec image_codec, | 87 ImageCodec image_codec, |
84 bool shrink_to_fit); | 88 bool shrink_to_fit); |
85 | 89 |
86 // Removes all instances of |image_request| from |image_request_id_map_|, | 90 // Removes all instances of |image_request| from |image_request_id_map_|, |
87 // ensuring callbacks are not made to the image_request after it is destroyed. | 91 // ensuring callbacks are not made to the image_request after it is destroyed. |
88 static void Cancel(ImageRequest* image_request); | 92 static void Cancel(ImageRequest* image_request); |
89 | 93 |
90 private: | 94 private: |
91 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; | 95 friend struct base::DefaultLazyInstanceTraits<ImageDecoder>; |
92 | 96 |
93 using RequestMap = std::map<int, ImageRequest*>; | 97 using RequestMap = std::map<int, ImageRequest*>; |
94 | 98 |
95 ImageDecoder(); | 99 ImageDecoder(); |
96 // It's a reference counted object, so destructor is private. | 100 // It's a reference counted object, so destructor is private. |
97 ~ImageDecoder() override; | 101 ~ImageDecoder() override; |
98 | 102 |
99 // Sends a request to the sandboxed process to decode the image. Starts | 103 // Sends a request to the sandboxed process to decode the image. Starts |
100 // batch mode if necessary. If the utility process fails to start, | 104 // batch mode if necessary. If the utility process fails to start, |
101 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. | 105 // an OnDecodeImageFailed task is posted to image_request's |task_runner_|. |
102 void DecodeImageInSandbox(int request_id, | 106 void DecodeImageInSandbox(int request_id, |
asanka
2015/06/11 03:30:52
I'll defer to the owners.
However, for both Decod
yoshiki
2015/06/11 08:22:09
Acknowledged.
| |
107 base::File image_file, | |
103 const std::vector<unsigned char>& image_data, | 108 const std::vector<unsigned char>& image_data, |
104 ImageCodec image_codec, | 109 ImageCodec image_codec, |
105 bool shrink_to_fit); | 110 bool shrink_to_fit); |
106 | 111 |
107 void StartWithOptionsImpl(ImageRequest* image_request, | 112 void StartWithOptionsImpl(ImageRequest* image_request, |
113 const base::FilePath& image_file_path, | |
108 const std::string& image_data, | 114 const std::string& image_data, |
109 ImageCodec image_codec, | 115 ImageCodec image_codec, |
110 bool shrink_to_fit); | 116 bool shrink_to_fit); |
111 void CancelImpl(ImageRequest* image_request); | 117 void CancelImpl(ImageRequest* image_request); |
112 | 118 |
113 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. | 119 // Starts UtilityProcessHost in batch mode and starts |batch_mode_timer_|. |
114 // If the utility process fails to start, the method resets | 120 // If the utility process fails to start, the method resets |
115 // |utility_process_host_| and returns. | 121 // |utility_process_host_| and returns. |
116 void StartBatchMode(); | 122 void StartBatchMode(); |
117 | 123 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | 155 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
150 | 156 |
151 // Calls StopBatchMode() after |kBatchModeTimeoutSeconds| have elapsed, | 157 // Calls StopBatchMode() after |kBatchModeTimeoutSeconds| have elapsed, |
152 // unless a new decoding request resets the timer. | 158 // unless a new decoding request resets the timer. |
153 scoped_ptr<base::DelayTimer<ImageDecoder>> batch_mode_timer_; | 159 scoped_ptr<base::DelayTimer<ImageDecoder>> batch_mode_timer_; |
154 | 160 |
155 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | 161 DISALLOW_COPY_AND_ASSIGN(ImageDecoder); |
156 }; | 162 }; |
157 | 163 |
158 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ | 164 #endif // CHROME_BROWSER_IMAGE_DECODER_H_ |
OLD | NEW |