| 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/chromeos/app_mode/kiosk_app_data.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 class KioskAppData::IconLoader : public ImageDecoder::Delegate { | 194 class KioskAppData::IconLoader : public ImageDecoder::Delegate { |
| 195 public: | 195 public: |
| 196 enum LoadResult { | 196 enum LoadResult { |
| 197 SUCCESS, | 197 SUCCESS, |
| 198 FAILED_TO_LOAD, | 198 FAILED_TO_LOAD, |
| 199 FAILED_TO_DECODE, | 199 FAILED_TO_DECODE, |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 IconLoader(const base::WeakPtr<KioskAppData>& client, | 202 IconLoader(const base::WeakPtr<KioskAppData>& client, |
| 203 const base::FilePath& icon_path) | 203 const base::FilePath& icon_path) |
| 204 : client_(client), | 204 : Delegate(task_runner_), |
| 205 client_(client), |
| 205 icon_path_(icon_path), | 206 icon_path_(icon_path), |
| 206 load_result_(SUCCESS) {} | 207 load_result_(SUCCESS) {} |
| 207 | 208 |
| 208 void Start() { | 209 void Start() { |
| 209 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 210 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 210 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); | 211 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); |
| 211 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | 212 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 212 token, | 213 token, |
| 213 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 214 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 214 task_runner_->PostTask(FROM_HERE, | 215 task_runner_->PostTask(FROM_HERE, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 225 void LoadOnBlockingPool() { | 226 void LoadOnBlockingPool() { |
| 226 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 227 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 227 | 228 |
| 228 std::string data; | 229 std::string data; |
| 229 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { | 230 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { |
| 230 ReportResultOnBlockingPool(FAILED_TO_LOAD); | 231 ReportResultOnBlockingPool(FAILED_TO_LOAD); |
| 231 return; | 232 return; |
| 232 } | 233 } |
| 233 raw_icon_ = base::RefCountedString::TakeString(&data); | 234 raw_icon_ = base::RefCountedString::TakeString(&data); |
| 234 | 235 |
| 235 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( | 236 ImageDecoder::Start(this, raw_icon_->data(), ImageDecoder::DEFAULT_CODEC, |
| 236 this, raw_icon_->data(), ImageDecoder::DEFAULT_CODEC); | 237 false); |
| 237 image_decoder->Start(task_runner_); | |
| 238 } | 238 } |
| 239 | 239 |
| 240 void ReportResultOnBlockingPool(LoadResult result) { | 240 void ReportResultOnBlockingPool(LoadResult result) { |
| 241 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 241 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 242 | 242 |
| 243 load_result_ = result; | 243 load_result_ = result; |
| 244 BrowserThread::PostTask( | 244 BrowserThread::PostTask( |
| 245 BrowserThread::UI, | 245 BrowserThread::UI, |
| 246 FROM_HERE, | 246 FROM_HERE, |
| 247 base::Bind(&IconLoader::ReportResultOnUIThread, | 247 base::Bind(&IconLoader::ReportResultOnUIThread, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 259 } | 259 } |
| 260 | 260 |
| 261 void ReportResultOnUIThread() { | 261 void ReportResultOnUIThread() { |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 263 | 263 |
| 264 NotifyClient(); | 264 NotifyClient(); |
| 265 delete this; | 265 delete this; |
| 266 } | 266 } |
| 267 | 267 |
| 268 // ImageDecoder::Delegate overrides: | 268 // ImageDecoder::Delegate overrides: |
| 269 void OnImageDecoded(const ImageDecoder* decoder, | 269 void OnImageDecoded(const SkBitmap& decoded_image) override { |
| 270 const SkBitmap& decoded_image) override { | |
| 271 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | 270 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); |
| 272 icon_.MakeThreadSafe(); | 271 icon_.MakeThreadSafe(); |
| 273 ReportResultOnBlockingPool(SUCCESS); | 272 ReportResultOnBlockingPool(SUCCESS); |
| 274 } | 273 } |
| 275 | 274 |
| 276 void OnDecodeImageFailed(const ImageDecoder* decoder) override { | 275 void OnDecodeImageFailed() override { |
| 277 ReportResultOnBlockingPool(FAILED_TO_DECODE); | 276 ReportResultOnBlockingPool(FAILED_TO_DECODE); |
| 278 } | 277 } |
| 279 | 278 |
| 280 base::WeakPtr<KioskAppData> client_; | 279 base::WeakPtr<KioskAppData> client_; |
| 281 base::FilePath icon_path_; | 280 base::FilePath icon_path_; |
| 282 | 281 |
| 283 LoadResult load_result_; | 282 LoadResult load_result_; |
| 284 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 283 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 285 | 284 |
| 286 gfx::ImageSkia icon_; | 285 gfx::ImageSkia icon_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 300 : client_(client) {} | 299 : client_(client) {} |
| 301 | 300 |
| 302 void Start(const std::string& app_id, | 301 void Start(const std::string& app_id, |
| 303 const std::string& manifest, | 302 const std::string& manifest, |
| 304 const GURL& icon_url, | 303 const GURL& icon_url, |
| 305 net::URLRequestContextGetter* context_getter) { | 304 net::URLRequestContextGetter* context_getter) { |
| 306 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = | 305 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = |
| 307 new extensions::WebstoreInstallHelper(this, | 306 new extensions::WebstoreInstallHelper(this, |
| 308 app_id, | 307 app_id, |
| 309 manifest, | 308 manifest, |
| 310 "", // No icon data. | |
| 311 icon_url, | 309 icon_url, |
| 312 context_getter); | 310 context_getter); |
| 313 webstore_helper->Start(); | 311 webstore_helper->Start(); |
| 314 } | 312 } |
| 315 | 313 |
| 316 private: | 314 private: |
| 317 friend class base::RefCounted<WebstoreDataParser>; | 315 friend class base::RefCounted<WebstoreDataParser>; |
| 318 | 316 |
| 319 ~WebstoreDataParser() override {} | 317 ~WebstoreDataParser() override {} |
| 320 | 318 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 642 |
| 645 SkBitmap icon = crx_loader->icon(); | 643 SkBitmap icon = crx_loader->icon(); |
| 646 if (icon.empty()) | 644 if (icon.empty()) |
| 647 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 645 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
| 648 SetCache(crx_loader->name(), icon); | 646 SetCache(crx_loader->name(), icon); |
| 649 | 647 |
| 650 SetStatus(STATUS_LOADED); | 648 SetStatus(STATUS_LOADED); |
| 651 } | 649 } |
| 652 | 650 |
| 653 } // namespace chromeos | 651 } // namespace chromeos |
| OLD | NEW |