OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media_galleries/fileapi/supported_image_type_validator.
h" | 5 #include "chrome/browser/media_galleries/fileapi/supported_image_type_validator.
h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/threading/sequenced_worker_pool.h" | |
15 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
16 #include "chrome/browser/image_decoder.h" | 15 #include "chrome/browser/image_decoder.h" |
17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
18 | 17 |
19 using content::BrowserThread; | 18 using content::BrowserThread; |
20 | 19 |
21 namespace chrome { | 20 namespace chrome { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 DCHECK(data_); | 70 DCHECK(data_); |
72 } | 71 } |
73 | 72 |
74 const std::string& data() { | 73 const std::string& data() { |
75 return *data_; | 74 return *data_; |
76 } | 75 } |
77 | 76 |
78 // ImageDecoder::Delegate methods. | 77 // ImageDecoder::Delegate methods. |
79 virtual void OnImageDecoded(const ImageDecoder* /*decoder*/, | 78 virtual void OnImageDecoded(const ImageDecoder* /*decoder*/, |
80 const SkBitmap& /*decoded_image*/) OVERRIDE { | 79 const SkBitmap& /*decoded_image*/) OVERRIDE { |
81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 80 callback_.Run(base::PLATFORM_FILE_OK); |
82 base::Bind(callback_, base::PLATFORM_FILE_OK)); | |
83 delete this; | 81 delete this; |
84 } | 82 } |
85 | 83 |
86 virtual void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) OVERRIDE { | 84 virtual void OnDecodeImageFailed(const ImageDecoder* /*decoder*/) OVERRIDE { |
87 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 85 callback_.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
88 base::Bind(callback_, | |
89 base::PLATFORM_FILE_ERROR_SECURITY)); | |
90 delete this; | 86 delete this; |
91 } | 87 } |
92 | 88 |
93 private: | 89 private: |
94 scoped_ptr<std::string> data_; | 90 scoped_ptr<std::string> data_; |
95 fileapi::CopyOrMoveFileValidator::ResultCallback callback_; | 91 fileapi::CopyOrMoveFileValidator::ResultCallback callback_; |
96 | 92 |
97 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); | 93 DISALLOW_COPY_AND_ASSIGN(ImageDecoderDelegateAdapter); |
98 }; | 94 }; |
99 | 95 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (!data.get()) { | 136 if (!data.get()) { |
141 callback_.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 137 callback_.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
142 return; | 138 return; |
143 } | 139 } |
144 | 140 |
145 // |adapter| will delete itself after a completion message is received. | 141 // |adapter| will delete itself after a completion message is received. |
146 ImageDecoderDelegateAdapter* adapter = | 142 ImageDecoderDelegateAdapter* adapter = |
147 new ImageDecoderDelegateAdapter(data.Pass(), callback_); | 143 new ImageDecoderDelegateAdapter(data.Pass(), callback_); |
148 decoder_ = new ImageDecoder(adapter, adapter->data(), | 144 decoder_ = new ImageDecoder(adapter, adapter->data(), |
149 ImageDecoder::DEFAULT_CODEC); | 145 ImageDecoder::DEFAULT_CODEC); |
150 base::SequencedWorkerPool* workerpool = BrowserThread::GetBlockingPool(); | 146 decoder_->Start(content::BrowserThread::GetMessageLoopProxyForThread( |
151 decoder_->Start(workerpool->GetSequencedTaskRunnerWithShutdownBehavior( | 147 BrowserThread::IO)); |
152 workerpool->GetSequenceToken(), | |
153 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); | |
154 } | 148 } |
155 | 149 |
156 } // namespace chrome | 150 } // namespace chrome |
OLD | NEW |