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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { | 69 bool IsValidKioskAppManifest(const extensions::Manifest& manifest) { |
70 bool kiosk_enabled; | 70 bool kiosk_enabled; |
71 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, | 71 if (manifest.GetBoolean(extensions::manifest_keys::kKioskEnabled, |
72 &kiosk_enabled)) { | 72 &kiosk_enabled)) { |
73 return kiosk_enabled; | 73 return kiosk_enabled; |
74 } | 74 } |
75 | 75 |
76 return false; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 std::string ValueToString(const base::Value* value) { | 79 std::string ValueToString(const base::Value& value) { |
80 std::string json; | 80 std::string json; |
81 base::JSONWriter::Write(value, &json); | 81 base::JSONWriter::Write(value, &json); |
82 return json; | 82 return json; |
83 } | 83 } |
84 | 84 |
85 } // namespace | 85 } // namespace |
86 | 86 |
87 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
88 // KioskAppData::CrxLoader | 88 // KioskAppData::CrxLoader |
89 // Loads meta data from crx file. | 89 // Loads meta data from crx file. |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 595 |
596 std::string icon_url_string; | 596 std::string icon_url_string; |
597 if (!CheckResponseKeyValue(webstore_data.get(), kIconUrlKey, | 597 if (!CheckResponseKeyValue(webstore_data.get(), kIconUrlKey, |
598 &icon_url_string)) | 598 &icon_url_string)) |
599 return; | 599 return; |
600 | 600 |
601 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( | 601 GURL icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( |
602 icon_url_string); | 602 icon_url_string); |
603 if (!icon_url.is_valid()) { | 603 if (!icon_url.is_valid()) { |
604 LOG(ERROR) << "Webstore response error (icon url): " | 604 LOG(ERROR) << "Webstore response error (icon url): " |
605 << ValueToString(webstore_data.get()); | 605 << ValueToString(*webstore_data); |
606 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 606 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
607 return; | 607 return; |
608 } | 608 } |
609 | 609 |
610 // WebstoreDataParser deletes itself when done. | 610 // WebstoreDataParser deletes itself when done. |
611 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, | 611 (new WebstoreDataParser(AsWeakPtr()))->Start(app_id_, |
612 manifest, | 612 manifest, |
613 icon_url, | 613 icon_url, |
614 GetRequestContextGetter()); | 614 GetRequestContextGetter()); |
615 } | 615 } |
616 | 616 |
617 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { | 617 void KioskAppData::OnWebstoreResponseParseFailure(const std::string& error) { |
618 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ | 618 LOG(ERROR) << "Webstore failed for kiosk app " << app_id_ |
619 << ", " << error; | 619 << ", " << error; |
620 webstore_fetcher_.reset(); | 620 webstore_fetcher_.reset(); |
621 SetStatus(STATUS_ERROR); | 621 SetStatus(STATUS_ERROR); |
622 } | 622 } |
623 | 623 |
624 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, | 624 bool KioskAppData::CheckResponseKeyValue(const base::DictionaryValue* response, |
625 const char* key, | 625 const char* key, |
626 std::string* value) { | 626 std::string* value) { |
627 if (!response->GetString(key, value)) { | 627 if (!response->GetString(key, value)) { |
628 LOG(ERROR) << "Webstore response error (" << key | 628 LOG(ERROR) << "Webstore response error (" << key |
629 << "): " << ValueToString(response); | 629 << "): " << ValueToString(*response); |
630 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); | 630 OnWebstoreResponseParseFailure(kInvalidWebstoreResponseError); |
631 return false; | 631 return false; |
632 } | 632 } |
633 return true; | 633 return true; |
634 } | 634 } |
635 | 635 |
636 void KioskAppData::MaybeLoadFromCrx() { | 636 void KioskAppData::MaybeLoadFromCrx() { |
637 if (status_ == STATUS_LOADED || crx_file_.empty()) | 637 if (status_ == STATUS_LOADED || crx_file_.empty()) |
638 return; | 638 return; |
639 | 639 |
(...skipping 14 matching lines...) Expand all Loading... |
654 | 654 |
655 SkBitmap icon = crx_loader->icon(); | 655 SkBitmap icon = crx_loader->icon(); |
656 if (icon.empty()) | 656 if (icon.empty()) |
657 icon = *extensions::util::GetDefaultAppIcon().bitmap(); | 657 icon = *extensions::util::GetDefaultAppIcon().bitmap(); |
658 SetCache(crx_loader->name(), icon); | 658 SetCache(crx_loader->name(), icon); |
659 | 659 |
660 SetStatus(STATUS_LOADED); | 660 SetStatus(STATUS_LOADED); |
661 } | 661 } |
662 | 662 |
663 } // namespace chromeos | 663 } // namespace chromeos |
OLD | NEW |