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 #ifndef SERVICES_CATALOG_READER_H_ | 5 #ifndef SERVICES_CATALOG_READER_H_ |
6 #define SERVICES_CATALOG_READER_H_ | 6 #define SERVICES_CATALOG_READER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "services/catalog/types.h" | 14 #include "services/catalog/types.h" |
15 #include "services/shell/public/interfaces/shell_resolver.mojom.h" | 15 #include "services/shell/public/interfaces/shell_resolver.mojom.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class TaskRunner; | 18 class SequencedWorkerPool; |
| 19 class SingleThreadTaskRunner; |
19 } | 20 } |
20 | 21 |
21 namespace catalog { | 22 namespace catalog { |
22 | 23 |
23 class Entry; | 24 class Entry; |
24 class ManifestProvider; | 25 class ManifestProvider; |
25 | 26 |
26 // Responsible for loading manifests & building the Entry data structures. | 27 // Responsible for loading manifests & building the Entry data structures. |
27 class Reader { | 28 class Reader { |
28 public: | 29 public: |
29 using ReadManifestCallback = base::Callback<void(std::unique_ptr<Entry>)>; | 30 using ReadManifestCallback = base::Callback<void(std::unique_ptr<Entry>)>; |
30 using CreateEntryForNameCallback = | 31 using CreateEntryForNameCallback = |
31 base::Callback<void(shell::mojom::ResolveResultPtr)>; | 32 base::Callback<void(shell::mojom::ResolveResultPtr)>; |
32 | 33 |
33 Reader(base::TaskRunner* file_task_runner, | 34 Reader(base::SequencedWorkerPool* worker_pool, |
| 35 ManifestProvider* manifest_provider); |
| 36 Reader(base::SingleThreadTaskRunner* task_runner, |
34 ManifestProvider* manifest_provider); | 37 ManifestProvider* manifest_provider); |
35 ~Reader(); | 38 ~Reader(); |
36 | 39 |
37 // Scans the contents of |package_dir|, reading all application manifests and | 40 // Scans the contents of |package_dir|, reading all application manifests and |
38 // populating |cache|. Runs |read_complete_closure| when done. | 41 // populating |cache|. Runs |read_complete_closure| when done. |
39 void Read(const base::FilePath& package_dir, | 42 void Read(const base::FilePath& package_dir, |
40 EntryCache* cache, | 43 EntryCache* cache, |
41 const base::Closure& read_complete_closure); | 44 const base::Closure& read_complete_closure); |
42 | 45 |
43 // Returns an Entry for |mojo_name| via |callback|, assuming a manifest file | 46 // Returns an Entry for |mojo_name| via |callback|, assuming a manifest file |
44 // in the canonical location | 47 // in the canonical location |
45 void CreateEntryForName( | 48 void CreateEntryForName( |
46 const std::string& mojo_name, | 49 const std::string& mojo_name, |
47 EntryCache* cache, | 50 EntryCache* cache, |
48 const CreateEntryForNameCallback& entry_created_callback); | 51 const CreateEntryForNameCallback& entry_created_callback); |
49 | 52 |
50 private: | 53 private: |
| 54 explicit Reader(ManifestProvider* manifest_provider); |
| 55 |
51 void OnReadManifest(EntryCache* cache, | 56 void OnReadManifest(EntryCache* cache, |
52 const CreateEntryForNameCallback& entry_created_callback, | 57 const CreateEntryForNameCallback& entry_created_callback, |
53 std::unique_ptr<Entry> entry); | 58 std::unique_ptr<Entry> entry); |
54 | 59 |
55 base::FilePath system_package_dir_; | 60 base::FilePath system_package_dir_; |
56 base::TaskRunner* file_task_runner_; | 61 scoped_refptr<base::TaskRunner> file_task_runner_; |
57 ManifestProvider* const manifest_provider_; | 62 ManifestProvider* const manifest_provider_; |
58 base::WeakPtrFactory<Reader> weak_factory_; | 63 base::WeakPtrFactory<Reader> weak_factory_; |
59 | 64 |
60 DISALLOW_COPY_AND_ASSIGN(Reader); | 65 DISALLOW_COPY_AND_ASSIGN(Reader); |
61 }; | 66 }; |
62 | 67 |
63 } // namespace catalog | 68 } // namespace catalog |
64 | 69 |
65 #endif // SERVICES_CATALOG_READER_H_ | 70 #endif // SERVICES_CATALOG_READER_H_ |
OLD | NEW |