[email protected] | 4d9dcff | 2011-04-06 22:49:08 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_ | ||||
6 | #define CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 8 | |
[email protected] | 928c0e71 | 2011-03-16 15:01:57 | [diff] [blame] | 9 | #include <string> |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 10 | #include <vector> |
11 | |||||
[email protected] | 373c106 | 2011-06-09 21:11:51 | [diff] [blame] | 12 | #include "content/browser/utility_process_host.h" |
13 | |||||
14 | class SkBitmap; | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 15 | |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 16 | namespace chromeos { |
17 | |||||
18 | // Decodes an image in a sandboxed process. | ||||
19 | class ImageDecoder : public UtilityProcessHost::Client { | ||||
20 | public: | ||||
21 | class Delegate { | ||||
22 | public: | ||||
23 | // Called when image is decoded. | ||||
[email protected] | 928c0e71 | 2011-03-16 15:01:57 | [diff] [blame] | 24 | // |decoder| is used to identify the image in case of decoding several |
25 | // images simultaneously. | ||||
26 | virtual void OnImageDecoded(const ImageDecoder* decoder, | ||||
27 | const SkBitmap& decoded_image) = 0; | ||||
28 | |||||
29 | // Called when decoding image failed. Delegate can do some cleanup in | ||||
30 | // this handler. | ||||
31 | virtual void OnDecodeImageFailed(const ImageDecoder* decoder) {} | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 32 | |
33 | protected: | ||||
34 | virtual ~Delegate() {} | ||||
35 | }; | ||||
36 | |||||
37 | ImageDecoder(Delegate* delegate, | ||||
[email protected] | 928c0e71 | 2011-03-16 15:01:57 | [diff] [blame] | 38 | const std::string& image_data); |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 39 | |
40 | // Starts image decoding. | ||||
41 | void Start(); | ||||
42 | |||||
43 | private: | ||||
44 | // It's a reference counted object, so destructor is private. | ||||
[email protected] | 863e6d96 | 2011-05-15 19:39:35 | [diff] [blame] | 45 | virtual ~ImageDecoder(); |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 46 | |
47 | // Overidden from UtilityProcessHost::Client: | ||||
[email protected] | 373c106 | 2011-06-09 21:11:51 | [diff] [blame] | 48 | virtual bool OnMessageReceived(const IPC::Message& message); |
49 | |||||
50 | // IPC message handlers. | ||||
51 | void OnDecodeImageSucceeded(const SkBitmap& decoded_image); | ||||
52 | void OnDecodeImageFailed(); | ||||
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 53 | |
54 | // Launches sandboxed process that will decode the image. | ||||
[email protected] | 4d9dcff | 2011-04-06 22:49:08 | [diff] [blame] | 55 | void DecodeImageInSandbox(const std::vector<unsigned char>& image_data); |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 56 | |
57 | Delegate* delegate_; | ||||
58 | std::vector<unsigned char> image_data_; | ||||
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame^] | 59 | content::BrowserThread::ID target_thread_id_; |
[email protected] | 551707a | 2010-06-16 16:59:47 | [diff] [blame] | 60 | |
61 | DISALLOW_COPY_AND_ASSIGN(ImageDecoder); | ||||
62 | }; | ||||
63 | |||||
64 | } // namespace chromeos | ||||
65 | |||||
66 | #endif // CHROME_BROWSER_CHROMEOS_LOGIN_IMAGE_DECODER_H_ |