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" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
26 #include "components/prefs/scoped_user_pref_update.h" | 27 #include "components/prefs/scoped_user_pref_update.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
29 #include "extensions/browser/image_loader.h" | 30 #include "extensions/browser/image_loader.h" |
30 #include "extensions/browser/sandboxed_unpacker.h" | 31 #include "extensions/browser/sandboxed_unpacker.h" |
31 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
32 #include "extensions/common/extension_urls.h" | 33 #include "extensions/common/extension_urls.h" |
33 #include "extensions/common/manifest.h" | 34 #include "extensions/common/manifest.h" |
34 #include "extensions/common/manifest_constants.h" | 35 #include "extensions/common/manifest_constants.h" |
35 #include "extensions/common/manifest_handlers/icons_handler.h" | 36 #include "extensions/common/manifest_handlers/icons_handler.h" |
36 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 37 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
37 #include "ui/gfx/codec/png_codec.h" | 38 #include "ui/gfx/codec/png_codec.h" |
38 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
39 | 40 |
40 using content::BrowserThread; | 41 using content::BrowserThread; |
41 | 42 |
42 namespace chromeos { | 43 namespace chromeos { |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 // Keys for local state data. See sample layout in KioskAppManager. | 47 // Keys for local state data. See sample layout in KioskAppManager. |
47 constexpr char kKeyRequiredPlatformVersion[] = "required_platform_version"; | 48 const char kKeyName[] = "name"; |
| 49 const char kKeyIcon[] = "icon"; |
| 50 const char kKeyRequiredPlatformVersion[] = "required_platform_version"; |
48 | 51 |
49 constexpr char kInvalidWebstoreResponseError[] = | 52 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; |
50 "Invalid Chrome Web Store reponse"; | 53 |
| 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 } |
51 | 71 |
52 // Returns true for valid kiosk app manifest. | 72 // Returns true for valid kiosk app manifest. |
53 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { | 73 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { |
54 bool kiosk_enabled; | 74 bool kiosk_enabled; |
55 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, | 75 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, |
56 &kiosk_enabled)) { | 76 &kiosk_enabled)) { |
57 return kiosk_enabled; | 77 return kiosk_enabled; |
58 } | 78 } |
59 | 79 |
60 return false; | 80 return false; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 196 |
177 // Extracted meta data. | 197 // Extracted meta data. |
178 std::string name_; | 198 std::string name_; |
179 SkBitmap icon_; | 199 SkBitmap icon_; |
180 std::string required_platform_version_; | 200 std::string required_platform_version_; |
181 | 201 |
182 DISALLOW_COPY_AND_ASSIGN(CrxLoader); | 202 DISALLOW_COPY_AND_ASSIGN(CrxLoader); |
183 }; | 203 }; |
184 | 204 |
185 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 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 //////////////////////////////////////////////////////////////////////////////// |
186 // KioskAppData::WebstoreDataParser | 319 // KioskAppData::WebstoreDataParser |
187 // Use WebstoreInstallHelper to parse the manifest and decode the icon. | 320 // Use WebstoreInstallHelper to parse the manifest and decode the icon. |
188 | 321 |
189 class KioskAppData::WebstoreDataParser | 322 class KioskAppData::WebstoreDataParser |
190 : public extensions::WebstoreInstallHelper::Delegate { | 323 : public extensions::WebstoreInstallHelper::Delegate { |
191 public: | 324 public: |
192 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) | 325 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) |
193 : client_(client) {} | 326 : client_(client) {} |
194 | 327 |
195 void Start(const std::string& app_id, | 328 void Start(const std::string& app_id, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 }; | 392 }; |
260 | 393 |
261 //////////////////////////////////////////////////////////////////////////////// | 394 //////////////////////////////////////////////////////////////////////////////// |
262 // KioskAppData | 395 // KioskAppData |
263 | 396 |
264 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, | 397 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, |
265 const std::string& app_id, | 398 const std::string& app_id, |
266 const AccountId& account_id, | 399 const AccountId& account_id, |
267 const GURL& update_url, | 400 const GURL& update_url, |
268 const base::FilePath& cached_crx) | 401 const base::FilePath& cached_crx) |
269 : KioskAppDataBase(KioskAppManager::kKioskDictionaryName, | 402 : delegate_(delegate), |
270 app_id, | |
271 account_id), | |
272 delegate_(delegate), | |
273 status_(STATUS_INIT), | 403 status_(STATUS_INIT), |
| 404 app_id_(app_id), |
| 405 account_id_(account_id), |
274 update_url_(update_url), | 406 update_url_(update_url), |
275 crx_file_(cached_crx), | 407 crx_file_(cached_crx) {} |
276 weak_factory_(this) {} | |
277 | 408 |
278 KioskAppData::~KioskAppData() {} | 409 KioskAppData::~KioskAppData() {} |
279 | 410 |
280 void KioskAppData::Load() { | 411 void KioskAppData::Load() { |
281 SetStatus(STATUS_LOADING); | 412 SetStatus(STATUS_LOADING); |
282 | 413 |
283 if (LoadFromCache()) | 414 if (LoadFromCache()) |
284 return; | 415 return; |
285 | 416 |
286 StartFetch(); | 417 StartFetch(); |
287 } | 418 } |
288 | 419 |
| 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 |
289 void KioskAppData::LoadFromInstalledApp(Profile* profile, | 437 void KioskAppData::LoadFromInstalledApp(Profile* profile, |
290 const extensions::Extension* app) { | 438 const extensions::Extension* app) { |
291 SetStatus(STATUS_LOADING); | 439 SetStatus(STATUS_LOADING); |
292 | 440 |
293 if (!app) { | 441 if (!app) { |
294 app = extensions::ExtensionSystem::Get(profile) | 442 app = extensions::ExtensionSystem::Get(profile) |
295 ->extension_service() | 443 ->extension_service() |
296 ->GetInstalledExtension(app_id()); | 444 ->GetInstalledExtension(app_id_); |
297 } | 445 } |
298 | 446 |
299 DCHECK_EQ(app_id(), app->id()); | 447 DCHECK_EQ(app_id_, app->id()); |
300 | 448 |
301 name_ = app->name(); | 449 name_ = app->name(); |
302 required_platform_version_ = | 450 required_platform_version_ = |
303 extensions::KioskModeInfo::Get(app)->required_platform_version; | 451 extensions::KioskModeInfo::Get(app)->required_platform_version; |
304 | 452 |
305 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; | 453 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; |
306 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 454 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
307 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); | 455 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); |
308 extensions::ImageLoader::Get(profile)->LoadImageAsync( | 456 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
309 app, image, gfx::Size(kIconSize, kIconSize), | 457 app, image, gfx::Size(kIconSize, kIconSize), |
310 base::Bind(&KioskAppData::OnExtensionIconLoaded, | 458 base::Bind(&KioskAppData::OnExtensionIconLoaded, AsWeakPtr())); |
311 weak_factory_.GetWeakPtr())); | |
312 } | 459 } |
313 | 460 |
314 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { | 461 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { |
315 if (crx_file_ == crx_file) | 462 if (crx_file_ == crx_file) |
316 return; | 463 return; |
317 | 464 |
318 crx_file_ = crx_file; | 465 crx_file_ = crx_file; |
319 LoadFromCrx(); | 466 LoadFromCrx(); |
320 } | 467 } |
321 | 468 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 status_ = status; | 500 status_ = status; |
354 | 501 |
355 if (!delegate_) | 502 if (!delegate_) |
356 return; | 503 return; |
357 | 504 |
358 switch (status_) { | 505 switch (status_) { |
359 case STATUS_INIT: | 506 case STATUS_INIT: |
360 break; | 507 break; |
361 case STATUS_LOADING: | 508 case STATUS_LOADING: |
362 case STATUS_LOADED: | 509 case STATUS_LOADED: |
363 delegate_->OnKioskAppDataChanged(app_id()); | 510 delegate_->OnKioskAppDataChanged(app_id_); |
364 break; | 511 break; |
365 case STATUS_ERROR: | 512 case STATUS_ERROR: |
366 delegate_->OnKioskAppDataLoadFailure(app_id()); | 513 delegate_->OnKioskAppDataLoadFailure(app_id_); |
367 break; | 514 break; |
368 } | 515 } |
369 } | 516 } |
370 | 517 |
371 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { | 518 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { |
372 return g_browser_process->system_request_context(); | 519 return g_browser_process->system_request_context(); |
373 } | 520 } |
374 | 521 |
375 bool KioskAppData::LoadFromCache() { | 522 bool KioskAppData::LoadFromCache() { |
376 PrefService* local_state = g_browser_process->local_state(); | 523 const std::string app_key = |
377 const base::DictionaryValue* dict = | 524 std::string(KioskAppManager::kKeyApps) + '.' + app_id_; |
378 local_state->GetDictionary(dictionary_name()); | 525 const std::string name_key = app_key + '.' + kKeyName; |
379 | 526 const std::string icon_path_key = app_key + '.' + kKeyIcon; |
380 if (!LoadFromDictionary(*dict)) | |
381 return false; | |
382 | |
383 const std::string app_key = std::string(kKeyApps) + '.' + app_id(); | |
384 const std::string required_platform_version_key = | 527 const std::string required_platform_version_key = |
385 app_key + '.' + kKeyRequiredPlatformVersion; | 528 app_key + '.' + kKeyRequiredPlatformVersion; |
386 | 529 |
387 return dict->GetString(required_platform_version_key, | 530 PrefService* local_state = g_browser_process->local_state(); |
388 &required_platform_version_); | 531 const base::DictionaryValue* dict = |
| 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); |
389 } | 570 } |
390 | 571 |
391 void KioskAppData::SetCache(const std::string& name, | 572 void KioskAppData::SetCache(const std::string& name, |
392 const SkBitmap& icon, | 573 const SkBitmap& icon, |
393 const std::string& required_platform_version) { | 574 const std::string& required_platform_version) { |
394 name_ = name; | |
395 required_platform_version_ = required_platform_version; | |
396 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); | 575 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); |
397 icon_.MakeThreadSafe(); | 576 icon_.MakeThreadSafe(); |
398 | 577 |
| 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 |
399 base::FilePath cache_dir; | 583 base::FilePath cache_dir; |
400 if (delegate_) | 584 if (delegate_) |
401 delegate_->GetKioskAppIconCacheDir(&cache_dir); | 585 delegate_->GetKioskAppIconCacheDir(&cache_dir); |
402 | 586 |
403 SaveIcon(icon, cache_dir); | 587 base::FilePath icon_path = |
| 588 cache_dir.AppendASCII(app_id_).AddExtension(kIconFileExtension); |
| 589 BrowserThread::GetBlockingPool()->PostTask( |
| 590 FROM_HERE, |
| 591 base::Bind(&SaveIconToLocalOnBlockingPool, icon_path, raw_icon)); |
404 | 592 |
405 PrefService* local_state = g_browser_process->local_state(); | 593 SetCache(name, icon_path, required_platform_version); |
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); | |
415 } | 594 } |
416 | 595 |
417 void KioskAppData::OnExtensionIconLoaded(const gfx::Image& icon) { | 596 void KioskAppData::OnExtensionIconLoaded(const gfx::Image& icon) { |
418 if (icon.IsEmpty()) { | 597 if (icon.IsEmpty()) { |
419 LOG(WARNING) << "Failed to load icon from installed app" | 598 LOG(WARNING) << "Failed to load icon from installed app" |
420 << ", id=" << app_id(); | 599 << ", id=" << app_id_; |
421 SetCache(name_, *extensions::util::GetDefaultAppIcon().bitmap(), | 600 SetCache(name_, *extensions::util::GetDefaultAppIcon().bitmap(), |
422 required_platform_version_); | 601 required_platform_version_); |
423 } else { | 602 } else { |
424 SetCache(name_, icon.AsBitmap(), required_platform_version_); | 603 SetCache(name_, icon.AsBitmap(), required_platform_version_); |
425 } | 604 } |
426 | 605 |
427 SetStatus(STATUS_LOADED); | 606 SetStatus(STATUS_LOADED); |
428 } | 607 } |
429 | 608 |
430 void KioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { | 609 void KioskAppData::OnIconLoadSuccess(const gfx::ImageSkia& icon) { |
431 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 610 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
432 kiosk_app_icon_loader_.release(); | |
433 icon_ = icon; | 611 icon_ = icon; |
434 SetStatus(STATUS_LOADED); | 612 SetStatus(STATUS_LOADED); |
435 } | 613 } |
436 | 614 |
437 void KioskAppData::OnIconLoadFailure() { | 615 void KioskAppData::OnIconLoadFailure() { |
438 kiosk_app_icon_loader_.release(); | |
439 // Re-fetch data from web store when failed to load cached data. | 616 // Re-fetch data from web store when failed to load cached data. |
440 StartFetch(); | 617 StartFetch(); |
441 } | 618 } |
442 | 619 |
443 void KioskAppData::OnWebstoreParseSuccess( | 620 void KioskAppData::OnWebstoreParseSuccess( |
444 const SkBitmap& icon, | 621 const SkBitmap& icon, |
445 const std::string& required_platform_version) { | 622 const std::string& required_platform_version) { |
446 SetCache(name_, icon, required_platform_version); | 623 SetCache(name_, icon, required_platform_version); |
447 SetStatus(STATUS_LOADED); | 624 SetStatus(STATUS_LOADED); |
448 } | 625 } |
449 | 626 |
450 void KioskAppData::OnWebstoreParseFailure() { | 627 void KioskAppData::OnWebstoreParseFailure() { |
451 SetStatus(STATUS_ERROR); | 628 SetStatus(STATUS_ERROR); |
452 } | 629 } |
453 | 630 |
454 void KioskAppData::StartFetch() { | 631 void KioskAppData::StartFetch() { |
455 if (!IsFromWebStore()) { | 632 if (!IsFromWebStore()) { |
456 LoadFromCrx(); | 633 LoadFromCrx(); |
457 return; | 634 return; |
458 } | 635 } |
459 | 636 |
460 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher( | 637 webstore_fetcher_.reset(new extensions::WebstoreDataFetcher( |
461 this, GetRequestContextGetter(), GURL(), app_id())); | 638 this, |
| 639 GetRequestContextGetter(), |
| 640 GURL(), |
| 641 app_id_)); |
462 webstore_fetcher_->set_max_auto_retries(3); | 642 webstore_fetcher_->set_max_auto_retries(3); |
463 webstore_fetcher_->Start(); | 643 webstore_fetcher_->Start(); |
464 } | 644 } |
465 | 645 |
466 void KioskAppData::OnWebstoreRequestFailure() { | 646 void KioskAppData::OnWebstoreRequestFailure() { |
467 SetStatus(STATUS_ERROR); | 647 SetStatus(STATUS_ERROR); |
468 } | 648 } |
469 | 649 |
470 void KioskAppData::OnWebstoreResponseParseSuccess( | 650 void KioskAppData::OnWebstoreResponseParseSuccess( |
471 std::unique_ptr<base::DictionaryValue> webstore_data) { | 651 std::unique_ptr<base::DictionaryValue> webstore_data) { |
(...skipping 15 matching lines...) Expand all Loading... |
487 GURL icon_url = | 667 GURL icon_url = |
488 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); | 668 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); |
489 if (!icon_url.is_valid()) { | 669 if (!icon_url.is_valid()) { |
490 LOG(ERROR) << "Webstore response error (icon url): " | 670 LOG(ERROR) << "Webstore response error (icon url): " |
491 << ValueToString(*webstore_data); | 671 << ValueToString(*webstore_data); |
492 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 672 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
493 return; | 673 return; |
494 } | 674 } |
495 | 675 |
496 // WebstoreDataParser deletes itself when done. | 676 // WebstoreDataParser deletes itself when done. |
497 (new WebstoreDataParser(weak_factory_.GetWeakPtr())) | 677 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, |
498 ->Start(app_id(), manifest, icon_url, GetRequestContextGetter()); | 678 manifest, |
| 679 icon_url, |
| 680 GetRequestContextGetter()); |
499 } | 681 } |
500 | 682 |
501 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { | 683 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { |
502 LOG(ERROR) << "Webstore failed for kiosk app " << app_id() << ", " << error; | 684 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ |
| 685 << ", " << error; |
503 webstore_fetcher_.reset(); | 686 webstore_fetcher_.reset(); |
504 SetStatus(STATUS_ERROR); | 687 SetStatus(STATUS_ERROR); |
505 } | 688 } |
506 | 689 |
507 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, | 690 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, |
508 const char* key, | 691 const char* key, |
509 std::string* value) { | 692 std::string* value) { |
510 if (!response->GetString(key, value)) { | 693 if (!response->GetString(key, value)) { |
511 LOG(ERROR) << "Webstore response error (" << key | 694 LOG(ERROR) << "Webstore response error (" << key |
512 << "): " << ValueToString(*response); | 695 << "): " << ValueToString(*response); |
513 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 696 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
514 return false; | 697 return false; |
515 } | 698 } |
516 return true; | 699 return true; |
517 } | 700 } |
518 | 701 |
519 void KioskAppData::LoadFromCrx() { | 702 void KioskAppData::LoadFromCrx() { |
520 if (crx_file_.empty()) | 703 if (crx_file_.empty()) |
521 return; | 704 return; |
522 | 705 |
523 scoped_refptr<CrxLoader> crx_loader( | 706 scoped_refptr<CrxLoader> crx_loader(new CrxLoader(AsWeakPtr(), crx_file_)); |
524 new CrxLoader(weak_factory_.GetWeakPtr(), crx_file_)); | |
525 crx_loader->Start(); | 707 crx_loader->Start(); |
526 } | 708 } |
527 | 709 |
528 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { | 710 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { |
529 DCHECK(crx_loader); | 711 DCHECK(crx_loader); |
530 | 712 |
531 if (crx_loader->crx_file() != crx_file_) | 713 if (crx_loader->crx_file() != crx_file_) |
532 return; | 714 return; |
533 | 715 |
534 if (!crx_loader->success()) { | 716 if (!crx_loader->success()) { |
535 SetStatus(STATUS_ERROR); | 717 SetStatus(STATUS_ERROR); |
536 return; | 718 return; |
537 } | 719 } |
538 | 720 |
539 SkBitmap icon = crx_loader->icon(); | 721 SkBitmap icon = crx_loader->icon(); |
540 if (icon.empty()) | 722 if (icon.empty()) |
541 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 723 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
542 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); | 724 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); |
543 | 725 |
544 SetStatus(STATUS_LOADED); | 726 SetStatus(STATUS_LOADED); |
545 } | 727 } |
546 | 728 |
547 } // namespace chromeos | 729 } // namespace chromeos |
OLD | NEW |