| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_CATALOG_READER_H_ | |
| 6 #define SERVICES_CATALOG_READER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "services/service_manager/public/interfaces/resolver.mojom.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class SequencedWorkerPool; | |
| 20 class SingleThreadTaskRunner; | |
| 21 class Value; | |
| 22 } | |
| 23 | |
| 24 namespace catalog { | |
| 25 | |
| 26 class Entry; | |
| 27 class EntryCache; | |
| 28 class ManifestProvider; | |
| 29 | |
| 30 // Responsible for loading manifests & building the Entry data structures. | |
| 31 class Reader { | |
| 32 public: | |
| 33 using ReadManifestCallback = base::Callback<void(std::unique_ptr<Entry>)>; | |
| 34 using CreateEntryForNameCallback = | |
| 35 service_manager::mojom::Resolver::ResolveServiceNameCallback; | |
| 36 | |
| 37 // Construct a Reader over a static manifest. This Reader never performs | |
| 38 // file I/O. | |
| 39 Reader(std::unique_ptr<base::Value> static_manifest, EntryCache* cache); | |
| 40 | |
| 41 Reader(base::SequencedWorkerPool* worker_pool, | |
| 42 ManifestProvider* manifest_provider); | |
| 43 Reader(base::SingleThreadTaskRunner* task_runner, | |
| 44 ManifestProvider* manifest_provider); | |
| 45 ~Reader(); | |
| 46 | |
| 47 // Scans the contents of |package_dir|, reading all application manifests and | |
| 48 // populating |cache|. Runs |read_complete_closure| when done. | |
| 49 void Read(const base::FilePath& package_dir, | |
| 50 EntryCache* cache, | |
| 51 const base::Closure& read_complete_closure); | |
| 52 | |
| 53 // Returns an Entry for |name| via |callback|, assuming a manifest file in the | |
| 54 // canonical location | |
| 55 void CreateEntryForName( | |
| 56 const std::string& name, | |
| 57 EntryCache* cache, | |
| 58 const CreateEntryForNameCallback& entry_created_callback); | |
| 59 | |
| 60 // Overrides the package name used for a specific service name. | |
| 61 void OverridePackageName(const std::string& service_name, | |
| 62 const std::string& package_name); | |
| 63 | |
| 64 // Overrides the manifest path used for a specific service name. | |
| 65 void OverrideManifestPath(const std::string& service_name, | |
| 66 const base::FilePath& path); | |
| 67 | |
| 68 private: | |
| 69 explicit Reader(ManifestProvider* manifest_provider); | |
| 70 | |
| 71 void OnReadManifest(EntryCache* cache, | |
| 72 const CreateEntryForNameCallback& entry_created_callback, | |
| 73 std::unique_ptr<Entry> entry); | |
| 74 | |
| 75 const bool using_static_catalog_ = false; | |
| 76 base::FilePath system_package_dir_; | |
| 77 scoped_refptr<base::TaskRunner> file_task_runner_; | |
| 78 ManifestProvider* const manifest_provider_; | |
| 79 std::map<std::string, std::string> package_name_overrides_; | |
| 80 std::map<std::string, base::FilePath> manifest_path_overrides_; | |
| 81 base::WeakPtrFactory<Reader> weak_factory_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(Reader); | |
| 84 }; | |
| 85 | |
| 86 } // namespace catalog | |
| 87 | |
| 88 #endif // SERVICES_CATALOG_READER_H_ | |
| OLD | NEW |