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

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: Removed unused method in apk_assets 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
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 bool PopulateRequiredFiles(const base::Value& manifest_value,
dcheng 2017/02/15 08:05:27 Would it make sense to return a base::Optional<Req
Jay Civelli 2017/02/15 19:53:48 Good idea. (I didn't know about Optional)
38 RequiredFileMap* required_files) {
39 const base::DictionaryValue* manifest_dictionary = nullptr;
40 if (!manifest_value.GetAsDictionary(&manifest_dictionary)) {
41 LOG(ERROR) << "Entry::Deserialize: manifest node is not a dictionary.";
42 return false;
43 }
44
45 if (!manifest_dictionary->HasKey(Store::kRequiredFilesKey))
46 return true;
47
48 const base::DictionaryValue* required_files_value = nullptr;
49 if (!manifest_dictionary->GetDictionary(Store::kRequiredFilesKey,
50 &required_files_value)) {
51 LOG(ERROR) << "Entry::Deserialize: RequiredFiles not a dictionary.";
52 return false;
53 }
54
55 base::DictionaryValue::Iterator it(*required_files_value);
56 for (; !it.IsAtEnd(); it.Advance()) {
57 const std::string& entry_name = it.key();
58 const base::ListValue* all_platform_values = nullptr;
59 if (!it.value().GetAsList(&all_platform_values)) {
60 LOG(ERROR) << "Entry::Deserialize: value of RequiredFiles for key: "
61 << entry_name << " not a list.";
62 return false;
63 }
64
65 for (size_t i = 0; i < all_platform_values->GetSize(); i++) {
dcheng 2017/02/15 08:05:28 It's possible to use range-based for loops with ba
Jay Civelli 2017/02/15 19:53:48 But then I'd lose the index value which I use in t
66 const base::DictionaryValue* file_descriptor_value = nullptr;
67 if (!all_platform_values->GetDictionary(i, &file_descriptor_value)) {
68 LOG(ERROR) << "Entry::Deserialize: value of entry at index " << i
69 << " of RequiredFiles for key: " << entry_name
70 << " not a dictionary.";
71 return false;
72 }
73 std::string platform;
74 if (file_descriptor_value->GetString(Store::kRequiredFilesKey_PlatformKey,
75 &platform)) {
76 if (!IsValidPlatformName(platform)) {
77 LOG(ERROR) << "Entry::Deserialize: value of platform for "
78 << "required file entry entry is invalid " << platform;
79 return false;
80 }
81 }
82 if (!IsCurrentPlatform(platform)) {
83 continue;
84 }
85 std::string path;
86 if (!file_descriptor_value->GetString(Store::kRequiredFilesKey_PathKey,
87 &path)) {
88 LOG(ERROR) << "Entry::Deserialize: value of RequiredFiles entry for "
89 << "key: " << entry_name
90 << " missing: " << Store::kRequiredFilesKey_PathKey
91 << " value.";
92 return false;
93 }
94 if (required_files->count(entry_name) > 0) {
95 LOG(ERROR) << "Entry::Deserialize: value of RequiredFiles entry for "
96 << "key: " << entry_name << " has more than one value for "
97 << "platform: " << platform;
98 return false;
99 }
100 (*required_files)[entry_name] = path;
101 }
102 }
103 return true;
104 }
105
106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698