OLD | NEW |
1 // Copyright (c) 2011 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_utility_messages.h" | 9 #include "chrome/common/chrome_utility_messages.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/utility_process_host.h" | 11 #include "content/public/browser/utility_process_host.h" |
(...skipping 13 matching lines...) Expand all Loading... |
25 void ImageDecoder::Start() { | 25 void ImageDecoder::Start() { |
26 if (!BrowserThread::GetCurrentThreadIdentifier(&target_thread_id_)) { | 26 if (!BrowserThread::GetCurrentThreadIdentifier(&target_thread_id_)) { |
27 NOTREACHED(); | 27 NOTREACHED(); |
28 return; | 28 return; |
29 } | 29 } |
30 BrowserThread::PostTask( | 30 BrowserThread::PostTask( |
31 BrowserThread::IO, FROM_HERE, | 31 BrowserThread::IO, FROM_HERE, |
32 base::Bind(&ImageDecoder::DecodeImageInSandbox, this, image_data_)); | 32 base::Bind(&ImageDecoder::DecodeImageInSandbox, this, image_data_)); |
33 } | 33 } |
34 | 34 |
| 35 bool |
| 36 ImageDecoder::get_image_data(std::vector<unsigned char>* image_data) const { |
| 37 if (image_data) { |
| 38 image_data->assign(image_data_.begin(), image_data_.end()); |
| 39 return true; |
| 40 } |
| 41 return false; |
| 42 } |
| 43 |
35 bool ImageDecoder::OnMessageReceived(const IPC::Message& message) { | 44 bool ImageDecoder::OnMessageReceived(const IPC::Message& message) { |
36 bool handled = true; | 45 bool handled = true; |
37 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message) | 46 IPC_BEGIN_MESSAGE_MAP(ImageDecoder, message) |
38 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded, | 47 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded, |
39 OnDecodeImageSucceeded) | 48 OnDecodeImageSucceeded) |
40 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed, | 49 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed, |
41 OnDecodeImageFailed) | 50 OnDecodeImageFailed) |
42 IPC_MESSAGE_UNHANDLED(handled = false) | 51 IPC_MESSAGE_UNHANDLED(handled = false) |
43 IPC_END_MESSAGE_MAP() | 52 IPC_END_MESSAGE_MAP() |
44 return handled; | 53 return handled; |
(...skipping 12 matching lines...) Expand all Loading... |
57 } | 66 } |
58 | 67 |
59 void ImageDecoder::DecodeImageInSandbox( | 68 void ImageDecoder::DecodeImageInSandbox( |
60 const std::vector<unsigned char>& image_data) { | 69 const std::vector<unsigned char>& image_data) { |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
62 UtilityProcessHost* utility_process_host = UtilityProcessHost::Create( | 71 UtilityProcessHost* utility_process_host = UtilityProcessHost::Create( |
63 this, target_thread_id_); | 72 this, target_thread_id_); |
64 utility_process_host->EnableZygote(); | 73 utility_process_host->EnableZygote(); |
65 utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data)); | 74 utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data)); |
66 } | 75 } |
OLD | NEW |