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_); | |
238 } | 261 } |
239 | 262 |
240 void ReportResultOnBlockingPool(LoadResult result) { | 263 void ReportResultOnBlockingPool(LoadResult result) { |
241 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 264 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
242 | 265 |
243 load_result_ = result; | 266 load_result_ = result; |
244 BrowserThread::PostTask( | 267 BrowserThread::PostTask( |
245 BrowserThread::UI, | 268 BrowserThread::UI, |
246 FROM_HERE, | 269 FROM_HERE, |
247 base::Bind(&IconLoader::ReportResultOnUIThread, | 270 base::Bind(&IconLoader::ReportResultOnUIThread, |
(...skipping 10 matching lines...) Expand all Loading... |
258 client_->OnIconLoadFailure(); | 281 client_->OnIconLoadFailure(); |
259 } | 282 } |
260 | 283 |
261 void ReportResultOnUIThread() { | 284 void ReportResultOnUIThread() { |
262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
263 | 286 |
264 NotifyClient(); | 287 NotifyClient(); |
265 delete this; | 288 delete this; |
266 } | 289 } |
267 | 290 |
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_; | 291 base::WeakPtr<KioskAppData> client_; |
281 base::FilePath icon_path_; | 292 base::FilePath icon_path_; |
282 | 293 |
283 LoadResult load_result_; | 294 LoadResult load_result_; |
284 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 295 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
285 | 296 |
286 gfx::ImageSkia icon_; | 297 gfx::ImageSkia icon_; |
287 scoped_refptr<base::RefCountedString> raw_icon_; | 298 scoped_refptr<base::RefCountedString> raw_icon_; |
288 | 299 |
289 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 300 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
(...skipping 10 matching lines...) Expand all Loading... |
300 : client_(client) {} | 311 : client_(client) {} |
301 | 312 |
302 void Start(const std::string& app_id, | 313 void Start(const std::string& app_id, |
303 const std::string& manifest, | 314 const std::string& manifest, |
304 const GURL& icon_url, | 315 const GURL& icon_url, |
305 net::URLRequestContextGetter* context_getter) { | 316 net::URLRequestContextGetter* context_getter) { |
306 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = | 317 scoped_refptr<extensions::WebstoreInstallHelper> webstore_helper = |
307 new extensions::WebstoreInstallHelper(this, | 318 new extensions::WebstoreInstallHelper(this, |
308 app_id, | 319 app_id, |
309 manifest, | 320 manifest, |
310 "", // No icon data. | |
311 icon_url, | 321 icon_url, |
312 context_getter); | 322 context_getter); |
313 webstore_helper->Start(); | 323 webstore_helper->Start(); |
314 } | 324 } |
315 | 325 |
316 private: | 326 private: |
317 friend class base::RefCounted<WebstoreDataParser>; | 327 friend class base::RefCounted<WebstoreDataParser>; |
318 | 328 |
319 ~WebstoreDataParser() override {} | 329 ~WebstoreDataParser() override {} |
320 | 330 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 | 654 |
645 SkBitmap icon = crx_loader->icon(); | 655 SkBitmap icon = crx_loader->icon(); |
646 if (icon.empty()) | 656 if (icon.empty()) |
647 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 657 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
648 SetCache(crx_loader->name(), icon); | 658 SetCache(crx_loader->name(), icon); |
649 | 659 |
650 SetStatus(STATUS_LOADED); | 660 SetStatus(STATUS_LOADED); |
651 } | 661 } |
652 | 662 |
653 } // namespace chromeos | 663 } // namespace chromeos |
OLD | NEW |