blob: 8c9c02841af22130c69132734c18dd4d8aeb285c [file] [log] [blame]
[email protected]4d9dcff2011-04-06 22:49:081// Copyright (c) 2011 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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]551707a2010-06-16 16:59:478
[email protected]928c0e712011-03-16 15:01:579#include <string>
[email protected]551707a2010-06-16 16:59:4710#include <vector>
11
[email protected]dfd50642011-11-28 20:00:4412#include "base/compiler_specific.h"
[email protected]c4f883a2012-02-03 17:02:0713#include "content/public/browser/browser_thread.h"
14#include "content/public/browser/utility_process_host_client.h"
[email protected]373c1062011-06-09 21:11:5115
16class SkBitmap;
[email protected]551707a2010-06-16 16:59:4717
[email protected]551707a2010-06-16 16:59:4718// Decodes an image in a sandboxed process.
[email protected]c4f883a2012-02-03 17:02:0719class ImageDecoder : public content::UtilityProcessHostClient {
[email protected]551707a2010-06-16 16:59:4720 public:
21 class Delegate {
22 public:
23 // Called when image is decoded.
[email protected]928c0e712011-03-16 15:01:5724 // |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]551707a2010-06-16 16:59:4732
33 protected:
34 virtual ~Delegate() {}
35 };
36
37 ImageDecoder(Delegate* delegate,
[email protected]928c0e712011-03-16 15:01:5738 const std::string& image_data);
[email protected]551707a2010-06-16 16:59:4739
40 // Starts image decoding.
41 void Start();
42
43 private:
44 // It's a reference counted object, so destructor is private.
[email protected]863e6d962011-05-15 19:39:3545 virtual ~ImageDecoder();
[email protected]551707a2010-06-16 16:59:4746
[email protected]c4f883a2012-02-03 17:02:0747 // Overidden from UtilityProcessHostClient:
[email protected]dfd50642011-11-28 20:00:4448 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
[email protected]373c1062011-06-09 21:11:5149
50 // IPC message handlers.
51 void OnDecodeImageSucceeded(const SkBitmap& decoded_image);
52 void OnDecodeImageFailed();
[email protected]551707a2010-06-16 16:59:4753
54 // Launches sandboxed process that will decode the image.
[email protected]4d9dcff2011-04-06 22:49:0855 void DecodeImageInSandbox(const std::vector<unsigned char>& image_data);
[email protected]551707a2010-06-16 16:59:4756
57 Delegate* delegate_;
58 std::vector<unsigned char> image_data_;
[email protected]631bb742011-11-02 11:29:3959 content::BrowserThread::ID target_thread_id_;
[email protected]551707a2010-06-16 16:59:4760
61 DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
62};
63
[email protected]6d33da172011-11-22 03:56:0964#endif // CHROME_BROWSER_IMAGE_DECODER_H_