| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 std::string name_; | 184 std::string name_; |
| 185 SkBitmap icon_; | 185 SkBitmap icon_; |
| 186 | 186 |
| 187 DISALLOW_COPY_AND_ASSIGN(CrxLoader); | 187 DISALLOW_COPY_AND_ASSIGN(CrxLoader); |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
| 191 // KioskAppData::IconLoader | 191 // KioskAppData::IconLoader |
| 192 // Loads locally stored icon data and decode it. | 192 // Loads locally stored icon data and decode it. |
| 193 | 193 |
| 194 class KioskAppData::IconLoader : public ImageDecoder::Delegate { | 194 class KioskAppData::IconLoader { |
| 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 : client_(client), |
| 205 icon_path_(icon_path), | 205 icon_path_(icon_path), |
| 206 load_result_(SUCCESS) {} | 206 load_result_(SUCCESS) {} |
| 207 | 207 |
| 208 void Start() { | 208 void Start() { |
| 209 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 209 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 210 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); | 210 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); |
| 211 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | 211 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 212 token, | 212 token, |
| 213 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 213 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 214 task_runner_->PostTask(FROM_HERE, | 214 task_runner_->PostTask(FROM_HERE, |
| 215 base::Bind(&IconLoader::LoadOnBlockingPool, | 215 base::Bind(&IconLoader::LoadOnBlockingPool, |
| 216 base::Unretained(this))); | 216 base::Unretained(this))); |
| 217 } | 217 } |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 friend class base::RefCountedThreadSafe<IconLoader>; | 220 friend class base::RefCountedThreadSafe<IconLoader>; |
| 221 | 221 |
| 222 ~IconLoader() override {} | 222 ~IconLoader() {} |
| 223 |
| 224 class IconImageRequest : public ImageDecoder::ImageRequest { |
| 225 public: |
| 226 IconImageRequest( |
| 227 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 228 IconLoader* icon_loader) |
| 229 : ImageRequest(task_runner), icon_loader_(icon_loader) {} |
| 230 |
| 231 void OnImageDecoded(const SkBitmap& decoded_image) override { |
| 232 icon_loader_->icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); |
| 233 icon_loader_->icon_.MakeThreadSafe(); |
| 234 icon_loader_->ReportResultOnBlockingPool(SUCCESS); |
| 235 delete this; |
| 236 } |
| 237 |
| 238 void OnDecodeImageFailed() override { |
| 239 icon_loader_->ReportResultOnBlockingPool(FAILED_TO_DECODE); |
| 240 delete this; |
| 241 } |
| 242 |
| 243 private: |
| 244 ~IconImageRequest() override {} |
| 245 IconLoader* icon_loader_; |
| 246 }; |
| 223 | 247 |
| 224 // Loads the icon from locally stored |icon_path_| on the blocking pool | 248 // Loads the icon from locally stored |icon_path_| on the blocking pool |
| 225 void LoadOnBlockingPool() { | 249 void LoadOnBlockingPool() { |
| 226 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 250 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 227 | 251 |
| 228 std::string data; | 252 std::string data; |
| 229 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { | 253 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { |
| 230 ReportResultOnBlockingPool(FAILED_TO_LOAD); | 254 ReportResultOnBlockingPool(FAILED_TO_LOAD); |
| 231 return; | 255 return; |
| 232 } | 256 } |
| 233 raw_icon_ = base::RefCountedString::TakeString(&data); | 257 raw_icon_ = base::RefCountedString::TakeString(&data); |
| 234 | 258 |
| 235 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( | 259 IconImageRequest* image_request = new IconImageRequest(task_runner_, this); |
| 236 this, raw_icon_->data(), ImageDecoder::DEFAULT_CODEC); | 260 ImageDecoder::Start(image_request, raw_icon_->data(), |
| 237 image_decoder->Start(task_runner_); | 261 ImageDecoder::DEFAULT_CODEC, false); |
| 238 } | 262 } |
| 239 | 263 |
| 240 void ReportResultOnBlockingPool(LoadResult result) { | 264 void ReportResultOnBlockingPool(LoadResult result) { |
| 241 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 265 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 242 | 266 |
| 243 load_result_ = result; | 267 load_result_ = result; |
| 244 BrowserThread::PostTask( | 268 BrowserThread::PostTask( |
| 245 BrowserThread::UI, | 269 BrowserThread::UI, |
| 246 FROM_HERE, | 270 FROM_HERE, |
| 247 base::Bind(&IconLoader::ReportResultOnUIThread, | 271 base::Bind(&IconLoader::ReportResultOnUIThread, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 258 client_->OnIconLoadFailure(); | 282 client_->OnIconLoadFailure(); |
| 259 } | 283 } |
| 260 | 284 |
| 261 void ReportResultOnUIThread() { | 285 void ReportResultOnUIThread() { |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 263 | 287 |
| 264 NotifyClient(); | 288 NotifyClient(); |
| 265 delete this; | 289 delete this; |
| 266 } | 290 } |
| 267 | 291 |
| 268 // ImageDecoder::Delegate overrides: | |
| 269 void OnImageDecoded(const ImageDecoder* decoder, | |
| 270 const SkBitmap& decoded_image) override { | |
| 271 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | |
| 272 icon_.MakeThreadSafe(); | |
| 273 ReportResultOnBlockingPool(SUCCESS); | |
| 274 } | |
| 275 | |
| 276 void OnDecodeImageFailed(const ImageDecoder* decoder) override { | |
| 277 ReportResultOnBlockingPool(FAILED_TO_DECODE); | |
| 278 } | |
| 279 | |
| 280 base::WeakPtr<KioskAppData> client_; | 292 base::WeakPtr<KioskAppData> client_; |
| 281 base::FilePath icon_path_; | 293 base::FilePath icon_path_; |
| 282 | 294 |
| 283 LoadResult load_result_; | 295 LoadResult load_result_; |
| 284 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 296 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 285 | 297 |
| 286 gfx::ImageSkia icon_; | 298 gfx::ImageSkia icon_; |
| 287 scoped_refptr<base::RefCountedString> raw_icon_; | 299 scoped_refptr<base::RefCountedString> raw_icon_; |
| 288 | 300 |
| 289 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 301 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 300 : client_(client) {} | 312 : client_(client) {} |
| 301 | 313 |
| 302 void Start(const std::string& app_id, | 314 void Start(const std::string& app_id, |
| 303 const std::string& manifest, | 315 const std::string& manifest, |
| 304 const GURL& icon_url, | 316 const GURL& icon_url, |
| 305 net::URLRequestContextGetter* context_getter) { | 317 net::URLRequestContextGetter* context_getter) { |
| 306 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = | 318 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = |
| 307 new extensions::WebstoreInstallHelper(this, | 319 new extensions::WebstoreInstallHelper(this, |
| 308 app_id, | 320 app_id, |
| 309 manifest, | 321 manifest, |
| 310 "", // No icon data. | |
| 311 icon_url, | 322 icon_url, |
| 312 context_getter); | 323 context_getter); |
| 313 webstore_helper->Start(); | 324 webstore_helper->Start(); |
| 314 } | 325 } |
| 315 | 326 |
| 316 private: | 327 private: |
| 317 friend class base::RefCounted<WebstoreDataParser>; | 328 friend class base::RefCounted<WebstoreDataParser>; |
| 318 | 329 |
| 319 ~WebstoreDataParser() override {} | 330 ~WebstoreDataParser() override {} |
| 320 | 331 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 655 |
| 645 SkBitmap icon = crx_loader->icon(); | 656 SkBitmap icon = crx_loader->icon(); |
| 646 if (icon.empty()) | 657 if (icon.empty()) |
| 647 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 658 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
| 648 SetCache(crx_loader->name(), icon); | 659 SetCache(crx_loader->name(), icon); |
| 649 | 660 |
| 650 SetStatus(STATUS_LOADED); | 661 SetStatus(STATUS_LOADED); |
| 651 } | 662 } |
| 652 | 663 |
| 653 } // namespace chromeos | 664 } // namespace chromeos |
| OLD | NEW |