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_CATALOG_H_ | 5 #ifndef SERVICES_CATALOG_CATALOG_H_ |
6 #define SERVICES_CATALOG_CATALOG_H_ | 6 #define SERVICES_CATALOG_CATALOG_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
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 "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "services/catalog/public/interfaces/catalog.mojom.h" | 15 #include "services/catalog/public/interfaces/catalog.mojom.h" |
16 #include "services/catalog/types.h" | 16 #include "services/catalog/types.h" |
17 #include "services/shell/public/cpp/shell_client.h" | 17 #include "services/shell/public/cpp/shell_client.h" |
18 #include "services/shell/public/interfaces/shell_client.mojom.h" | 18 #include "services/shell/public/interfaces/shell_client.mojom.h" |
19 #include "services/shell/public/interfaces/shell_resolver.mojom.h" | 19 #include "services/shell/public/interfaces/shell_resolver.mojom.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class TaskRunner; | 22 class SequencedWorkerPool; |
| 23 class SingleThreadTaskRunner; |
23 } | 24 } |
24 | 25 |
25 namespace shell { | 26 namespace shell { |
26 class ShellConnection; | 27 class ShellConnection; |
27 } | 28 } |
28 | 29 |
29 namespace catalog { | 30 namespace catalog { |
30 | 31 |
31 class Instance; | 32 class Instance; |
32 class ManifestProvider; | 33 class ManifestProvider; |
33 class Reader; | 34 class Reader; |
34 class Store; | 35 class Store; |
35 | 36 |
36 // Creates and owns an instance of the catalog. Exposes a ShellClientPtr that | 37 // Creates and owns an instance of the catalog. Exposes a ShellClientPtr that |
37 // can be passed to the Shell, potentially in a different process. | 38 // can be passed to the Shell, potentially in a different process. |
38 class Catalog : public shell::ShellClient, | 39 class Catalog : public shell::ShellClient, |
39 public shell::InterfaceFactory<mojom::Catalog>, | 40 public shell::InterfaceFactory<mojom::Catalog>, |
40 public shell::InterfaceFactory<shell::mojom::ShellResolver> { | 41 public shell::InterfaceFactory<shell::mojom::ShellResolver> { |
41 public: | 42 public: |
42 // |manifest_provider| may be null. | 43 // |manifest_provider| may be null. |
43 Catalog(base::TaskRunner* file_task_runner, | 44 Catalog(base::SequencedWorkerPool* worker_pool, |
| 45 std::unique_ptr<Store> store, |
| 46 ManifestProvider* manifest_provider); |
| 47 Catalog(base::SingleThreadTaskRunner* task_runner, |
44 std::unique_ptr<Store> store, | 48 std::unique_ptr<Store> store, |
45 ManifestProvider* manifest_provider); | 49 ManifestProvider* manifest_provider); |
46 ~Catalog() override; | 50 ~Catalog() override; |
47 | 51 |
48 shell::mojom::ShellClientPtr TakeShellClient(); | 52 shell::mojom::ShellClientPtr TakeShellClient(); |
49 | 53 |
50 private: | 54 private: |
| 55 explicit Catalog(std::unique_ptr<Store> store); |
| 56 |
| 57 // Starts a scane for system packages. |
| 58 void ScanSystemPackageDir(); |
| 59 |
51 // shell::ShellClient: | 60 // shell::ShellClient: |
52 bool AcceptConnection(shell::Connection* connection) override; | 61 bool AcceptConnection(shell::Connection* connection) override; |
53 | 62 |
54 // shell::InterfaceFactory<shell::mojom::ShellResolver>: | 63 // shell::InterfaceFactory<shell::mojom::ShellResolver>: |
55 void Create(shell::Connection* connection, | 64 void Create(shell::Connection* connection, |
56 shell::mojom::ShellResolverRequest request) override; | 65 shell::mojom::ShellResolverRequest request) override; |
57 | 66 |
58 // shell::InterfaceFactory<mojom::Catalog>: | 67 // shell::InterfaceFactory<mojom::Catalog>: |
59 void Create(shell::Connection* connection, | 68 void Create(shell::Connection* connection, |
60 mojom::CatalogRequest request) override; | 69 mojom::CatalogRequest request) override; |
61 | 70 |
62 Instance* GetInstanceForUserId(const std::string& user_id); | 71 Instance* GetInstanceForUserId(const std::string& user_id); |
63 | 72 |
64 void SystemPackageDirScanned(); | 73 void SystemPackageDirScanned(); |
65 | 74 |
66 base::TaskRunner* const file_task_runner_; | |
67 std::unique_ptr<Store> store_; | 75 std::unique_ptr<Store> store_; |
68 | 76 |
69 shell::mojom::ShellClientPtr shell_client_; | 77 shell::mojom::ShellClientPtr shell_client_; |
70 std::unique_ptr<shell::ShellConnection> shell_connection_; | 78 std::unique_ptr<shell::ShellConnection> shell_connection_; |
71 | 79 |
72 std::map<std::string, std::unique_ptr<Instance>> instances_; | 80 std::map<std::string, std::unique_ptr<Instance>> instances_; |
73 | 81 |
74 std::unique_ptr<Reader> system_reader_; | 82 std::unique_ptr<Reader> system_reader_; |
75 EntryCache system_cache_; | 83 EntryCache system_cache_; |
76 bool loaded_ = false; | 84 bool loaded_ = false; |
77 | 85 |
78 base::WeakPtrFactory<Catalog> weak_factory_; | 86 base::WeakPtrFactory<Catalog> weak_factory_; |
79 | 87 |
80 DISALLOW_COPY_AND_ASSIGN(Catalog); | 88 DISALLOW_COPY_AND_ASSIGN(Catalog); |
81 }; | 89 }; |
82 | 90 |
83 } // namespace catalog | 91 } // namespace catalog |
84 | 92 |
85 #endif // SERVICES_CATALOG_CATALOG_H_ | 93 #endif // SERVICES_CATALOG_CATALOG_H_ |
OLD | NEW |