Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: services/catalog/public/cpp/manifest_parsing_util.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Fix build. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/catalog/public/cpp/manifest_parsing_util.h ('k') | services/catalog/store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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
5 #include "services/catalog/public/cpp/manifest_parsing_util.h"
6
7 #include "base/values.h"
8 #include "services/catalog/store.h"
9
10 namespace catalog {
11
12 namespace {
13
14 bool IsValidPlatformName(const std::string& name) {
15 return name == Store::kRequiredFilesKey_PlatformValue_Windows ||
16 name == Store::kRequiredFilesKey_PlatformValue_Linux ||
17 name == Store::kRequiredFilesKey_PlatformValue_MacOSX ||
18 name == Store::kRequiredFilesKey_PlatformValue_Android;
19 }
20
21 bool IsCurrentPlatform(const std::string& name) {
22 #if defined(OS_WIN)
23 return name == Store::kRequiredFilesKey_PlatformValue_Windows;
24 #elif defined(OS_LINUX)
25 return name == Store::kRequiredFilesKey_PlatformValue_Linux;
26 #elif defined(OS_MACOSX)
27 return name == Store::kRequiredFilesKey_PlatformValue_MacOSX;
28 #elif defined(OS_ANDROID)
29 return name == Store::kRequiredFilesKey_PlatformValue_Android;
30 #else
31 #error This architecture is not supported.
32 #endif
33 }
34
35 } // namespace
36
37 base::Optional<RequiredFileMap> RetrieveRequiredFiles(
38 const base::Value& manifest_value) {
39 const base::DictionaryValue* manifest_dictionary = nullptr;
40 if (!manifest_value.GetAsDictionary(&manifest_dictionary)) {
41 DLOG(ERROR) << "Entry::Deserialize: manifest node is not a dictionary.";
42 return base::nullopt;
43 }
44
45 RequiredFileMap required_files;
46 if (!manifest_dictionary->HasKey(Store::kRequiredFilesKey))
47 return {required_files};
48
49 const base::DictionaryValue* required_files_value = nullptr;
50 if (!manifest_dictionary->GetDictionary(Store::kRequiredFilesKey,
51 &required_files_value)) {
52 DLOG(ERROR) << "Entry::Deserialize: RequiredFiles not a dictionary.";
53 return base::nullopt;
54 }
55
56 base::DictionaryValue::Iterator it(*required_files_value);
57 for (; !it.IsAtEnd(); it.Advance()) {
58 const std::string& entry_name = it.key();
59 const base::ListValue* all_platform_values = nullptr;
60 if (!it.value().GetAsList(&all_platform_values)) {
61 DLOG(ERROR) << "Entry::Deserialize: value of RequiredFiles for key: "
62 << entry_name << " not a list.";
63 return base::nullopt;
64 }
65
66 for (size_t i = 0; i < all_platform_values->GetSize(); i++) {
67 const base::DictionaryValue* file_descriptor_value = nullptr;
68 if (!all_platform_values->GetDictionary(i, &file_descriptor_value)) {
69 DLOG(ERROR) << "Entry::Deserialize: value of entry at index " << i
70 << " of RequiredFiles for key: " << entry_name
71 << " not a dictionary.";
72 return base::nullopt;
73 }
74 std::string platform;
75 if (file_descriptor_value->GetString(Store::kRequiredFilesKey_PlatformKey,
76 &platform)) {
77 if (!IsValidPlatformName(platform)) {
78 DLOG(ERROR) << "Entry::Deserialize: value of platform for "
79 << "required file entry entry is invalid " << platform;
80 return base::nullopt;
81 }
82 }
83 if (!IsCurrentPlatform(platform)) {
84 continue;
85 }
86 base::FilePath::StringType path;
87 if (!file_descriptor_value->GetString(Store::kRequiredFilesKey_PathKey,
88 &path)) {
89 DLOG(ERROR) << "Entry::Deserialize: value of RequiredFiles entry for "
90 << "key: " << entry_name
91 << " missing: " << Store::kRequiredFilesKey_PathKey
92 << " value.";
93 return base::nullopt;
94 }
95 if (required_files.count(entry_name) > 0) {
96 DLOG(ERROR) << "Entry::Deserialize: value of RequiredFiles entry for "
97 << "key: " << entry_name << " has more than one value for "
98 << "platform: " << platform;
99 return base::nullopt;
100 }
101 required_files[entry_name] = base::FilePath(path);
102 }
103 }
104 return base::make_optional(std::move(required_files));
105 }
106
107 } // namespace content
OLDNEW
« no previous file with comments | « services/catalog/public/cpp/manifest_parsing_util.h ('k') | services/catalog/store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698