Chromium Code Reviews| 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"; | |
| 49 const char kKeyIcon[] = "icon"; | |
| 50 const char kKeyRequiredPlatformVersion[] = "required_platform_version"; | 47 const char kKeyRequiredPlatformVersion[] = "required_platform_version"; |
|
Luis Héctor Chávez
2017/03/30 16:49:54
nit: constexpr
Sergey Poromov
2017/03/30 18:22:06
Done.
| |
| 51 | 48 |
| 52 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; | 49 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; |
| 53 | 50 |
| 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 | |
| 72 // Returns true for valid kiosk app manifest. | 51 // Returns true for valid kiosk app manifest. |
| 73 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { | 52 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { |
| 74 bool kiosk_enabled; | 53 bool kiosk_enabled; |
| 75 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, | 54 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, |
| 76 &kiosk_enabled)) { | 55 &kiosk_enabled)) { |
| 77 return kiosk_enabled; | 56 return kiosk_enabled; |
| 78 } | 57 } |
| 79 | 58 |
| 80 return false; | 59 return false; |
| 81 } | 60 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 175 |
| 197 // Extracted meta data. | 176 // Extracted meta data. |
| 198 std::string name_; | 177 std::string name_; |
| 199 SkBitmap icon_; | 178 SkBitmap icon_; |
| 200 std::string required_platform_version_; | 179 std::string required_platform_version_; |
| 201 | 180 |
| 202 DISALLOW_COPY_AND_ASSIGN(CrxLoader); | 181 DISALLOW_COPY_AND_ASSIGN(CrxLoader); |
| 203 }; | 182 }; |
| 204 | 183 |
| 205 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 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 | 185 // KioskAppData::WebstoreDataParser |
| 320 // Use WebstoreInstallHelper to parse the manifest and decode the icon. | 186 // Use WebstoreInstallHelper to parse the manifest and decode the icon. |
| 321 | 187 |
| 322 class KioskAppData::WebstoreDataParser | 188 class KioskAppData::WebstoreDataParser |
| 323 : public extensions::WebstoreInstallHelper::Delegate { | 189 : public extensions::WebstoreInstallHelper::Delegate { |
| 324 public: | 190 public: |
| 325 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) | 191 explicit WebstoreDataParser(const base::WeakPtr<KioskAppData>& client) |
| 326 : client_(client) {} | 192 : client_(client) {} |
| 327 | 193 |
| 328 void Start(const std::string& app_id, | 194 void Start(const std::string& app_id, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 }; | 258 }; |
| 393 | 259 |
| 394 //////////////////////////////////////////////////////////////////////////////// | 260 //////////////////////////////////////////////////////////////////////////////// |
| 395 // KioskAppData | 261 // KioskAppData |
| 396 | 262 |
| 397 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, | 263 KioskAppData::KioskAppData(KioskAppDataDelegate* delegate, |
| 398 const std::string& app_id, | 264 const std::string& app_id, |
| 399 const AccountId& account_id, | 265 const AccountId& account_id, |
| 400 const GURL& update_url, | 266 const GURL& update_url, |
| 401 const base::FilePath& cached_crx) | 267 const base::FilePath& cached_crx) |
| 402 : delegate_(delegate), | 268 : KioskAppDataBase(app_id, account_id), |
| 269 delegate_(delegate), | |
| 403 status_(STATUS_INIT), | 270 status_(STATUS_INIT), |
| 404 app_id_(app_id), | |
| 405 account_id_(account_id), | |
| 406 update_url_(update_url), | 271 update_url_(update_url), |
| 407 crx_file_(cached_crx) {} | 272 crx_file_(cached_crx) {} |
| 408 | 273 |
| 409 KioskAppData::~KioskAppData() {} | 274 KioskAppData::~KioskAppData() {} |
| 410 | 275 |
| 411 void KioskAppData::Load() { | 276 void KioskAppData::Load() { |
| 412 SetStatus(STATUS_LOADING); | 277 SetStatus(STATUS_LOADING); |
| 413 | 278 |
| 414 if (LoadFromCache()) | 279 if (LoadFromCache()) |
| 415 return; | 280 return; |
| 416 | 281 |
| 417 StartFetch(); | 282 StartFetch(); |
| 418 } | 283 } |
| 419 | 284 |
| 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, | 285 void KioskAppData::LoadFromInstalledApp(Profile* profile, |
| 438 const extensions::Extension* app) { | 286 const extensions::Extension* app) { |
| 439 SetStatus(STATUS_LOADING); | 287 SetStatus(STATUS_LOADING); |
| 440 | 288 |
| 441 if (!app) { | 289 if (!app) { |
| 442 app = extensions::ExtensionSystem::Get(profile) | 290 app = extensions::ExtensionSystem::Get(profile) |
| 443 ->extension_service() | 291 ->extension_service() |
| 444 ->GetInstalledExtension(app_id_); | 292 ->GetInstalledExtension(app_id_); |
| 445 } | 293 } |
| 446 | 294 |
| 447 DCHECK_EQ(app_id_, app->id()); | 295 DCHECK_EQ(app_id_, app->id()); |
| 448 | 296 |
| 449 name_ = app->name(); | 297 name_ = app->name(); |
| 450 required_platform_version_ = | 298 required_platform_version_ = |
| 451 extensions::KioskModeInfo::Get(app)->required_platform_version; | 299 extensions::KioskModeInfo::Get(app)->required_platform_version; |
| 452 | 300 |
| 453 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; | 301 const int kIconSize = extension_misc::EXTENSION_ICON_LARGE; |
| 454 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 302 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
| 455 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); | 303 app, kIconSize, ExtensionIconSet::MATCH_BIGGER); |
| 456 extensions::ImageLoader::Get(profile)->LoadImageAsync( | 304 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
| 457 app, image, gfx::Size(kIconSize, kIconSize), | 305 app, image, gfx::Size(kIconSize, kIconSize), |
| 458 base::Bind(&KioskAppData::OnExtensionIconLoaded, AsWeakPtr())); | 306 base::Bind(&KioskAppData::OnExtensionIconLoaded, |
| 307 base::SupportsWeakPtr<KioskAppData>::AsWeakPtr())); | |
| 459 } | 308 } |
| 460 | 309 |
| 461 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { | 310 void KioskAppData::SetCachedCrx(const base::FilePath& crx_file) { |
| 462 if (crx_file_ == crx_file) | 311 if (crx_file_ == crx_file) |
| 463 return; | 312 return; |
| 464 | 313 |
| 465 crx_file_ = crx_file; | 314 crx_file_ = crx_file; |
| 466 LoadFromCrx(); | 315 LoadFromCrx(); |
| 467 } | 316 } |
| 468 | 317 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 delegate_->OnKioskAppDataLoadFailure(app_id_); | 362 delegate_->OnKioskAppDataLoadFailure(app_id_); |
| 514 break; | 363 break; |
| 515 } | 364 } |
| 516 } | 365 } |
| 517 | 366 |
| 518 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { | 367 net::URLRequestContextGetter* KioskAppData::GetRequestContextGetter() { |
| 519 return g_browser_process->system_request_context(); | 368 return g_browser_process->system_request_context(); |
| 520 } | 369 } |
| 521 | 370 |
| 522 bool KioskAppData::LoadFromCache() { | 371 bool KioskAppData::LoadFromCache() { |
| 523 const std::string app_key = | 372 PrefService* local_state = g_browser_process->local_state(); |
| 524 std::string(KioskAppManager::kKeyApps) + '.' + app_id_; | 373 const base::DictionaryValue* dict = |
| 525 const std::string name_key = app_key + '.' + kKeyName; | 374 local_state->GetDictionary(kiosk_dictionary_name()); |
| 526 const std::string icon_path_key = app_key + '.' + kKeyIcon; | 375 |
| 376 if (!LoadFromDictionary(dict)) | |
| 377 return false; | |
| 378 | |
| 379 const std::string app_key = std::string(kKeyApps) + '.' + app_id_; | |
| 527 const std::string required_platform_version_key = | 380 const std::string required_platform_version_key = |
| 528 app_key + '.' + kKeyRequiredPlatformVersion; | 381 app_key + '.' + kKeyRequiredPlatformVersion; |
| 529 | 382 |
| 530 PrefService* local_state = g_browser_process->local_state(); | 383 return dict->GetString(required_platform_version_key, |
| 531 const base::DictionaryValue* dict = | 384 &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 } | 385 } |
| 571 | 386 |
| 572 void KioskAppData::SetCache(const std::string& name, | 387 void KioskAppData::SetCache(const std::string& name, |
| 573 const SkBitmap& icon, | 388 const SkBitmap& icon, |
| 574 const std::string& required_platform_version) { | 389 const std::string& required_platform_version) { |
| 390 name_ = name; | |
| 391 required_platform_version_ = required_platform_version; | |
| 575 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); | 392 icon_ = gfx::ImageSkia::CreateFrom1xBitmap(icon); |
| 576 icon_.MakeThreadSafe(); | 393 icon_.MakeThreadSafe(); |
| 577 | 394 |
| 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; | 395 base::FilePath cache_dir; |
| 584 if (delegate_) | 396 if (delegate_) |
| 585 delegate_->GetKioskAppIconCacheDir(&cache_dir); | 397 delegate_->GetKioskAppIconCacheDir(&cache_dir); |
| 586 | 398 |
| 587 base::FilePath icon_path = | 399 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 | 400 |
| 593 SetCache(name, icon_path, required_platform_version); | 401 PrefService* local_state = g_browser_process->local_state(); |
| 402 DictionaryPrefUpdate dict_update(local_state, kiosk_dictionary_name()); | |
| 403 SaveToDictionary(dict_update); | |
| 404 | |
| 405 const std::string app_key = std::string(kKeyApps) + '.' + app_id_; | |
| 406 const std::string required_platform_version_key = | |
| 407 app_key + '.' + kKeyRequiredPlatformVersion; | |
| 408 | |
| 409 dict_update->SetString(required_platform_version_key, | |
| 410 required_platform_version); | |
| 411 } | |
| 412 | |
| 413 const char* KioskAppData::kiosk_dictionary_name() const { | |
| 414 return KioskAppManager::kKioskDictionaryName; | |
| 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_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 GURL icon_url = | 488 GURL icon_url = |
| 668 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); | 489 extension_urls::GetWebstoreLaunchURL().Resolve(icon_url_string); |
| 669 if (!icon_url.is_valid()) { | 490 if (!icon_url.is_valid()) { |
| 670 LOG(ERROR) << "Webstore response error (icon url): " | 491 LOG(ERROR) << "Webstore response error (icon url): " |
| 671 << ValueToString(*webstore_data); | 492 << ValueToString(*webstore_data); |
| 672 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 493 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
| 673 return; | 494 return; |
| 674 } | 495 } |
| 675 | 496 |
| 676 // WebstoreDataParser deletes itself when done. | 497 // WebstoreDataParser deletes itself when done. |
| 677 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, | 498 (new WebstoreDataParser(base::SupportsWeakPtr<KioskAppData>::AsWeakPtr())) |
| 678 manifest, | 499 ->Start(app_id_, manifest, icon_url, GetRequestContextGetter()); |
| 679 icon_url, | |
| 680 GetRequestContextGetter()); | |
| 681 } | 500 } |
| 682 | 501 |
| 683 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { | 502 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { |
| 684 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ | 503 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ |
| 685 << ", " << error; | 504 << ", " << error; |
| 686 webstore_fetcher_.reset(); | 505 webstore_fetcher_.reset(); |
| 687 SetStatus(STATUS_ERROR); | 506 SetStatus(STATUS_ERROR); |
| 688 } | 507 } |
| 689 | 508 |
| 690 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, | 509 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, |
| 691 const char* key, | 510 const char* key, |
| 692 std::string* value) { | 511 std::string* value) { |
| 693 if (!response->GetString(key, value)) { | 512 if (!response->GetString(key, value)) { |
| 694 LOG(ERROR) << "Webstore response error (" << key | 513 LOG(ERROR) << "Webstore response error (" << key |
| 695 << "): " << ValueToString(*response); | 514 << "): " << ValueToString(*response); |
| 696 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 515 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
| 697 return false; | 516 return false; |
| 698 } | 517 } |
| 699 return true; | 518 return true; |
| 700 } | 519 } |
| 701 | 520 |
| 702 void KioskAppData::LoadFromCrx() { | 521 void KioskAppData::LoadFromCrx() { |
| 703 if (crx_file_.empty()) | 522 if (crx_file_.empty()) |
| 704 return; | 523 return; |
| 705 | 524 |
| 706 scoped_refptr<CrxLoader> crx_loader(new CrxLoader(AsWeakPtr(), crx_file_)); | 525 scoped_refptr<CrxLoader> crx_loader(new CrxLoader( |
| 526 base::SupportsWeakPtr<KioskAppData>::AsWeakPtr(), crx_file_)); | |
| 707 crx_loader->Start(); | 527 crx_loader->Start(); |
| 708 } | 528 } |
| 709 | 529 |
| 710 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { | 530 void KioskAppData::OnCrxLoadFinished(const CrxLoader* crx_loader) { |
| 711 DCHECK(crx_loader); | 531 DCHECK(crx_loader); |
| 712 | 532 |
| 713 if (crx_loader->crx_file() != crx_file_) | 533 if (crx_loader->crx_file() != crx_file_) |
| 714 return; | 534 return; |
| 715 | 535 |
| 716 if (!crx_loader->success()) { | 536 if (!crx_loader->success()) { |
| 717 SetStatus(STATUS_ERROR); | 537 SetStatus(STATUS_ERROR); |
| 718 return; | 538 return; |
| 719 } | 539 } |
| 720 | 540 |
| 721 SkBitmap icon = crx_loader->icon(); | 541 SkBitmap icon = crx_loader->icon(); |
| 722 if (icon.empty()) | 542 if (icon.empty()) |
| 723 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 543 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
| 724 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); | 544 SetCache(crx_loader->name(), icon, crx_loader->required_platform_version()); |
| 725 | 545 |
| 726 SetStatus(STATUS_LOADED); | 546 SetStatus(STATUS_LOADED); |
| 727 } | 547 } |
| 728 | 548 |
| 729 } // namespace chromeos | 549 } // namespace chromeos |
| OLD | NEW |