blob: 69caa43abde465d66bae86d5146571f2e95cf8ca [file] [log] [blame]
[email protected]44013f682012-05-31 13:49:401// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]551707a2010-06-16 16:59:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6d33da172011-11-22 03:56:095#ifndef CHROME_BROWSER_IMAGE_DECODER_H_
6#define CHROME_BROWSER_IMAGE_DECODER_H_
[email protected]551707a2010-06-16 16:59:477
[email protected]928c0e712011-03-16 15:01:578#include <string>
[email protected]551707a2010-06-16 16:59:479#include <vector>
10
[email protected]dfd50642011-11-28 20:00:4411#include "base/compiler_specific.h"
[email protected]c4f883a2012-02-03 17:02:0712#include "content/public/browser/browser_thread.h"
13#include "content/public/browser/utility_process_host_client.h"
[email protected]373c1062011-06-09 21:11:5114
15class SkBitmap;
[email protected]551707a2010-06-16 16:59:4716
[email protected]551707a2010-06-16 16:59:4717// Decodes an image in a sandboxed process.
[email protected]c4f883a2012-02-03 17:02:0718class ImageDecoder : public content::UtilityProcessHostClient {
[email protected]551707a2010-06-16 16:59:4719 public:
20 class Delegate {
21 public:
22 // Called when image is decoded.
[email protected]928c0e712011-03-16 15:01:5723 // |decoder| is used to identify the image in case of decoding several
24 // images simultaneously.
25 virtual void OnImageDecoded(const ImageDecoder* decoder,
26 const SkBitmap& decoded_image) = 0;
27
28 // Called when decoding image failed. Delegate can do some cleanup in
29 // this handler.
30 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) {}
[email protected]551707a2010-06-16 16:59:4731
32 protected:
33 virtual ~Delegate() {}
34 };
35
36 ImageDecoder(Delegate* delegate,
[email protected]928c0e712011-03-16 15:01:5737 const std::string& image_data);
[email protected]551707a2010-06-16 16:59:4738
39 // Starts image decoding.
40 void Start();
41
[email protected]bebc8e122012-06-12 19:52:3442 const std::vector<unsigned char>& get_image_data() const {
43 return image_data_;
44 }
45
[email protected]11b0856d2012-06-13 19:21:5646 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
47
[email protected]551707a2010-06-16 16:59:4748 private:
49 // It's a reference counted object, so destructor is private.
[email protected]863e6d962011-05-15 19:39:3550 virtual ~ImageDecoder();
[email protected]551707a2010-06-16 16:59:4751
[email protected]c4f883a2012-02-03 17:02:0752 // Overidden from UtilityProcessHostClient:
[email protected]dfd50642011-11-28 20:00:4453 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
[email protected]373c1062011-06-09 21:11:5154
55 // IPC message handlers.
56 void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
57 void OnDecodeImageFailed();
[email protected]551707a2010-06-16 16:59:4758
59 // Launches sandboxed process that will decode the image.
[email protected]4d9dcff2011-04-06 22:49:0860 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data);
[email protected]551707a2010-06-16 16:59:4761
62 Delegate* delegate_;
63 std::vector<unsigned char> image_data_;
[email protected]631bb742011-11-02 11:29:3964 content::BrowserThread::ID target_thread_id_;
[email protected]551707a2010-06-16 16:59:4765
66 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
67};
68
[email protected]6d33da172011-11-22 03:56:0969#endif // CHROME_BROWSER_IMAGE_DECODER_H_