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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/json/json_writer.h" |
11 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h" | 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_data_delegate.h" |
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
18 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 19 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
19 #include "chrome/browser/extensions/webstore_install_helper.h" | 20 #include "chrome/browser/extensions/webstore_install_helper.h" |
20 #include "chrome/browser/image_decoder.h" | 21 #include "chrome/browser/image_decoder.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { | 65 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { |
65 bool kiosk_enabled; | 66 bool kiosk_enabled; |
66 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, | 67 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, |
67 &kiosk_enabled)) { | 68 &kiosk_enabled)) { |
68 return kiosk_enabled; | 69 return kiosk_enabled; |
69 } | 70 } |
70 | 71 |
71 return false; | 72 return false; |
72 } | 73 } |
73 | 74 |
| 75 std::string ValueToString(const base::Value* value) { |
| 76 std::string json; |
| 77 base::JSONWriter::Write(value, &json); |
| 78 return json; |
| 79 } |
| 80 |
74 } // namespace | 81 } // namespace |
75 | 82 |
76 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
77 // KioskAppData::IconLoader | 84 // KioskAppData::IconLoader |
78 // Loads locally stored icon data and decode it. | 85 // Loads locally stored icon data and decode it. |
79 | 86 |
80 class KioskAppData::IconLoader : public ImageDecoder::Delegate { | 87 class KioskAppData::IconLoader : public ImageDecoder::Delegate { |
81 public: | 88 public: |
82 enum LoadResult { | 89 enum LoadResult { |
83 SUCCESS, | 90 SUCCESS, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 409 } |
403 | 410 |
404 void KioskAppData::OnWebstoreResponseParseSuccess( | 411 void KioskAppData::OnWebstoreResponseParseSuccess( |
405 base::DictionaryValue* webstore_data) { | 412 base::DictionaryValue* webstore_data) { |
406 // Takes ownership of |webstore_data|. | 413 // Takes ownership of |webstore_data|. |
407 scoped_ptr<base::DictionaryValue> data(webstore_data); | 414 scoped_ptr<base::DictionaryValue> data(webstore_data); |
408 | 415 |
409 webstore_fetcher_.reset(); | 416 webstore_fetcher_.reset(); |
410 | 417 |
411 std::string manifest; | 418 std::string manifest; |
412 if (!webstore_data->GetString(kManifestKey, &manifest)) { | 419 if (!CheckResponseKeyValue(data.get(), kManifestKey, &manifest)) |
| 420 return; |
| 421 |
| 422 if (!CheckResponseKeyValue(data.get(), kLocalizedNameKey, &name_)) |
| 423 return; |
| 424 |
| 425 std::string icon_url_string; |
| 426 if (!CheckResponseKeyValue(data.get(), kIconUrlKey, &icon_url_string)) |
| 427 return; |
| 428 |
| 429 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( |
| 430 icon_url_string); |
| 431 if (!icon_url.is_valid()) { |
| 432 LOG(ERROR) << "Webstore response error (icon url): " |
| 433 << ValueToString(data.get()); |
413 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 434 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
414 return; | 435 return; |
415 } | 436 } |
416 | |
417 if (!webstore_data->GetString(kLocalizedNameKey, &name_)) { | |
418 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | |
419 return; | |
420 } | |
421 | |
422 std::string icon_url_string; | |
423 if (!webstore_data->GetString(kIconUrlKey, &icon_url_string)) { | |
424 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | |
425 return; | |
426 } | |
427 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( | |
428 icon_url_string); | |
429 if (!icon_url.is_valid()) { | |
430 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | |
431 return; | |
432 } | |
433 | 437 |
434 // WebstoreDataParser deletes itself when done. | 438 // WebstoreDataParser deletes itself when done. |
435 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, | 439 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, |
436 manifest, | 440 manifest, |
437 icon_url, | 441 icon_url, |
438 GetRequestContextGetter()); | 442 GetRequestContextGetter()); |
439 } | 443 } |
440 | 444 |
441 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { | 445 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { |
| 446 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ |
| 447 << ", " << error; |
442 webstore_fetcher_.reset(); | 448 webstore_fetcher_.reset(); |
443 SetStatus(STATUS_ERROR); | 449 SetStatus(STATUS_ERROR); |
444 } | 450 } |
445 | 451 |
| 452 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, |
| 453 const char* key, |
| 454 std::string* value) { |
| 455 if (!response->GetString(key, value)) { |
| 456 LOG(ERROR) << "Webstore response error (" << key |
| 457 << "): " << ValueToString(response); |
| 458 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
| 459 return false; |
| 460 } |
| 461 return true; |
| 462 } |
| 463 |
446 } // namespace chromeos | 464 } // namespace chromeos |
OLD | NEW |