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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/task_scheduler/post_task.h" | 14 #include "base/task_scheduler/post_task.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h" | 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h" |
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
22 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 22 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
23 #include "chrome/browser/extensions/webstore_install_helper.h" | 23 #include "chrome/browser/extensions/webstore_install_helper.h" |
24 #include "chrome/browser/image_decoder.h" | |
25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
26 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
27 #include "components/prefs/scoped_user_pref_update.h" | 26 #include "components/prefs/scoped_user_pref_update.h" |
28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
29 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
30 #include "extensions/browser/image_loader.h" | 29 #include "extensions/browser/image_loader.h" |
31 #include "extensions/browser/sandboxed_unpacker.h" | 30 #include "extensions/browser/sandboxed_unpacker.h" |
32 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
33 #include "extensions/common/extension_urls.h" | 32 #include "extensions/common/extension_urls.h" |
34 #include "extensions/common/manifest.h" | 33 #include "extensions/common/manifest.h" |
35 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
36 #include "extensions/common/manifest_handlers/icons_handler.h" | 35 #include "extensions/common/manifest_handlers/icons_handler.h" |
37 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 36 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
38 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
39 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
40 | 39 |
41 using content::BrowserThread; | 40 using content::BrowserThread; |
42 | 41 |
43 namespace chromeos { | 42 namespace chromeos { |
44 | 43 |
45 namespace { | 44 namespace { |
46 | 45 |
47 // Keys for local state data. See sample layout in KioskAppManager. | 46 // Keys for local state data. See sample layout in KioskAppManager. |
48 const char kKeyName[] = "name"; | 47 constexpr char kKeyRequiredPlatformVersion[] = "required_platform_version"; |
49 const char kKeyIcon[] = "icon"; | |
50 const char kKeyRequiredPlatformVersion[] = "required_platform_version"; | |
51 | 48 |
52 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; | 49 constexpr char kInvalidWebstoreResponseError[] = |
53 | 50 "Invalid Chrome Web Store reponse"; |
54 // Icon file extension. | |
55 const char kIconFileExtension[] = ".png"; | |
56 | |
57 // Save |raw_icon| for given |app_id|. | |
58 void SaveIconToLocalOnBlockingPool( | |
59 const base::FilePath& icon_path, | |
60 scoped_refptr<base::RefCountedString> raw_icon) { | |
61 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
62 | |
63 base::FilePath dir = icon_path.DirName(); | |
64 if (!base::PathExists(dir)) | |
65 CHECK(base::CreateDirectory(dir)); | |
66 | |
67 CHECK_EQ(static_cast<int>(raw_icon->size()), | |
68 base::WriteFile(icon_path, | |
69 raw_icon->data().c_str(), raw_icon->size())); | |
70 } | |
71 | 51 |
72 // Returns true for valid kiosk app manifest. | 52 // Returns true for valid kiosk app manifest. |
73 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { | 53 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { |
74 bool kiosk_enabled; | 54 bool kiosk_enabled; |
75 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, | 55 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, |
76 &kiosk_enabled)) { | 56 &kiosk_enabled)) { |
77 return kiosk_enabled; | 57 return kiosk_enabled; |
78 } | 58 } |
79 | 59 |
80 return false; | 60 return false; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 176 |
197 // Extracted meta data. | 177 // Extracted meta data. |
198 std::string name_; | 178 std::string name_; |
199 SkBitmap icon_; | 179 SkBitmap icon_; |
200 std::string required_platform_version_; | 180 std::string required_platform_version_; |
201 | 181 |
202 DISALLOW_COPY_AND_ASSIGN(CrxLoader); | 182 DISALLOW_COPY_AND_ASSIGN(CrxLoader); |
203 }; | 183 }; |
204 | 184 |
205 //////////////////////////////////////////////////////////////////////////////// | 185 //////////////////////////////////////////////////////////////////////////////// |
206 // KioskAppData::IconLoader | |
207 // Loads locally stored icon data and decode it. | |
208 | |
209 class KioskAppData::IconLoader { | |
210 public: | |
211 enum LoadResult { | |
212 SUCCESS, | |
213 FAILED_TO_LOAD, | |
214 FAILED_TO_DECODE, | |
215 }; | |
216 | |
217 IconLoader(const base::WeakPtr<KioskAppData>& client, | |
218 const base::FilePath& icon_path) | |
219 : client_(client), | |
220 icon_path_(icon_path), | |
221 load_result_(SUCCESS) {} | |
222 | |
223 void Start() { | |
224 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | |
225 base::SequencedWorkerPool::SequenceToken token = pool->GetSequenceToken(); | |
226 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
227 token, | |
228 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
229 task_runner_->PostTask(FROM_HERE, | |
230 base::Bind(&IconLoader::LoadOnBlockingPool, | |
231 base::Unretained(this))); | |
232 } | |
233 | |
234 private: | |
235 friend class base::RefCountedThreadSafe<IconLoader>; | |
236 | |
237 ~IconLoader() {} | |
238 | |
239 class IconImageRequest : public ImageDecoder::ImageRequest { | |
240 public: | |
241 IconImageRequest( | |
242 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | |
243 IconLoader* icon_loader) | |
244 : ImageRequest(task_runner), icon_loader_(icon_loader) {} | |
245 | |
246 void OnImageDecoded(const SkBitmap& decoded_image) override { | |
247 icon_loader_->icon_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | |
248 icon_loader_->icon_.MakeThreadSafe(); | |
249 icon_loader_->ReportResultOnBlockingPool(SUCCESS); | |
250 delete this; | |
251 } | |
252 | |
253 void OnDecodeImageFailed() override { | |
254 icon_loader_->ReportResultOnBlockingPool(FAILED_TO_DECODE); | |
255 delete this; | |
256 } | |
257 | |
258 private: | |
259 ~IconImageRequest() override {} | |
260 IconLoader* icon_loader_; | |
261 }; | |
262 | |
263 // Loads the icon from locally stored |icon_path_| on the blocking pool | |
264 void LoadOnBlockingPool() { | |
265 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
266 | |
267 std::string data; | |
268 if (!base::ReadFileToString(base::FilePath(icon_path_), &data)) { | |
269 ReportResultOnBlockingPool(FAILED_TO_LOAD); | |
270 return; | |
271 } | |
272 raw_icon_ = base::RefCountedString::TakeString(&data); | |
273 | |
274 IconImageRequest* image_request = new IconImageRequest(task_runner_, this); | |
275 ImageDecoder::Start(image_request, raw_icon_->data()); | |
276 } | |
277 | |
278 void ReportResultOnBlockingPool(LoadResult result) { | |
279 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
280 | |
281 load_result_ = result; | |
282 BrowserThread::PostTask( | |
283 BrowserThread::UI, | |
284 FROM_HERE, | |
285 base::Bind(&IconLoader::ReportResultOnUIThread, | |
286 base::Unretained(this))); | |
287 } | |
288 | |
289 void NotifyClient() { | |
290 if (!client_) | |
291 return; | |
292 | |
293 if (load_result_ == SUCCESS) | |
294 client_->OnIconLoadSuccess(icon_); | |
295 else | |
296 client_->OnIconLoadFailure(); | |
297 } | |
298 | |
299 void ReportResultOnUIThread() { | |
300 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
301 | |
302 NotifyClient(); | |
303 delete this; | |
304 } | |
305 | |
306 base::WeakPtr<KioskAppData> client_; | |
307 base::FilePath icon_path_; | |
308 | |
309 LoadResult load_result_; | |
310 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
311 | |
312 gfx::ImageSkia icon_; | |
313 scoped_refptr<base::RefCountedString> raw_icon_; | |
314 | |
315 DISALLOW_COPY_AND_ASSIGN(IconLoader); | |
316 }; | |
317 | |
318 //////////////////////////////////////////////////////////////////////////////// | |
319 // KioskAppData::WebstoreDataParser | 186 // KioskAppData::WebstoreDataParser |
320 // Use WebstoreInstallHelper to parse the manifest and decode the icon. | 187 // Use WebstoreInstallHelper to parse the manifest and decode the icon. |
321 | 188 |
322 class KioskAppData::WebstoreDataParser | 189 class KioskAppData::WebstoreDataParser |
323 : public extensions::WebstoreInstallHelper::Delegate { | 190 : public extensions::WebstoreInstallHelper::Delegate { |
324 public: | 191 public: |
325 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) | 192 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) |
326 : client_(client) {} | 193 : client_(client) {} |
327 | 194 |
328 void Start(const std::string& app_id, | 195 void Start(const std::string& app_id, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 }; | 259 }; |
393 | 260 |
394 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
395 // KioskAppData | 262 // KioskAppData |
396 | 263 |
397 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, | 264 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, |
398 const std::string& app_id, | 265 const std::string& app_id, |
399 const AccountId& account_id, | 266 const AccountId& account_id, |
400 const GURL& update_url, | 267 const GURL& update_url, |
401 const base::FilePath& cached_crx) | 268 const base::FilePath& cached_crx) |
402 : delegate_(delegate), | 269 : KioskAppDataBase(KioskAppManager::kKioskDictionaryName, |
270 app_id, | |
271 account_id), | |
272 delegate_(delegate), | |
403 status_(STATUS_INIT), | 273 status_(STATUS_INIT), |
404 app_id_(app_id), | |
405 account_id_(account_id), | |
406 update_url_(update_url), | 274 update_url_(update_url), |
407 crx_file_(cached_crx) {} | 275 crx_file_(cached_crx), |
276 weak_factory_(this) {} | |
408 | 277 |
409 KioskAppData::~KioskAppData() {} | 278 KioskAppData::~KioskAppData() {} |
410 | 279 |
411 void KioskAppData::Load() { | 280 void KioskAppData::Load() { |
412 SetStatus(STATUS_LOADING); | 281 SetStatus(STATUS_LOADING); |
413 | 282 |
414 if (LoadFromCache()) | 283 if (LoadFromCache()) |
415 return; | 284 return; |
416 | 285 |
417 StartFetch(); | 286 StartFetch(); |
418 } | 287 } |
419 | 288 |
420 void KioskAppData::ClearCache() { | |
421 PrefService* local_state = g_browser_process->local_state(); | |
422 | |
423 DictionaryPrefUpdate dict_update(local_state, | |
424 KioskAppManager::kKioskDictionaryName); | |
425 | |
426 std::string app_key = std::string(KioskAppManager::kKeyApps) + '.' + app_id_; | |
427 dict_update->Remove(app_key, NULL); | |
428 | |
429 if (!icon_path_.empty()) { | |
430 base::PostTaskWithTraits( | |
431 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | |
432 base::TaskPriority::BACKGROUND), | |
433 base::Bind(base::IgnoreResult(&base::DeleteFile), icon_path_, false)); | |
434 } | |
435 } | |
436 | |
437 void KioskAppData::LoadFromInstalledApp(Profile* profile, | 289 void KioskAppData::LoadFromInstalledApp(Profile* profile, |
438 const extensions::Extension* app) { | 290 const extensions::Extension* app) { |
439 SetStatus(STATUS_LOADING); | 291 SetStatus(STATUS_LOADING); |
440 | 292 |
441 if (!app) { | 293 if (!app) { |
442 app = extensions::ExtensionSystem::Get(profile) | 294 app = extensions::ExtensionSystem::Get(profile) |
443 ->extension_service() | 295 ->extension_service() |
444 ->GetInstalledExtension(app_id_); | 296 ->GetInstalledExtension(app_id()); |
445 } | 297 } |
446 | 298 |
447 DCHECK_EQ(app_id_, app->id()); | 299 DCHECK_EQ(app_id(), app->id()); |
448 | 300 |
449 name_ = app->name(); | 301 name_ = app->name(); |
450 required_platform_version_ = | 302 required_platform_version_ = |
451 extensions::KioskModeInfo::Get(app)->required_platform_version; | 303 extensions::KioskModeInfo::Get(app)->required_platform_version; |
452 | 304 |
453 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; | 305 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; |
454 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 306 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
455 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); | 307 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); |
456 extensions::ImageLoader::Get(profile)->LoadImageAsync( | 308 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
457 app, image, gfx::Size(kIconSize, kIconSize), | 309 app, image, gfx::Size(kIconSize, kIconSize), |
458 base::Bind(&KioskAppData::OnExtensionIconLoaded, AsWeakPtr())); | 310 base::Bind(&KioskAppData::OnExtensionIconLoaded, |
311 weak_factory_.GetWeakPtr())); | |
459 } | 312 } |
460 | 313 |
461 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { | 314 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { |
462 if (crx_file_ == crx_file) | 315 if (crx_file_ == crx_file) |
463 return; | 316 return; |
464 | 317 |
465 crx_file_ = crx_file; | 318 crx_file_ = crx_file; |
466 LoadFromCrx(); | 319 LoadFromCrx(); |
467 } | 320 } |
468 | 321 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 status_ = status; | 353 status_ = status; |
501 | 354 |
502 if (!delegate_) | 355 if (!delegate_) |
503 return; | 356 return; |
504 | 357 |
505 switch (status_) { | 358 switch (status_) { |
506 case STATUS_INIT: | 359 case STATUS_INIT: |
507 break; | 360 break; |
508 case STATUS_LOADING: | 361 case STATUS_LOADING: |
509 case STATUS_LOADED: | 362 case STATUS_LOADED: |
510 delegate_->OnKioskAppDataChanged(app_id_); | 363 delegate_->OnKioskAppDataChanged(app_id()); |
511 break; | 364 break; |
512 case STATUS_ERROR: | 365 case STATUS_ERROR: |
513 delegate_->OnKioskAppDataLoadFailure(app_id_); | 366 delegate_->OnKioskAppDataLoadFailure(app_id()); |
514 break; | 367 break; |
515 } | 368 } |
516 } | 369 } |
517 | 370 |
518 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { | 371 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { |
519 return g_browser_process->system_request_context(); | 372 return g_browser_process->system_request_context(); |
520 } | 373 } |
521 | 374 |
522 bool KioskAppData::LoadFromCache() { | 375 bool KioskAppData::LoadFromCache() { |
523 const std::string app_key = | 376 PrefService* local_state = g_browser_process->local_state(); |
524 std::string(KioskAppManager::kKeyApps) + '.' + app_id_; | 377 const base::DictionaryValue* dict = |
525 const std::string name_key = app_key + '.' + kKeyName; | 378 local_state->GetDictionary(dictionary_name()); |
526 const std::string icon_path_key = app_key + '.' + kKeyIcon; | 379 |
380 if (!LoadFromDictionary(*dict)) | |
381 return false; | |
382 | |
383 const std::string app_key = std::string(kKeyApps) + '.' + app_id(); | |
527 const std::string required_platform_version_key = | 384 const std::string required_platform_version_key = |
528 app_key + '.' + kKeyRequiredPlatformVersion; | 385 app_key + '.' + kKeyRequiredPlatformVersion; |
529 | 386 |
530 PrefService* local_state = g_browser_process->local_state(); | 387 return dict->GetString(required_platform_version_key, |
531 const base::DictionaryValue* dict = | 388 &required_platform_version_); |
532 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); | |
533 | |
534 icon_path_.clear(); | |
535 std::string icon_path_string; | |
536 if (!dict->GetString(name_key, &name_) || | |
537 !dict->GetString(icon_path_key, &icon_path_string) || | |
538 !dict->GetString(required_platform_version_key, | |
539 &required_platform_version_)) { | |
540 return false; | |
541 } | |
542 icon_path_ = base::FilePath(icon_path_string); | |
543 | |
544 // IconLoader deletes itself when done. | |
545 (new IconLoader(AsWeakPtr(), icon_path_))->Start(); | |
546 return true; | |
547 } | |
548 | |
549 void KioskAppData::SetCache(const std::string& name, | |
550 const base::FilePath& icon_path, | |
551 const std::string& required_platform_version) { | |
552 name_ = name; | |
553 icon_path_ = icon_path; | |
554 required_platform_version_ = required_platform_version; | |
555 | |
556 const std::string app_key = | |
557 std::string(KioskAppManager::kKeyApps) + '.' + app_id_; | |
558 const std::string name_key = app_key + '.' + kKeyName; | |
559 const std::string icon_path_key = app_key + '.' + kKeyIcon; | |
560 const std::string required_platform_version_key = | |
561 app_key + '.' + kKeyRequiredPlatformVersion; | |
562 | |
563 PrefService* local_state = g_browser_process->local_state(); | |
564 DictionaryPrefUpdate dict_update(local_state, | |
565 KioskAppManager::kKioskDictionaryName); | |
566 dict_update->SetString(name_key, name); | |
567 dict_update->SetString(icon_path_key, icon_path.value()); | |
568 dict_update->SetString(required_platform_version_key, | |
569 required_platform_version); | |
570 } | 389 } |
571 | 390 |
572 void KioskAppData::SetCache(const std::string& name, | 391 void KioskAppData::SetCache(const std::string& name, |
573 const SkBitmap& icon, | 392 const SkBitmap& icon, |
574 const std::string& required_platform_version) { | 393 const std::string& required_platform_version) { |
394 name_ = name; | |
395 required_platform_version_ = required_platform_version; | |
575 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); | 396 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); |
576 icon_.MakeThreadSafe(); | 397 icon_.MakeThreadSafe(); |
577 | 398 |
578 std::vector<unsigned char> image_data; | |
579 CHECK(gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &image_data)); | |
580 scoped_refptr<base::RefCountedString> raw_icon(new base::RefCountedString); | |
581 raw_icon->data().assign(image_data.begin(), image_data.end()); | |
582 | |
583 base::FilePath cache_dir; | 399 base::FilePath cache_dir; |
584 if (delegate_) | 400 if (delegate_) |
585 delegate_->GetKioskAppIconCacheDir(&cache_dir); | 401 delegate_->GetKioskAppIconCacheDir(&cache_dir); |
586 | 402 |
587 base::FilePath icon_path = | 403 SaveIcon(icon, cache_dir); |
588 cache_dir.AppendASCII(app_id_).AddExtension(kIconFileExtension); | |
589 BrowserThread::GetBlockingPool()->PostTask( | |
590 FROM_HERE, | |
591 base::Bind(&SaveIconToLocalOnBlockingPool, icon_path, raw_icon)); | |
592 | 404 |
593 SetCache(name, icon_path, required_platform_version); | 405 PrefService* local_state = g_browser_process->local_state(); |
406 DictionaryPrefUpdate dict_update(local_state, dictionary_name()); | |
407 SaveToDictionary(dict_update); | |
408 | |
409 const std::string app_key = std::string(kKeyApps) + '.' + app_id(); | |
410 const std::string required_platform_version_key = | |
411 app_key + '.' + kKeyRequiredPlatformVersion; | |
412 | |
413 dict_update->SetString(required_platform_version_key, | |
414 required_platform_version); | |
594 } | 415 } |
595 | 416 |
596 void KioskAppData::OnExtensionIconLoaded(const gfx::Image& icon) { | 417 void KioskAppData::OnExtensionIconLoaded(const gfx::Image& icon) { |
597 if (icon.IsEmpty()) { | 418 if (icon.IsEmpty()) { |
598 LOG(WARNING) << "Failed to load icon from installed app" | 419 LOG(WARNING) << "Failed to load icon from installed app" |
599 << ", id=" << app_id_; | 420 << ", id=" << app_id(); |
600 SetCache(name_, *extensions::util::GetDefaultAppIcon().bitmap(), | 421 SetCache(name_, *extensions::util::GetDefaultAppIcon().bitmap(), |
601 required_platform_version_); | 422 required_platform_version_); |
602 } else { | 423 } else { |
603 SetCache(name_, icon.AsBitmap(), required_platform_version_); | 424 SetCache(name_, icon.AsBitmap(), required_platform_version_); |
604 } | 425 } |
605 | 426 |
606 SetStatus(STATUS_LOADED); | 427 SetStatus(STATUS_LOADED); |
607 } | 428 } |
608 | 429 |
609 void KioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { | 430 void KioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { |
610 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 431 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
432 kiosk_app_icon_loader_.release(); | |
xiyuan
2017/04/11 16:22:01
Oops.. This should be kiosk_app_icon_loader_.reset
Sergey Poromov
2017/04/12 12:48:36
Done. Thank you!
| |
611 icon_ = icon; | 433 icon_ = icon; |
612 SetStatus(STATUS_LOADED); | 434 SetStatus(STATUS_LOADED); |
613 } | 435 } |
614 | 436 |
615 void KioskAppData::OnIconLoadFailure() { | 437 void KioskAppData::OnIconLoadFailure() { |
438 kiosk_app_icon_loader_.release(); | |
616 // Re-fetch data from web store when failed to load cached data. | 439 // Re-fetch data from web store when failed to load cached data. |
617 StartFetch(); | 440 StartFetch(); |
618 } | 441 } |
619 | 442 |
620 void KioskAppData::OnWebstoreParseSuccess( | 443 void KioskAppData::OnWebstoreParseSuccess( |
621 const SkBitmap& icon, | 444 const SkBitmap& icon, |
622 const std::string& required_platform_version) { | 445 const std::string& required_platform_version) { |
623 SetCache(name_, icon, required_platform_version); | 446 SetCache(name_, icon, required_platform_version); |
624 SetStatus(STATUS_LOADED); | 447 SetStatus(STATUS_LOADED); |
625 } | 448 } |
626 | 449 |
627 void KioskAppData::OnWebstoreParseFailure() { | 450 void KioskAppData::OnWebstoreParseFailure() { |
628 SetStatus(STATUS_ERROR); | 451 SetStatus(STATUS_ERROR); |
629 } | 452 } |
630 | 453 |
631 void KioskAppData::StartFetch() { | 454 void KioskAppData::StartFetch() { |
632 if (!IsFromWebStore()) { | 455 if (!IsFromWebStore()) { |
633 LoadFromCrx(); | 456 LoadFromCrx(); |
634 return; | 457 return; |
635 } | 458 } |
636 | 459 |
637 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher( | 460 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher( |
638 this, | 461 this, GetRequestContextGetter(), GURL(), app_id())); |
639 GetRequestContextGetter(), | |
640 GURL(), | |
641 app_id_)); | |
642 webstore_fetcher_->set_max_auto_retries(3); | 462 webstore_fetcher_->set_max_auto_retries(3); |
643 webstore_fetcher_->Start(); | 463 webstore_fetcher_->Start(); |
644 } | 464 } |
645 | 465 |
646 void KioskAppData::OnWebstoreRequestFailure() { | 466 void KioskAppData::OnWebstoreRequestFailure() { |
647 SetStatus(STATUS_ERROR); | 467 SetStatus(STATUS_ERROR); |
648 } | 468 } |
649 | 469 |
650 void KioskAppData::OnWebstoreResponseParseSuccess( | 470 void KioskAppData::OnWebstoreResponseParseSuccess( |
651 std::unique_ptr<base::DictionaryValue> webstore_data) { | 471 std::unique_ptr<base::DictionaryValue> webstore_data) { |
(...skipping 15 matching lines...) Expand all Loading... | |
667 GURL icon_url = | 487 GURL icon_url = |
668 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); | 488 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); |
669 if (!icon_url.is_valid()) { | 489 if (!icon_url.is_valid()) { |
670 LOG(ERROR) << "Webstore response error (icon url): " | 490 LOG(ERROR) << "Webstore response error (icon url): " |
671 << ValueToString(*webstore_data); | 491 << ValueToString(*webstore_data); |
672 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 492 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
673 return; | 493 return; |
674 } | 494 } |
675 | 495 |
676 // WebstoreDataParser deletes itself when done. | 496 // WebstoreDataParser deletes itself when done. |
677 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, | 497 (new WebstoreDataParser(weak_factory_.GetWeakPtr())) |
678 manifest, | 498 ->Start(app_id(), manifest, icon_url, GetRequestContextGetter()); |
679 icon_url, | |
680 GetRequestContextGetter()); | |
681 } | 499 } |
682 | 500 |
683 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { | 501 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { |
684 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ | 502 LOG(ERROR) << "Webstore failed for kiosk app " << app_id() << ", " << error; |
685 << ", " << error; | |
686 webstore_fetcher_.reset(); | 503 webstore_fetcher_.reset(); |
687 SetStatus(STATUS_ERROR); | 504 SetStatus(STATUS_ERROR); |
688 } | 505 } |
689 | 506 |
690 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, | 507 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, |
691 const char* key, | 508 const char* key, |
692 std::string* value) { | 509 std::string* value) { |
693 if (!response->GetString(key, value)) { | 510 if (!response->GetString(key, value)) { |
694 LOG(ERROR) << "Webstore response error (" << key | 511 LOG(ERROR) << "Webstore response error (" << key |
695 << "): " << ValueToString(*response); | 512 << "): " << ValueToString(*response); |
696 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 513 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
697 return false; | 514 return false; |
698 } | 515 } |
699 return true; | 516 return true; |
700 } | 517 } |
701 | 518 |
702 void KioskAppData::LoadFromCrx() { | 519 void KioskAppData::LoadFromCrx() { |
703 if (crx_file_.empty()) | 520 if (crx_file_.empty()) |
704 return; | 521 return; |
705 | 522 |
706 scoped_refptr<CrxLoader> crx_loader(new CrxLoader(AsWeakPtr(), crx_file_)); | 523 scoped_refptr<CrxLoader> crx_loader( |
524 new CrxLoader(weak_factory_.GetWeakPtr(), crx_file_)); | |
707 crx_loader->Start(); | 525 crx_loader->Start(); |
708 } | 526 } |
709 | 527 |
710 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { | 528 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { |
711 DCHECK(crx_loader); | 529 DCHECK(crx_loader); |
712 | 530 |
713 if (crx_loader->crx_file() != crx_file_) | 531 if (crx_loader->crx_file() != crx_file_) |
714 return; | 532 return; |
715 | 533 |
716 if (!crx_loader->success()) { | 534 if (!crx_loader->success()) { |
717 SetStatus(STATUS_ERROR); | 535 SetStatus(STATUS_ERROR); |
718 return; | 536 return; |
719 } | 537 } |
720 | 538 |
721 SkBitmap icon = crx_loader->icon(); | 539 SkBitmap icon = crx_loader->icon(); |
722 if (icon.empty()) | 540 if (icon.empty()) |
723 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 541 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
724 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); | 542 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); |
725 | 543 |
726 SetStatus(STATUS_LOADED); | 544 SetStatus(STATUS_LOADED); |
727 } | 545 } |
728 | 546 |
729 } // namespace chromeos | 547 } // namespace chromeos |
OLD | NEW |