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

Side by Side Diff: mojo/shell/application_manager.h

Issue 1351963002: Some more minor cleanup to ApplicationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 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
« no previous file with comments | « mojo/shell/application_instance.cc ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 MOJO_SHELL_APPLICATION_MANAGER_H_ 5 #ifndef MOJO_SHELL_APPLICATION_MANAGER_H_
6 #define MOJO_SHELL_APPLICATION_MANAGER_H_ 6 #define MOJO_SHELL_APPLICATION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/application/public/interfaces/application.mojom.h" 14 #include "mojo/application/public/interfaces/application.mojom.h"
15 #include "mojo/application/public/interfaces/service_provider.mojom.h" 15 #include "mojo/application/public/interfaces/service_provider.mojom.h"
16 #include "mojo/application/public/interfaces/shell.mojom.h" 16 #include "mojo/application/public/interfaces/shell.mojom.h"
17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
18 #include "mojo/public/cpp/bindings/interface_request.h" 18 #include "mojo/public/cpp/bindings/interface_request.h"
19 #include "mojo/services/updater/updater.mojom.h"
20 #include "mojo/shell/application_loader.h" 19 #include "mojo/shell/application_loader.h"
21 #include "mojo/shell/capability_filter.h" 20 #include "mojo/shell/capability_filter.h"
22 #include "mojo/shell/connect_to_application_params.h" 21 #include "mojo/shell/connect_to_application_params.h"
23 #include "mojo/shell/fetcher.h" 22 #include "mojo/shell/fetcher.h"
24 #include "mojo/shell/identity.h" 23 #include "mojo/shell/identity.h"
25 #include "mojo/shell/native_runner.h" 24 #include "mojo/shell/native_runner.h"
26 #include "url/gurl.h" 25 #include "url/gurl.h"
27 26
28 namespace base { 27 namespace base {
29 class FilePath; 28 class FilePath;
(...skipping 22 matching lines...) Expand all
52 private: 51 private:
53 ApplicationManager* manager_; 52 ApplicationManager* manager_;
54 53
55 DISALLOW_COPY_AND_ASSIGN(TestAPI); 54 DISALLOW_COPY_AND_ASSIGN(TestAPI);
56 }; 55 };
57 56
58 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); 57 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager);
59 ~ApplicationManager(); 58 ~ApplicationManager();
60 59
61 // Loads a service if necessary and establishes a new client connection. 60 // Loads a service if necessary and establishes a new client connection.
62 // |originator| can be NULL (e.g. for the first application or in tests), but
63 // typically is non-NULL and identifies the instance initiating the
64 // connection.
65 // Please see the comments in connect_to_application_params.h for more details 61 // Please see the comments in connect_to_application_params.h for more details
66 // about the parameters. 62 // about the parameters.
67 void ConnectToApplication(
68 ApplicationInstance* originator,
69 URLRequestPtr app_url_request,
70 const std::string& qualifier,
71 InterfaceRequest<ServiceProvider> services,
72 ServiceProviderPtr exposed_services,
73 const CapabilityFilter& filter,
74 const base::Closure& on_application_end,
75 const Shell::ConnectToApplicationCallback& connect_callback);
76
77 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); 63 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params);
78 64
79 // Must only be used by shell internals and test code as it does not forward
80 // capability filters.
81 template <typename Interface>
82 inline void ConnectToService(const GURL& application_url,
83 InterfacePtr<Interface>* ptr) {
84 ScopedMessagePipeHandle service_handle =
85 ConnectToServiceByName(application_url, Interface::Name_);
86 ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u));
87 }
88
89 // Sets the default Loader to be used if not overridden by SetLoaderForURL(). 65 // Sets the default Loader to be used if not overridden by SetLoaderForURL().
90 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { 66 void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
91 default_loader_ = loader.Pass(); 67 default_loader_ = loader.Pass();
92 } 68 }
93 void set_native_runner_factory( 69 void set_native_runner_factory(
94 scoped_ptr<NativeRunnerFactory> runner_factory) { 70 scoped_ptr<NativeRunnerFactory> runner_factory) {
95 native_runner_factory_ = runner_factory.Pass(); 71 native_runner_factory_ = runner_factory.Pass();
96 } 72 }
97 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { 73 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
98 blocking_pool_ = blocking_pool; 74 blocking_pool_ = blocking_pool;
99 } 75 }
100 // Sets a Loader to be used for a specific url. 76 // Sets a Loader to be used for a specific url.
101 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); 77 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
102 78
103 // Destroys all Shell-ends of connections established with Applications. 79 // Destroys all Shell-ends of connections established with Applications.
104 // Applications connected by this ApplicationManager will observe pipe errors 80 // Applications connected by this ApplicationManager will observe pipe errors
105 // and have a chance to shutdown. 81 // and have a chance to shutdown.
106 void TerminateShellConnections(); 82 void TerminateShellConnections();
107 83
108 // Removes a ApplicationInstance when it encounters an error. 84 // Removes a ApplicationInstance when it encounters an error.
109 void OnApplicationInstanceError(ApplicationInstance* instance); 85 void OnApplicationInstanceError(ApplicationInstance* instance);
110 86
111 // Removes a ContentHandler when its connection is closed. 87 // Removes a ContentHandler when its connection is closed.
112 void OnContentHandlerConnectionClosed( 88 void OnContentHandlerConnectionClosed(
113 ContentHandlerConnection* content_handler); 89 ContentHandlerConnection* content_handler);
114 90
115 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; 91 ApplicationInstance* GetApplicationInstance(const Identity& identity) const;
116 92
117 private: 93 private:
118 using IdentityToApplicationInstanceMap = 94 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>;
119 std::map<Identity, ApplicationInstance*>; 95 using IdentityToContentHandlerMap =
120 using URLToContentHandlerMap = 96 std::map<Identity, ContentHandlerConnection*>;
121 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>;
122 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; 97 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
123 98
124 // Takes the contents of |params| only when it returns true. 99 // Takes the contents of |params| only when it returns true.
125 bool ConnectToRunningApplication( 100 bool ConnectToRunningApplication(
126 scoped_ptr<ConnectToApplicationParams>* params); 101 scoped_ptr<ConnectToApplicationParams>* params);
127 // |resolved_url| is the URL to load by |loader| (if loader is not null). It 102 // |resolved_url| is the URL to load by |loader| (if loader is not null). It
128 // may be different from |(*params)->app_url()| because of mappings and 103 // may be different from |(*params)->app_url()| because of mappings and
129 // resolution rules. 104 // resolution rules.
130 // Takes the contents of |params| only when it returns true. 105 // Takes the contents of |params| only when it returns true.
131 void ConnectToApplicationWithLoader( 106 void ConnectToApplicationWithLoader(
132 scoped_ptr<ConnectToApplicationParams>* params, 107 scoped_ptr<ConnectToApplicationParams>* params,
133 const GURL& resolved_url, 108 const GURL& resolved_url,
134 ApplicationLoader* loader); 109 ApplicationLoader* loader);
135 110
136 InterfaceRequest<Application> RegisterInstance( 111 InterfaceRequest<Application> CreateInstance(
137 scoped_ptr<ConnectToApplicationParams> params, 112 scoped_ptr<ConnectToApplicationParams> params,
138 ApplicationInstance** resulting_instance); 113 ApplicationInstance** instance);
139 114
140 // Called once |fetcher| has found app. |params->app_url()| is the url of 115 // Called once |fetcher| has found app. |params->app_url()| is the url of
141 // the requested application before any mappings/resolution have been applied. 116 // the requested application before any mappings/resolution have been applied.
142 // The corresponding URLRequest struct in |params| has been taken. 117 // The corresponding URLRequest struct in |params| has been taken.
143 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, 118 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params,
144 scoped_ptr<Fetcher> fetcher); 119 scoped_ptr<Fetcher> fetcher);
145 120
146 void RunNativeApplication(InterfaceRequest<Application> application_request, 121 void RunNativeApplication(InterfaceRequest<Application> application_request,
147 bool start_sandboxed, 122 bool start_sandboxed,
148 scoped_ptr<Fetcher> fetcher, 123 scoped_ptr<Fetcher> fetcher,
(...skipping 10 matching lines...) Expand all
159 ApplicationInstance* app, 134 ApplicationInstance* app,
160 InterfaceRequest<Application> application_request, 135 InterfaceRequest<Application> application_request,
161 URLResponsePtr url_response); 136 URLResponsePtr url_response);
162 137
163 // Returns the appropriate loader for |url|, or the default loader if there is 138 // Returns the appropriate loader for |url|, or the default loader if there is
164 // no loader configured for the URL. 139 // no loader configured for the URL.
165 ApplicationLoader* GetLoaderForURL(const GURL& url); 140 ApplicationLoader* GetLoaderForURL(const GURL& url);
166 141
167 void CleanupRunner(NativeRunner* runner); 142 void CleanupRunner(NativeRunner* runner);
168 143
169 ScopedMessagePipeHandle ConnectToServiceByName(
170 const GURL& application_url,
171 const std::string& interface_name);
172
173 scoped_ptr<PackageManager> const package_manager_; 144 scoped_ptr<PackageManager> const package_manager_;
174 // Loader management. 145 // Loader management.
175 // Loaders are chosen in the order they are listed here. 146 // Loaders are chosen in the order they are listed here.
176 URLToLoaderMap url_to_loader_; 147 URLToLoaderMap url_to_loader_;
177 scoped_ptr<ApplicationLoader> default_loader_; 148 scoped_ptr<ApplicationLoader> default_loader_;
178 scoped_ptr<NativeRunnerFactory> native_runner_factory_; 149 scoped_ptr<NativeRunnerFactory> native_runner_factory_;
179 150
180 IdentityToApplicationInstanceMap identity_to_instance_; 151 IdentityToInstanceMap identity_to_instance_;
181 URLToContentHandlerMap url_to_content_handler_; 152 IdentityToContentHandlerMap identity_to_content_handler_;
182 153
183 base::SequencedWorkerPool* blocking_pool_; 154 base::SequencedWorkerPool* blocking_pool_;
184 updater::UpdaterPtr updater_;
185 ScopedVector<NativeRunner> native_runners_; 155 ScopedVector<NativeRunner> native_runners_;
186 // Counter used to assign ids to content_handlers. 156 // Counter used to assign ids to content_handlers.
187 uint32_t content_handler_id_counter_; 157 uint32_t content_handler_id_counter_;
188 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; 158 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
189 159
190 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); 160 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
191 }; 161 };
192 162
193 Shell::ConnectToApplicationCallback EmptyConnectCallback(); 163 Shell::ConnectToApplicationCallback EmptyConnectCallback();
194 164
195 } // namespace shell 165 } // namespace shell
196 } // namespace mojo 166 } // namespace mojo
197 167
198 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ 168 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/shell/application_instance.cc ('k') | mojo/shell/application_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698