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