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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/chrome_utility_messages.h" | 10 #include "chrome/common/chrome_utility_messages.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/utility_process_host.h" | 12 #include "content/public/browser/utility_process_host.h" |
| 13 #include "content/public/common/service_registry.h" |
| 14 #include "services/image_decoder/public/interfaces/image_decoder.mojom.h" |
| 15 #include "skia/public/type_converters.h" |
12 | 16 |
13 using content::BrowserThread; | 17 using content::BrowserThread; |
14 using content::UtilityProcessHost; | 18 using content::UtilityProcessHost; |
15 | 19 |
16 ImageDecoder::ImageDecoder(Delegate* delegate, | 20 ImageDecoder::ImageDecoder(Delegate* delegate, |
17 const std::string& image_data, | 21 const std::string& image_data, |
18 ImageCodec image_codec) | 22 ImageCodec image_codec) |
19 : delegate_(delegate), | 23 : delegate_(delegate), |
20 image_data_(image_data.begin(), image_data.end()), | 24 image_data_(image_data.begin(), image_data.end()), |
21 image_codec_(image_codec), | 25 image_codec_(image_codec), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (delegate_) | 63 if (delegate_) |
60 delegate_->OnImageDecoded(this, decoded_image); | 64 delegate_->OnImageDecoded(this, decoded_image); |
61 } | 65 } |
62 | 66 |
63 void ImageDecoder::OnDecodeImageFailed() { | 67 void ImageDecoder::OnDecodeImageFailed() { |
64 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 68 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
65 if (delegate_) | 69 if (delegate_) |
66 delegate_->OnDecodeImageFailed(this); | 70 delegate_->OnDecodeImageFailed(this); |
67 } | 71 } |
68 | 72 |
| 73 void ImageDecoder::OnDecodeImageDone(bool success, |
| 74 skia::ImagePtr image) { |
| 75 LOG(INFO) << "ImageDecoder::OnDecodeImageDone: " << success; |
| 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 if (delegate_) { |
| 78 if (success && image) { |
| 79 SkBitmap bitmap = image.To<SkBitmap>(); |
| 80 task_runner_->PostTask(FROM_HERE, |
| 81 base::Bind(&ImageDecoder::OnDecodeImageSucceeded, |
| 82 this, |
| 83 bitmap)); |
| 84 } else { |
| 85 task_runner_->PostTask(FROM_HERE, |
| 86 base::Bind(&ImageDecoder::OnDecodeImageFailed, |
| 87 this)); |
| 88 } |
| 89 } |
| 90 decoder_.reset(); |
| 91 } |
| 92 |
69 void ImageDecoder::DecodeImageInSandbox( | 93 void ImageDecoder::DecodeImageInSandbox( |
70 const std::vector<unsigned char>& image_data) { | 94 const std::vector<unsigned char>& image_data) { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
72 UtilityProcessHost* utility_process_host; | 96 UtilityProcessHost* utility_process_host; |
73 utility_process_host = UtilityProcessHost::Create(this, task_runner_.get()); | 97 utility_process_host = UtilityProcessHost::Create(this, task_runner_.get()); |
74 if (image_codec_ == ROBUST_JPEG_CODEC) { | 98 |
75 utility_process_host->Send( | 99 if (switches::MojoUtilityServicesEnabled()) { |
76 new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data)); | 100 LOG(INFO) << "ImageDecoder::DecodeImageInSandbox using Mojo"; |
| 101 if (!utility_process_host->StartMojoMode()) { |
| 102 OnDecodeImageDone(false, nullptr); |
| 103 return; |
| 104 } |
| 105 content::ServiceRegistry* service_registry = |
| 106 utility_process_host->GetServiceRegistry(); |
| 107 service_registry->ConnectToRemoteService(&decoder_); |
| 108 |
| 109 decoder_->DecodeImage(mojo::Array<uint8_t>::From(image_data), |
| 110 image_codec_ == ROBUST_JPEG_CODEC ? |
| 111 services::image_decoder::IMAGE_CODEC_ROBUST_JPEG : |
| 112 services::image_decoder::IMAGE_CODEC_DEFAULT, |
| 113 shrink_to_fit_, |
| 114 base::Bind(&ImageDecoder::OnDecodeImageDone, this)); |
77 } else { | 115 } else { |
78 utility_process_host->Send( | 116 LOG(INFO) << "ImageDecoder::DecodeImageInSandbox using Chrome IPC"; |
79 new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_)); | 117 if (image_codec_ == ROBUST_JPEG_CODEC) { |
| 118 utility_process_host->Send( |
| 119 new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data)); |
| 120 } else { |
| 121 utility_process_host->Send( |
| 122 new ChromeUtilityMsg_DecodeImage(image_data, shrink_to_fit_)); |
| 123 } |
80 } | 124 } |
81 } | 125 } |
OLD | NEW |