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

Side by Side Diff: mojo/shell/package_manager/package_manager_impl.h

Issue 1701933004: Remove the old package manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@am2
Patch Set: . Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2015 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 MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
6 #define MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
7
8 #include <stdint.h>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/values.h"
13 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
14 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
15 #include "mojo/shell/fetcher/url_resolver.h"
16 #include "mojo/shell/package_manager.h"
17
18 namespace base {
19 class TaskRunner;
20 }
21
22 namespace mojo {
23 class ContentHandler;
24 namespace shell {
25 class ContentHandlerConnection;
26 class Fetcher;
27 class Identity;
28
29 // Static information about an application package known to the PackageManager.
30 struct ApplicationInfo {
31 ApplicationInfo();
32 ~ApplicationInfo();
33
34 std::string url;
35 std::string name;
36 CapabilityFilter base_filter;
37 };
38
39 // Implemented by an object that provides storage for the application catalog
40 // (e.g. in Chrome, preferences). The PackageManagerImpl is the canonical owner
41 // of the contents of the store, so no one else must modify its contents.
42 class ApplicationCatalogStore {
43 public:
44 // Called during initialization to construct the PackageManagerImpl's catalog.
45 virtual void GetStore(base::ListValue** store) = 0;
46
47 // Write the catalog to the store. Called when the PackageManagerImpl learns
48 // of a newly encountered application.
49 virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0;
50
51 protected:
52 virtual ~ApplicationCatalogStore();
53 };
54
55 // This is the default implementation of PackageManager. It loads http/s urls
56 // off the network as well as providing special handling for mojo: and about:
57 // urls.
58 class PackageManagerImpl : public PackageManager {
59 public:
60 // mojo: urls are only supported if |shell_file_root| is non-empty.
61 // |task_runner| is used by Fetchers created by the PackageManager to complete
62 // file copies needed to obtain library paths that the ApplicationManager can
63 // load. This can be null only in tests where application loading is handled
64 // by custom ApplicationLoader implementations.
65 PackageManagerImpl(const base::FilePath& shell_file_root,
66 base::TaskRunner* task_runner,
67 ApplicationCatalogStore* catalog_store);
68 ~PackageManagerImpl() override;
69
70 // Register a content handler to handle content of |mime_type|.
71 void RegisterContentHandler(const std::string& mime_type,
72 const GURL& content_handler_url);
73
74 // Registers a package alias. When attempting to load |alias|, it will
75 // instead redirect to |content_handler_package|, which is a content handler
76 // which will be passed the |alias| as the URLResponse::url. Different values
77 // of |alias| with the same |qualifier| that are in the same
78 // |content_handler_package| will run in the same process in multi-process
79 // mode.
80 void RegisterApplicationPackageAlias(
81 const GURL& alias,
82 const GURL& content_handler_package,
83 const std::string& qualifier);
84
85 private:
86 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>;
87 using MimeTypeToURLMap = std::map<std::string, GURL>;
88 using IdentityToContentHandlerMap =
89 std::map<Identity, ContentHandlerConnection*>;
90
91 // Overridden from PackageManager:
92 void SetApplicationManager(ApplicationManager* manager) override;
93 void BuiltinAppLoaded(const GURL& url) override;
94 void FetchRequest(
95 URLRequestPtr request,
96 const Fetcher::FetchCallback& loader_callback) override;
97 uint32_t HandleWithContentHandler(
98 Fetcher* fetcher,
99 const Identity& source,
100 const GURL& target_url,
101 const CapabilityFilter& target_filter,
102 InterfaceRequest<mojom::ShellClient>* request) override;
103 bool IsURLInCatalog(const std::string& url) const override;
104 std::string GetApplicationName(const std::string& url) const override;
105 GURL ResolveMojoURL(const GURL& mojo_url) override;
106 uint32_t StartContentHandler(const Identity& source,
107 const Identity& content_handler,
108 const GURL& url,
109 mojom::ShellClientRequest request) override;
110
111 GURL ResolveURL(const GURL& url);
112 bool ShouldHandleWithContentHandler(
113 Fetcher* fetcher,
114 const GURL& target_url,
115 const CapabilityFilter& target_filter,
116 Identity* content_handler_identity,
117 URLResponsePtr* response) const;
118
119 // Returns a running ContentHandler for |content_handler_identity|, if there
120 // is not one running one is started for |source_identity|.
121 ContentHandlerConnection* GetContentHandler(
122 const Identity& content_handler_identity,
123 const Identity& source_identity);
124
125 void OnContentHandlerConnectionClosed(
126 ContentHandlerConnection* content_handler);
127
128 // If |url| is not in the catalog, attempts to load a manifest for it.
129 void EnsureURLInCatalog(const GURL& url);
130
131 // Populate/serialize the catalog from/to the supplied store.
132 void DeserializeCatalog();
133 void SerializeCatalog();
134
135 // Construct a catalog entry from |dictionary|.
136 const ApplicationInfo& DeserializeApplication(
137 const base::DictionaryValue* dictionary);
138
139 // Reads a manifest in the blocking pool and returns a base::Value with its
140 // contents via OnReadManifest().
141 scoped_ptr<base::Value> ReadManifest(const base::FilePath& manifest_path);
142 void OnReadManifest(scoped_ptr<base::Value> manifest);
143
144 ApplicationManager* application_manager_;
145 scoped_ptr<URLResolver> url_resolver_;
146 const bool disable_cache_;
147 NetworkServicePtr network_service_;
148 URLLoaderFactoryPtr url_loader_factory_;
149 ApplicationPackagedAlias application_package_alias_;
150 MimeTypeToURLMap mime_type_to_url_;
151 IdentityToContentHandlerMap identity_to_content_handler_;
152 // Counter used to assign ids to content handlers.
153 uint32_t content_handler_id_counter_;
154 base::TaskRunner* task_runner_;
155 base::FilePath shell_file_root_;
156
157 ApplicationCatalogStore* catalog_store_;
158 std::map<std::string, ApplicationInfo> catalog_;
159
160 DISALLOW_COPY_AND_ASSIGN(PackageManagerImpl);
161 };
162
163 } // namespace shell
164 } // namespace mojo
165
166 #endif // MOJO_SHELL_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/shell/package_manager/content_handler_unittest.cc ('k') | mojo/shell/package_manager/package_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698