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

Side by Side Diff: services/catalog/reader.cc

Issue 2164503006: Rename mojo_application GN templates to service* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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/entry.cc ('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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/catalog/reader.h" 5 #include "services/catalog/reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_enumerator.h" 8 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
(...skipping 18 matching lines...) Expand all
29 if (type == shell::kNameType_Mojo) { 29 if (type == shell::kNameType_Mojo) {
30 return package_dir.AppendASCII(kMojoApplicationsDirName).AppendASCII( 30 return package_dir.AppendASCII(kMojoApplicationsDirName).AppendASCII(
31 path + "/manifest.json"); 31 path + "/manifest.json");
32 } 32 }
33 if (type == shell::kNameType_Exe) 33 if (type == shell::kNameType_Exe)
34 return package_dir.AppendASCII(path + "_manifest.json"); 34 return package_dir.AppendASCII(path + "_manifest.json");
35 return base::FilePath(); 35 return base::FilePath();
36 } 36 }
37 37
38 38
39 base::FilePath GetPackagePath(const base::FilePath& package_dir, 39 base::FilePath GetExecutablePath(const base::FilePath& package_dir,
40 const std::string& name) { 40 const std::string& name) {
41 std::string type = shell::GetNameType(name); 41 std::string type = shell::GetNameType(name);
42 if (type == shell::kNameType_Mojo) { 42 if (type == shell::kNameType_Mojo) {
43 // It's still a mojo: URL, use the default mapping scheme. 43 // It's still a mojo: URL, use the default mapping scheme.
44 const std::string host = shell::GetNamePath(name); 44 const std::string host = shell::GetNamePath(name);
45 return package_dir.AppendASCII(host + "/" + host + ".mojo"); 45 return package_dir.AppendASCII(host + "/" + host + ".library");
46 } 46 }
47 if (type == shell::kNameType_Exe) { 47 if (type == shell::kNameType_Exe) {
48 #if defined OS_WIN 48 #if defined OS_WIN
49 std::string extension = ".exe"; 49 std::string extension = ".exe";
50 #else 50 #else
51 std::string extension; 51 std::string extension;
52 #endif 52 #endif
53 return package_dir.AppendASCII(shell::GetNamePath(name) + extension); 53 return package_dir.AppendASCII(shell::GetNamePath(name) + extension);
54 } 54 }
55 return base::FilePath(); 55 return base::FilePath();
56 } 56 }
57 57
58 std::unique_ptr<Entry> ProcessManifest( 58 std::unique_ptr<Entry> ProcessManifest(
59 std::unique_ptr<base::Value> manifest_root, 59 std::unique_ptr<base::Value> manifest_root,
60 const base::FilePath& package_dir) { 60 const base::FilePath& package_dir) {
61 // Manifest was malformed or did not exist. 61 // Manifest was malformed or did not exist.
62 if (!manifest_root) 62 if (!manifest_root)
63 return nullptr; 63 return nullptr;
64 64
65 const base::DictionaryValue* dictionary = nullptr; 65 const base::DictionaryValue* dictionary = nullptr;
66 if (!manifest_root->GetAsDictionary(&dictionary)) 66 if (!manifest_root->GetAsDictionary(&dictionary))
67 return nullptr; 67 return nullptr;
68 68
69 std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary); 69 std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary);
70 if (!entry) 70 if (!entry)
71 return nullptr; 71 return nullptr;
72 entry->set_path(GetPackagePath(package_dir, entry->name())); 72 entry->set_path(GetExecutablePath(package_dir, entry->name()));
73 return entry; 73 return entry;
74 } 74 }
75 75
76 std::unique_ptr<Entry> CreateEntryForManifestAt( 76 std::unique_ptr<Entry> CreateEntryForManifestAt(
77 const base::FilePath& manifest_path, 77 const base::FilePath& manifest_path,
78 const base::FilePath& package_dir) { 78 const base::FilePath& package_dir) {
79 JSONFileValueDeserializer deserializer(manifest_path); 79 JSONFileValueDeserializer deserializer(manifest_path);
80 int error = 0; 80 int error = 0;
81 std::string message; 81 std::string message;
82 82
(...skipping 16 matching lines...) Expand all
99 break; 99 break;
100 base::FilePath manifest_path = path.AppendASCII("manifest.json"); 100 base::FilePath manifest_path = path.AppendASCII("manifest.json");
101 std::unique_ptr<Entry> entry = 101 std::unique_ptr<Entry> entry =
102 CreateEntryForManifestAt(manifest_path, package_dir); 102 CreateEntryForManifestAt(manifest_path, package_dir);
103 if (!entry) 103 if (!entry)
104 continue; 104 continue;
105 105
106 // Skip over subdirs that contain only manifests, they're artifacts of the 106 // Skip over subdirs that contain only manifests, they're artifacts of the
107 // build (e.g. for applications that are packaged into others) and are not 107 // build (e.g. for applications that are packaged into others) and are not
108 // valid standalone packages. 108 // valid standalone packages.
109 base::FilePath package_path = GetPackagePath(package_dir, entry->name()); 109 base::FilePath package_path = GetExecutablePath(package_dir, entry->name());
110 if (entry->name() != "mojo:shell" && entry->name() != "mojo:catalog" && 110 if (entry->name() != "mojo:shell" && entry->name() != "mojo:catalog" &&
111 !base::PathExists(package_path)) { 111 !base::PathExists(package_path)) {
112 continue; 112 continue;
113 } 113 }
114 114
115 original_thread_task_runner->PostTask( 115 original_thread_task_runner->PostTask(
116 FROM_HERE, 116 FROM_HERE,
117 base::Bind(read_manifest_callback, base::Passed(&entry))); 117 base::Bind(read_manifest_callback, base::Passed(&entry)));
118 } 118 }
119 119
120 original_thread_task_runner->PostTask(FROM_HERE, read_complete_closure); 120 original_thread_task_runner->PostTask(FROM_HERE, read_complete_closure);
121 } 121 }
122 122
123 std::unique_ptr<Entry> ReadManifest(const base::FilePath& package_dir, 123 std::unique_ptr<Entry> ReadManifest(const base::FilePath& package_dir,
124 const std::string& mojo_name) { 124 const std::string& mojo_name) {
125 std::unique_ptr<Entry> entry = CreateEntryForManifestAt( 125 std::unique_ptr<Entry> entry = CreateEntryForManifestAt(
126 GetManifestPath(package_dir, mojo_name), package_dir); 126 GetManifestPath(package_dir, mojo_name), package_dir);
127 if (!entry) { 127 if (!entry) {
128 entry.reset(new Entry(mojo_name)); 128 entry.reset(new Entry(mojo_name));
129 entry->set_path(GetPackagePath( 129 entry->set_path(GetExecutablePath(
130 package_dir.AppendASCII(kMojoApplicationsDirName), mojo_name)); 130 package_dir.AppendASCII(kMojoApplicationsDirName), mojo_name));
131 } 131 }
132 return entry; 132 return entry;
133 } 133 }
134 134
135 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) { 135 void AddEntryToCache(EntryCache* cache, std::unique_ptr<Entry> entry) {
136 for (auto* child : entry->applications()) 136 for (auto* child : entry->services())
137 AddEntryToCache(cache, base::WrapUnique(child)); 137 AddEntryToCache(cache, base::WrapUnique(child));
138 (*cache)[entry->name()] = std::move(entry); 138 (*cache)[entry->name()] = std::move(entry);
139 } 139 }
140 140
141 void DoNothing(shell::mojom::ResolveResultPtr) {} 141 void DoNothing(shell::mojom::ResolveResultPtr) {}
142 142
143 } // namespace 143 } // namespace
144 144
145 // A sequenced task runner is used to guarantee requests are serviced in the 145 // A sequenced task runner is used to guarantee requests are serviced in the
146 // order requested. To do otherwise means we may run callbacks in an 146 // order requested. To do otherwise means we may run callbacks in an
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 EntryCache* cache, 207 EntryCache* cache,
208 const CreateEntryForNameCallback& entry_created_callback, 208 const CreateEntryForNameCallback& entry_created_callback,
209 std::unique_ptr<Entry> entry) { 209 std::unique_ptr<Entry> entry) {
210 shell::mojom::ResolveResultPtr result = 210 shell::mojom::ResolveResultPtr result =
211 shell::mojom::ResolveResult::From(*entry); 211 shell::mojom::ResolveResult::From(*entry);
212 AddEntryToCache(cache, std::move(entry)); 212 AddEntryToCache(cache, std::move(entry));
213 entry_created_callback.Run(std::move(result)); 213 entry_created_callback.Run(std::move(result));
214 } 214 }
215 215
216 } // namespace catalog 216 } // namespace catalog
OLDNEW
« no previous file with comments | « services/catalog/entry.cc ('k') | services/catalog/store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698