Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/image_batch_decoder.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a couple more build issues Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/image_batch_decoder.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/common/chrome_utility_messages.h"
10 #include "content/public/browser/browser_thread.h"
11
12 using content::BrowserThread;
13
14 ImageBatchDecoder::ImageBatchDecoder(
15 scoped_refptr<base::SequencedTaskRunner> task_runner)
16 : task_runner_(task_runner) {
17 BrowserThread::PostTask(
18 BrowserThread::IO, FROM_HERE,
19 base::Bind(
20 &ImageBatchDecoder::ConstructUtilityProcessHost,
21 this));
22 }
23
24 ImageBatchDecoder::~ImageBatchDecoder() {
25 utility_process_host_->EndBatchMode();
26 }
27
28 void ImageBatchDecoder::ConstructUtilityProcessHost() {
29 utility_process_host_ =
30 UtilityProcessHost::Create(this, task_runner_.get());
31 utility_process_host_->StartBatchMode();
32 }
33
34 void ImageBatchDecoder::Start(Delegate* delegate,
35 const std::string& image_data,
36 ImageCodec image_codec) {
37 BrowserThread::PostTask(
38 BrowserThread::IO, FROM_HERE,
39 base::Bind(
40 &ImageBatchDecoder::DecodeImageInSandbox,
41 this,
42 delegate,
43 std::vector<unsigned char>(image_data.begin(), image_data.end()),
44 image_codec));
45 }
46
47 bool ImageBatchDecoder::OnMessageReceived(const IPC::Message& message) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP(ImageBatchDecoder, message)
50 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Succeeded,
51 OnDecodeImageSucceeded)
52 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_DecodeImage_Failed,
53 OnDecodeImageFailed)
54 IPC_MESSAGE_UNHANDLED(handled = false)
55 IPC_END_MESSAGE_MAP()
56 return handled;
57 }
58
59 void ImageBatchDecoder::OnDecodeImageSucceeded(const SkBitmap& decoded_image,
60 int id) {
61 DCHECK(task_runner_->RunsTasksOnCurrentThread());
62 if (delegate_map_.find(id) != delegate_map_.end()) {
63 delegate_map_[id]->OnImageDecoded(this, decoded_image);
64 delegate_map_.erase(id);
65 }
66 }
67
68 void ImageBatchDecoder::OnDecodeImageFailed(int id) {
69 DCHECK(task_runner_->RunsTasksOnCurrentThread());
70 if (delegate_map_.find(id) != delegate_map_.end()) {
71 delegate_map_[id]->OnDecodeImageFailed(this);
72 delegate_map_.erase(id);
73 }
74 }
75
76 void ImageBatchDecoder::DecodeImageInSandbox(
77 Delegate* delegate,
78 const std::vector<unsigned char>& image_data,
79 ImageCodec image_codec) {
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
81 delegate_map_[id_counter_] = delegate;
82 if (image_codec == ROBUST_JPEG_CODEC) {
83 utility_process_host_->Send(
84 new ChromeUtilityMsg_RobustJPEGDecodeImage(image_data, id_counter_));
85 } else {
86 utility_process_host_->Send(
87 new ChromeUtilityMsg_DecodeImage(image_data, false, id_counter_));
88 }
89 ++id_counter_;
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698