| OLD | NEW |
| 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/catalog.h" | 5 #include "services/catalog/catalog.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "mojo/common/url_type_converters.h" | 13 #include "mojo/common/url_type_converters.h" |
| 14 #include "services/catalog/entry.h" | 14 #include "services/catalog/entry.h" |
| 15 #include "services/catalog/manifest_provider.h" | 15 #include "services/catalog/manifest_provider.h" |
| 16 #include "services/catalog/store.h" | 16 #include "services/catalog/store.h" |
| 17 #include "services/shell/public/cpp/names.h" | 17 #include "services/shell/public/cpp/names.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 #include "url/url_util.h" | 19 #include "url/url_util.h" |
| 20 | 20 |
| 21 namespace catalog { | 21 namespace catalog { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 base::FilePath GetManifestPath(const base::FilePath& package_dir, | 24 base::FilePath GetManifestPath(const base::FilePath& package_dir, |
| 25 const std::string& name) { | 25 const std::string& name) { |
| 26 // TODO(beng): think more about how this should be done for exe targets. | 26 // TODO(beng): think more about how this should be done for exe targets. |
| 27 std::string type = mojo::GetNameType(name); | 27 std::string type = shell::GetNameType(name); |
| 28 std::string path = mojo::GetNamePath(name); | 28 std::string path = shell::GetNamePath(name); |
| 29 if (type == mojo::kNameType_Mojo) { | 29 if (type == shell::kNameType_Mojo) { |
| 30 return package_dir.AppendASCII("Mojo Applications").AppendASCII( | 30 return package_dir.AppendASCII("Mojo Applications").AppendASCII( |
| 31 path + "/manifest.json"); | 31 path + "/manifest.json"); |
| 32 } | 32 } |
| 33 if (type == mojo::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 base::FilePath GetPackagePath(const base::FilePath& package_dir, | 38 base::FilePath GetPackagePath(const base::FilePath& package_dir, |
| 39 const std::string& name) { | 39 const std::string& name) { |
| 40 std::string type = mojo::GetNameType(name); | 40 std::string type = shell::GetNameType(name); |
| 41 if (type == mojo::kNameType_Mojo) { | 41 if (type == shell::kNameType_Mojo) { |
| 42 // It's still a mojo: URL, use the default mapping scheme. | 42 // It's still a mojo: URL, use the default mapping scheme. |
| 43 const std::string host = mojo::GetNamePath(name); | 43 const std::string host = shell::GetNamePath(name); |
| 44 return package_dir.AppendASCII("Mojo Applications").AppendASCII( | 44 return package_dir.AppendASCII("Mojo Applications").AppendASCII( |
| 45 host + "/" + host + ".mojo"); | 45 host + "/" + host + ".mojo"); |
| 46 } | 46 } |
| 47 if (type == mojo::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(mojo::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 scoped_ptr<ReadManifestResult> ProcessManifest( | 58 scoped_ptr<ReadManifestResult> ProcessManifest( |
| 59 const base::FilePath& user_package_dir, | 59 const base::FilePath& user_package_dir, |
| 60 const base::FilePath& system_package_dir, | 60 const base::FilePath& system_package_dir, |
| 61 const std::string& name, | 61 const std::string& name, |
| 62 scoped_ptr<base::Value> manifest_root) { | 62 scoped_ptr<base::Value> manifest_root) { |
| 63 scoped_ptr<Entry> entry(new Entry(name)); | 63 scoped_ptr<Entry> entry(new Entry(name)); |
| 64 if (manifest_root) { | 64 if (manifest_root) { |
| 65 const base::DictionaryValue* dictionary = nullptr; | 65 const base::DictionaryValue* dictionary = nullptr; |
| 66 CHECK(manifest_root->GetAsDictionary(&dictionary)); | 66 CHECK(manifest_root->GetAsDictionary(&dictionary)); |
| 67 entry = Entry::Deserialize(*dictionary); | 67 entry = Entry::Deserialize(*dictionary); |
| 68 } | 68 } |
| 69 entry->set_path(GetPackagePath(system_package_dir, name)); | 69 entry->set_path(GetPackagePath(system_package_dir, name)); |
| 70 | 70 |
| 71 scoped_ptr<ReadManifestResult> result(new ReadManifestResult); | 71 scoped_ptr<ReadManifestResult> result(new ReadManifestResult); |
| 72 // NOTE: This TypeConverter must run on a thread which allows IO. | 72 // NOTE: This TypeConverter must run on a thread which allows IO. |
| 73 result->resolve_result = mojo::shell::mojom::ResolveResult::From(*entry); | 73 result->resolve_result = shell::mojom::ResolveResult::From(*entry); |
| 74 result->catalog_entry = std::move(entry); | 74 result->catalog_entry = std::move(entry); |
| 75 result->package_dir = system_package_dir; | 75 result->package_dir = system_package_dir; |
| 76 return result; | 76 return result; |
| 77 } | 77 } |
| 78 | 78 |
| 79 scoped_ptr<ReadManifestResult> ReadManifest( | 79 scoped_ptr<ReadManifestResult> ReadManifest( |
| 80 const base::FilePath& user_package_dir, | 80 const base::FilePath& user_package_dir, |
| 81 const base::FilePath& system_package_dir, | 81 const base::FilePath& system_package_dir, |
| 82 const std::string& name) { | 82 const std::string& name) { |
| 83 base::FilePath manifest_path = GetManifestPath(system_package_dir, name); | 83 base::FilePath manifest_path = GetManifestPath(system_package_dir, name); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 PathService::Get(base::DIR_MODULE, &system_package_dir_); | 118 PathService::Get(base::DIR_MODULE, &system_package_dir_); |
| 119 DeserializeCatalog(); | 119 DeserializeCatalog(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 Catalog::~Catalog() {} | 122 Catalog::~Catalog() {} |
| 123 | 123 |
| 124 void Catalog::BindResolver(mojom::ResolverRequest request) { | 124 void Catalog::BindResolver(mojom::ResolverRequest request) { |
| 125 resolver_bindings_.AddBinding(this, std::move(request)); | 125 resolver_bindings_.AddBinding(this, std::move(request)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void Catalog::BindShellResolver( | 128 void Catalog::BindShellResolver(shell::mojom::ShellResolverRequest request) { |
| 129 mojo::shell::mojom::ShellResolverRequest request) { | |
| 130 shell_resolver_bindings_.AddBinding(this, std::move(request)); | 129 shell_resolver_bindings_.AddBinding(this, std::move(request)); |
| 131 } | 130 } |
| 132 | 131 |
| 133 void Catalog::BindCatalog(mojom::CatalogRequest request) { | 132 void Catalog::BindCatalog(mojom::CatalogRequest request) { |
| 134 catalog_bindings_.AddBinding(this, std::move(request)); | 133 catalog_bindings_.AddBinding(this, std::move(request)); |
| 135 } | 134 } |
| 136 | 135 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 136 //////////////////////////////////////////////////////////////////////////////// |
| 138 // Catalog, mojom::Resolver: | 137 // Catalog, mojom::Resolver: |
| 139 | 138 |
| 140 void Catalog::ResolveInterfaces(mojo::Array<mojo::String> interfaces, | 139 void Catalog::ResolveInterfaces(mojo::Array<mojo::String> interfaces, |
| 141 const ResolveInterfacesCallback& callback) { | 140 const ResolveInterfacesCallback& callback) { |
| 142 // TODO(beng): implement. | 141 // TODO(beng): implement. |
| 143 } | 142 } |
| 144 | 143 |
| 145 void Catalog::ResolveMIMEType(const mojo::String& mime_type, | 144 void Catalog::ResolveMIMEType(const mojo::String& mime_type, |
| 146 const ResolveMIMETypeCallback& callback) { | 145 const ResolveMIMETypeCallback& callback) { |
| 147 // TODO(beng): implement. | 146 // TODO(beng): implement. |
| 148 } | 147 } |
| 149 | 148 |
| 150 void Catalog::ResolveProtocolScheme( | 149 void Catalog::ResolveProtocolScheme( |
| 151 const mojo::String& scheme, | 150 const mojo::String& scheme, |
| 152 const ResolveProtocolSchemeCallback& callback) { | 151 const ResolveProtocolSchemeCallback& callback) { |
| 153 // TODO(beng): implement. | 152 // TODO(beng): implement. |
| 154 } | 153 } |
| 155 | 154 |
| 156 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
| 157 // Catalog, mojo::shell::mojom::ShellResolver: | 156 // Catalog, shell::mojom::ShellResolver: |
| 158 | 157 |
| 159 void Catalog::ResolveMojoName(const mojo::String& mojo_name, | 158 void Catalog::ResolveMojoName(const mojo::String& mojo_name, |
| 160 const ResolveMojoNameCallback& callback) { | 159 const ResolveMojoNameCallback& callback) { |
| 161 std::string type = mojo::GetNameType(mojo_name); | 160 std::string type = shell::GetNameType(mojo_name); |
| 162 if (type != "mojo" && type != "exe") { | 161 if (type != "mojo" && type != "exe") { |
| 163 scoped_ptr<Entry> entry(new Entry(mojo_name)); | 162 scoped_ptr<Entry> entry(new Entry(mojo_name)); |
| 164 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry)); | 163 callback.Run(shell::mojom::ResolveResult::From(*entry)); |
| 165 return; | 164 return; |
| 166 } | 165 } |
| 167 | 166 |
| 168 auto entry = user_catalog_.find(mojo_name); | 167 auto entry = user_catalog_.find(mojo_name); |
| 169 if (entry != user_catalog_.end()) { | 168 if (entry != user_catalog_.end()) { |
| 170 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry->second)); | 169 callback.Run(shell::mojom::ResolveResult::From(*entry->second)); |
| 171 return; | 170 return; |
| 172 } | 171 } |
| 173 entry = system_catalog_->find(mojo_name); | 172 entry = system_catalog_->find(mojo_name); |
| 174 if (entry != system_catalog_->end()) { | 173 if (entry != system_catalog_->end()) { |
| 175 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry->second)); | 174 callback.Run(shell::mojom::ResolveResult::From(*entry->second)); |
| 176 return; | 175 return; |
| 177 } | 176 } |
| 178 | 177 |
| 179 std::string manifest_contents; | 178 std::string manifest_contents; |
| 180 if (manifest_provider_ && | 179 if (manifest_provider_ && |
| 181 manifest_provider_->GetApplicationManifest(mojo_name.To<std::string>(), | 180 manifest_provider_->GetApplicationManifest(mojo_name.To<std::string>(), |
| 182 &manifest_contents)) { | 181 &manifest_contents)) { |
| 183 scoped_ptr<base::Value> manifest_root = | 182 scoped_ptr<base::Value> manifest_root = |
| 184 base::JSONReader::Read(manifest_contents); | 183 base::JSONReader::Read(manifest_contents); |
| 185 base::PostTaskAndReplyWithResult( | 184 base::PostTaskAndReplyWithResult( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 EntryCache* catalog = is_system_catalog ? system_catalog_ : &user_catalog_; | 272 EntryCache* catalog = is_system_catalog ? system_catalog_ : &user_catalog_; |
| 274 if (catalog->end() != catalog->find(entry->name())) | 273 if (catalog->end() != catalog->find(entry->name())) |
| 275 return; | 274 return; |
| 276 for (auto child : entry->applications()) | 275 for (auto child : entry->applications()) |
| 277 AddEntryToCatalog(make_scoped_ptr(child), is_system_catalog); | 276 AddEntryToCatalog(make_scoped_ptr(child), is_system_catalog); |
| 278 (*catalog)[entry->name()] = std::move(entry); | 277 (*catalog)[entry->name()] = std::move(entry); |
| 279 SerializeCatalog(); | 278 SerializeCatalog(); |
| 280 } | 279 } |
| 281 | 280 |
| 282 } // namespace catalog | 281 } // namespace catalog |
| OLD | NEW |