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 #include "chrome/browser/image_decoder.h" | 5 #include "chrome/browser/image_decoder.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
11 #include "chrome/common/image_decoder.mojom.h" | 13 #include "chrome/common/image_decoder.mojom.h" |
12 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/utility_process_host.h" | 16 #include "content/public/browser/utility_process_host.h" |
15 #include "services/shell/public/cpp/interface_provider.h" | 17 #include "services/shell/public/cpp/interface_provider.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 65 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
64 } | 66 } |
65 | 67 |
66 ImageDecoder::ImageRequest::~ImageRequest() { | 68 ImageDecoder::ImageRequest::~ImageRequest() { |
67 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 69 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
68 ImageDecoder::Cancel(this); | 70 ImageDecoder::Cancel(this); |
69 } | 71 } |
70 | 72 |
71 // static | 73 // static |
72 void ImageDecoder::Start(ImageRequest* image_request, | 74 void ImageDecoder::Start(ImageRequest* image_request, |
| 75 std::vector<uint8_t> image_data) { |
| 76 StartWithOptions(image_request, std::move(image_data), DEFAULT_CODEC, false); |
| 77 } |
| 78 |
| 79 // static |
| 80 void ImageDecoder::Start(ImageRequest* image_request, |
73 const std::string& image_data) { | 81 const std::string& image_data) { |
74 StartWithOptions(image_request, image_data, DEFAULT_CODEC, false); | 82 Start(image_request, |
| 83 std::vector<uint8_t>(image_data.begin(), image_data.end())); |
| 84 } |
| 85 |
| 86 // static |
| 87 void ImageDecoder::StartWithOptions(ImageRequest* image_request, |
| 88 std::vector<uint8_t> image_data, |
| 89 ImageCodec image_codec, |
| 90 bool shrink_to_fit) { |
| 91 g_decoder.Pointer()->StartWithOptionsImpl(image_request, |
| 92 std::move(image_data), |
| 93 image_codec, shrink_to_fit); |
75 } | 94 } |
76 | 95 |
77 // static | 96 // static |
78 void ImageDecoder::StartWithOptions(ImageRequest* image_request, | 97 void ImageDecoder::StartWithOptions(ImageRequest* image_request, |
79 const std::string& image_data, | 98 const std::string& image_data, |
80 ImageCodec image_codec, | 99 ImageCodec image_codec, |
81 bool shrink_to_fit) { | 100 bool shrink_to_fit) { |
82 g_decoder.Pointer()->StartWithOptionsImpl(image_request, image_data, | 101 StartWithOptions(image_request, |
83 image_codec, shrink_to_fit); | 102 std::vector<uint8_t>(image_data.begin(), image_data.end()), |
| 103 image_codec, shrink_to_fit); |
84 } | 104 } |
85 | 105 |
86 void ImageDecoder::StartWithOptionsImpl(ImageRequest* image_request, | 106 void ImageDecoder::StartWithOptionsImpl(ImageRequest* image_request, |
87 const std::string& image_data, | 107 std::vector<uint8_t> image_data, |
88 ImageCodec image_codec, | 108 ImageCodec image_codec, |
89 bool shrink_to_fit) { | 109 bool shrink_to_fit) { |
90 DCHECK(image_request); | 110 DCHECK(image_request); |
91 DCHECK(image_request->task_runner()); | 111 DCHECK(image_request->task_runner()); |
92 | 112 |
93 int request_id; | 113 int request_id; |
94 { | 114 { |
95 base::AutoLock lock(map_lock_); | 115 base::AutoLock lock(map_lock_); |
96 request_id = image_request_id_counter_++; | 116 request_id = image_request_id_counter_++; |
97 image_request_id_map_.insert(std::make_pair(request_id, image_request)); | 117 image_request_id_map_.insert(std::make_pair(request_id, image_request)); |
98 } | 118 } |
99 | 119 |
100 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
101 BrowserThread::IO, FROM_HERE, | 121 BrowserThread::IO, FROM_HERE, |
102 base::Bind( | 122 base::Bind( |
103 &ImageDecoder::DecodeImageInSandbox, | 123 &ImageDecoder::DecodeImageInSandbox, |
104 g_decoder.Pointer(), request_id, | 124 g_decoder.Pointer(), request_id, |
105 std::vector<unsigned char>(image_data.begin(), image_data.end()), | 125 base::Passed(std::move(image_data)), |
106 image_codec, shrink_to_fit)); | 126 image_codec, shrink_to_fit)); |
107 } | 127 } |
108 | 128 |
109 // static | 129 // static |
110 void ImageDecoder::Cancel(ImageRequest* image_request) { | 130 void ImageDecoder::Cancel(ImageRequest* image_request) { |
111 DCHECK(image_request); | 131 DCHECK(image_request); |
112 g_decoder.Pointer()->CancelImpl(image_request); | 132 g_decoder.Pointer()->CancelImpl(image_request); |
113 } | 133 } |
114 | 134 |
115 void ImageDecoder::DecodeImageInSandbox( | 135 void ImageDecoder::DecodeImageInSandbox( |
116 int request_id, | 136 int request_id, |
117 const std::vector<unsigned char>& image_data, | 137 std::vector<uint8_t> image_data, |
118 ImageCodec image_codec, | 138 ImageCodec image_codec, |
119 bool shrink_to_fit) { | 139 bool shrink_to_fit) { |
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
121 base::AutoLock lock(map_lock_); | 141 base::AutoLock lock(map_lock_); |
122 const auto it = image_request_id_map_.find(request_id); | 142 const auto it = image_request_id_map_.find(request_id); |
123 if (it == image_request_id_map_.end()) | 143 if (it == image_request_id_map_.end()) |
124 return; | 144 return; |
125 | 145 |
126 ImageRequest* image_request = it->second; | 146 ImageRequest* image_request = it->second; |
127 if (!utility_process_host_) { | 147 if (!utility_process_host_) { |
(...skipping 19 matching lines...) Expand all Loading... |
147 batch_mode_timer_->Reset(); | 167 batch_mode_timer_->Reset(); |
148 | 168 |
149 mojom::ImageCodec mojo_codec = mojom::ImageCodec::DEFAULT; | 169 mojom::ImageCodec mojo_codec = mojom::ImageCodec::DEFAULT; |
150 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
151 if (image_codec == ROBUST_JPEG_CODEC) | 171 if (image_codec == ROBUST_JPEG_CODEC) |
152 mojo_codec = mojom::ImageCodec::ROBUST_JPEG; | 172 mojo_codec = mojom::ImageCodec::ROBUST_JPEG; |
153 if (image_codec == ROBUST_PNG_CODEC) | 173 if (image_codec == ROBUST_PNG_CODEC) |
154 mojo_codec = mojom::ImageCodec::ROBUST_PNG; | 174 mojo_codec = mojom::ImageCodec::ROBUST_PNG; |
155 #endif // defined(OS_CHROMEOS) | 175 #endif // defined(OS_CHROMEOS) |
156 decoder_->DecodeImage( | 176 decoder_->DecodeImage( |
157 mojo::Array<uint8_t>::From(image_data), | 177 mojo::Array<uint8_t>(std::move(image_data)), |
158 mojo_codec, | 178 mojo_codec, |
159 shrink_to_fit, | 179 shrink_to_fit, |
160 base::Bind(&OnDecodeImageDone, | 180 base::Bind(&OnDecodeImageDone, |
161 base::Bind(&ImageDecoder::OnDecodeImageFailed, this), | 181 base::Bind(&ImageDecoder::OnDecodeImageFailed, this), |
162 base::Bind(&ImageDecoder::OnDecodeImageSucceeded, this), | 182 base::Bind(&ImageDecoder::OnDecodeImageSucceeded, this), |
163 request_id)); | 183 request_id)); |
164 } | 184 } |
165 | 185 |
166 void ImageDecoder::CancelImpl(ImageRequest* image_request) { | 186 void ImageDecoder::CancelImpl(ImageRequest* image_request) { |
167 base::AutoLock lock(map_lock_); | 187 base::AutoLock lock(map_lock_); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 auto it = image_request_id_map_.find(request_id); | 314 auto it = image_request_id_map_.find(request_id); |
295 if (it == image_request_id_map_.end()) | 315 if (it == image_request_id_map_.end()) |
296 return; | 316 return; |
297 image_request = it->second; | 317 image_request = it->second; |
298 image_request_id_map_.erase(it); | 318 image_request_id_map_.erase(it); |
299 } | 319 } |
300 | 320 |
301 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); | 321 DCHECK(image_request->task_runner()->RunsTasksOnCurrentThread()); |
302 image_request->OnDecodeImageFailed(); | 322 image_request->OnDecodeImageFailed(); |
303 } | 323 } |
OLD | NEW |