kiosk_oem_manifest_parser.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chromeos/system/kiosk_oem_manifest_parser.h"
  5. #include <memory>
  6. #include "base/json/json_file_value_serializer.h"
  7. #include "base/values.h"
  8. namespace chromeos {
  9. namespace {
  10. const char kEnterpriseManaged[] = "enterprise_managed";
  11. const char kAllowReset[] = "can_exit_enrollment";
  12. const char kDeviceRequisition[] = "device_requisition";
  13. const char kKeyboardDrivenOobe[] = "keyboard_driven_oobe";
  14. } // namespace
  15. KioskOemManifestParser::Manifest::Manifest()
  16. : enterprise_managed(false),
  17. can_exit_enrollment(true),
  18. keyboard_driven_oobe(false) {}
  19. bool KioskOemManifestParser::Load(const base::FilePath& kiosk_oem_file,
  20. KioskOemManifestParser::Manifest* manifest) {
  21. int error_code = JSONFileValueDeserializer::JSON_NO_ERROR;
  22. std::string error_msg;
  23. std::unique_ptr<JSONFileValueDeserializer> deserializer(
  24. new JSONFileValueDeserializer(kiosk_oem_file));
  25. std::unique_ptr<base::Value> value =
  26. deserializer->Deserialize(&error_code, &error_msg);
  27. base::DictionaryValue* dict = NULL;
  28. if (error_code != JSONFileValueDeserializer::JSON_NO_ERROR || !value.get() ||
  29. !value->GetAsDictionary(&dict)) {
  30. return false;
  31. }
  32. dict->GetString(kDeviceRequisition, &manifest->device_requisition);
  33. if (absl::optional<bool> v = dict->FindBoolPath(kKeyboardDrivenOobe)) {
  34. manifest->keyboard_driven_oobe = *v;
  35. }
  36. if (absl::optional<bool> v = dict->FindBoolPath(kEnterpriseManaged)) {
  37. manifest->enterprise_managed = *v;
  38. } else {
  39. return false;
  40. }
  41. if (absl::optional<bool> v = dict->FindBoolPath(kAllowReset)) {
  42. manifest->can_exit_enrollment = *v;
  43. } else {
  44. return false;
  45. }
  46. return true;
  47. }
  48. } // namespace chromeos