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

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Get rid of ImageDecoderImpl Created 5 years, 9 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 #include "chrome/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 decoded_image.reset(); 231 decoded_image.reset();
232 LOG(ERROR) << "Decoded image too large for IPC message"; 232 LOG(ERROR) << "Decoded image too large for IPC message";
233 } 233 }
234 } 234 }
235 235
236 return decoded_image; 236 return decoded_image;
237 } 237 }
238 238
239 // static 239 // static
240 void ChromeContentUtilityClient::DecodeImageAndSend( 240 void ChromeContentUtilityClient::DecodeImageAndSend(
241 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit){ 241 const std::vector<unsigned char>& encoded_data,
242 bool shrink_to_fit,
243 int id) {
242 SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit); 244 SkBitmap decoded_image = DecodeImage(encoded_data, shrink_to_fit);
243 245
244 if (decoded_image.empty()) { 246 if (decoded_image.empty()) {
245 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); 247 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id));
246 } else { 248 } else {
247 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image)); 249 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(decoded_image, id));
248 } 250 }
249 ReleaseProcessIfNeeded(); 251 ReleaseProcessIfNeeded();
250 } 252 }
251 253
252 void ChromeContentUtilityClient::OnDecodeImage( 254 void ChromeContentUtilityClient::OnDecodeImage(
253 const std::vector<unsigned char>& encoded_data, bool shrink_to_fit) { 255 const std::vector<unsigned char>& encoded_data,
254 DecodeImageAndSend(encoded_data, shrink_to_fit); 256 bool shrink_to_fit,
257 int id) {
258 DecodeImageAndSend(encoded_data, shrink_to_fit, id);
255 } 259 }
256 260
257 #if defined(OS_CHROMEOS) 261 #if defined(OS_CHROMEOS)
258 void ChromeContentUtilityClient::OnCreateZipFile( 262 void ChromeContentUtilityClient::OnCreateZipFile(
259 const base::FilePath& src_dir, 263 const base::FilePath& src_dir,
260 const std::vector<base::FilePath>& src_relative_paths, 264 const std::vector<base::FilePath>& src_relative_paths,
261 const base::FileDescriptor& dest_fd) { 265 const base::FileDescriptor& dest_fd) {
262 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for 266 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for
263 // details. 267 // details.
264 base::ScopedFD fd_closer(dest_fd.fd); 268 base::ScopedFD fd_closer(dest_fd.fd);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 bool supports_syscall = sandbox::SandboxBPF::SupportsSeccompSandbox( 300 bool supports_syscall = sandbox::SandboxBPF::SupportsSeccompSandbox(
297 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED); 301 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED);
298 Send(new ChromeUtilityHostMsg_DetectSeccompSupport_ResultSyscall( 302 Send(new ChromeUtilityHostMsg_DetectSeccompSupport_ResultSyscall(
299 supports_syscall)); 303 supports_syscall));
300 304
301 ReleaseProcessIfNeeded(); 305 ReleaseProcessIfNeeded();
302 } 306 }
303 #endif // defined(OS_ANDROID) && defined(USE_SECCOMP_BPF) 307 #endif // defined(OS_ANDROID) && defined(USE_SECCOMP_BPF)
304 308
305 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage( 309 void ChromeContentUtilityClient::OnRobustJPEGDecodeImage(
306 const std::vector<unsigned char>& encoded_data) { 310 const std::vector<unsigned char>& encoded_data,
311 int id) {
307 // Our robust jpeg decoding is using IJG libjpeg. 312 // Our robust jpeg decoding is using IJG libjpeg.
308 if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG && 313 if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG &&
309 !encoded_data.empty()) { 314 !encoded_data.empty()) {
310 scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode( 315 scoped_ptr<SkBitmap> decoded_image(gfx::JPEGCodec::Decode(
311 &encoded_data[0], encoded_data.size())); 316 &encoded_data[0], encoded_data.size()));
312 if (!decoded_image.get() || decoded_image->empty()) { 317 if (!decoded_image.get() || decoded_image->empty()) {
313 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); 318 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id));
314 } else { 319 } else {
315 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image)); 320 Send(new ChromeUtilityHostMsg_DecodeImage_Succeeded(*decoded_image, id));
316 } 321 }
317 } else { 322 } else {
318 Send(new ChromeUtilityHostMsg_DecodeImage_Failed()); 323 Send(new ChromeUtilityHostMsg_DecodeImage_Failed(id));
319 } 324 }
320 ReleaseProcessIfNeeded(); 325 ReleaseProcessIfNeeded();
321 } 326 }
322 327
323 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) { 328 void ChromeContentUtilityClient::OnParseJSON(const std::string& json) {
324 int error_code; 329 int error_code;
325 std::string error; 330 std::string error;
326 base::Value* value = base::JSONReader::ReadAndReturnError( 331 base::Value* value = base::JSONReader::ReadAndReturnError(
327 json, base::JSON_PARSE_RFC, &error_code, &error); 332 json, base::JSON_PARSE_RFC, &error_code, &error);
328 if (value) { 333 if (value) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 const std::string& mime_type, int64 total_size, bool get_attached_images) { 397 const std::string& mime_type, int64 total_size, bool get_attached_images) {
393 // Only one IPCDataSource may be created and added to the list of handlers. 398 // Only one IPCDataSource may be created and added to the list of handlers.
394 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); 399 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size);
395 handlers_.push_back(source); 400 handlers_.push_back(source);
396 401
397 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( 402 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser(
398 source, mime_type, get_attached_images); 403 source, mime_type, get_attached_images);
399 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); 404 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser)));
400 } 405 }
401 #endif 406 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698