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

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
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 61 // |originator| can be NULL (e.g. for the first application or in tests), but
yzshen1 2015/09/17 20:49:11 Please remove this sentence.
63 // typically is non-NULL and identifies the instance initiating the 62 // typically is non-NULL and identifies the instance initiating the
64 // connection. 63 // connection.
65 // Please see the comments in connect_to_application_params.h for more details 64 // Please see the comments in connect_to_application_params.h for more details
66 // about the parameters. 65 // 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); 66 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params);
78 67
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(). 68 // Sets the default Loader to be used if not overridden by SetLoaderForURL().
90 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { 69 void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
91 default_loader_ = loader.Pass(); 70 default_loader_ = loader.Pass();
92 } 71 }
93 void set_native_runner_factory( 72 void set_native_runner_factory(
94 scoped_ptr<NativeRunnerFactory> runner_factory) { 73 scoped_ptr<NativeRunnerFactory> runner_factory) {
95 native_runner_factory_ = runner_factory.Pass(); 74 native_runner_factory_ = runner_factory.Pass();
96 } 75 }
97 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { 76 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) {
98 blocking_pool_ = blocking_pool; 77 blocking_pool_ = blocking_pool;
99 } 78 }
100 // Sets a Loader to be used for a specific url. 79 // Sets a Loader to be used for a specific url.
101 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); 80 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
102 81
103 // Destroys all Shell-ends of connections established with Applications. 82 // Destroys all Shell-ends of connections established with Applications.
104 // Applications connected by this ApplicationManager will observe pipe errors 83 // Applications connected by this ApplicationManager will observe pipe errors
105 // and have a chance to shutdown. 84 // and have a chance to shutdown.
106 void TerminateShellConnections(); 85 void TerminateShellConnections();
107 86
108 // Removes a ApplicationInstance when it encounters an error. 87 // Removes a ApplicationInstance when it encounters an error.
109 void OnApplicationInstanceError(ApplicationInstance* instance); 88 void OnApplicationInstanceError(ApplicationInstance* instance);
110 89
111 // Removes a ContentHandler when its connection is closed. 90 // Removes a ContentHandler when its connection is closed.
112 void OnContentHandlerConnectionClosed( 91 void OnContentHandlerConnectionClosed(
113 ContentHandlerConnection* content_handler); 92 ContentHandlerConnection* content_handler);
114 93
115 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; 94 ApplicationInstance* GetApplicationInstance(const Identity& identity) const;
116 95
117 private: 96 private:
118 using IdentityToApplicationInstanceMap = 97 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>;
119 std::map<Identity, ApplicationInstance*>; 98 using IdentityToContentHandlerMap =
120 using URLToContentHandlerMap = 99 std::map<Identity, ContentHandlerConnection*>;
121 std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>;
122 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; 100 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
123 101
124 // Takes the contents of |params| only when it returns true. 102 // Takes the contents of |params| only when it returns true.
125 bool ConnectToRunningApplication( 103 bool ConnectToRunningApplication(
126 scoped_ptr<ConnectToApplicationParams>* params); 104 scoped_ptr<ConnectToApplicationParams>* params);
127 // |resolved_url| is the URL to load by |loader| (if loader is not null). It 105 // |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 106 // may be different from |(*params)->app_url()| because of mappings and
129 // resolution rules. 107 // resolution rules.
130 // Takes the contents of |params| only when it returns true. 108 // Takes the contents of |params| only when it returns true.
131 void ConnectToApplicationWithLoader( 109 void ConnectToApplicationWithLoader(
132 scoped_ptr<ConnectToApplicationParams>* params, 110 scoped_ptr<ConnectToApplicationParams>* params,
133 const GURL& resolved_url, 111 const GURL& resolved_url,
134 ApplicationLoader* loader); 112 ApplicationLoader* loader);
135 113
136 InterfaceRequest<Application> RegisterInstance( 114 InterfaceRequest<Application> CreateInstance(
137 scoped_ptr<ConnectToApplicationParams> params, 115 scoped_ptr<ConnectToApplicationParams> params,
138 ApplicationInstance** resulting_instance); 116 ApplicationInstance** instance);
139 117
140 // Called once |fetcher| has found app. |params->app_url()| is the url of 118 // Called once |fetcher| has found app. |params->app_url()| is the url of
141 // the requested application before any mappings/resolution have been applied. 119 // the requested application before any mappings/resolution have been applied.
142 // The corresponding URLRequest struct in |params| has been taken. 120 // The corresponding URLRequest struct in |params| has been taken.
143 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, 121 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params,
144 scoped_ptr<Fetcher> fetcher); 122 scoped_ptr<Fetcher> fetcher);
145 123
146 void RunNativeApplication(InterfaceRequest<Application> application_request, 124 void RunNativeApplication(InterfaceRequest<Application> application_request,
147 bool start_sandboxed, 125 bool start_sandboxed,
148 scoped_ptr<Fetcher> fetcher, 126 scoped_ptr<Fetcher> fetcher,
(...skipping 10 matching lines...) Expand all
159 ApplicationInstance* app, 137 ApplicationInstance* app,
160 InterfaceRequest<Application> application_request, 138 InterfaceRequest<Application> application_request,
161 URLResponsePtr url_response); 139 URLResponsePtr url_response);
162 140
163 // Returns the appropriate loader for |url|, or the default loader if there is 141 // Returns the appropriate loader for |url|, or the default loader if there is
164 // no loader configured for the URL. 142 // no loader configured for the URL.
165 ApplicationLoader* GetLoaderForURL(const GURL& url); 143 ApplicationLoader* GetLoaderForURL(const GURL& url);
166 144
167 void CleanupRunner(NativeRunner* runner); 145 void CleanupRunner(NativeRunner* runner);
168 146
169 ScopedMessagePipeHandle ConnectToServiceByName(
170 const GURL& application_url,
171 const std::string& interface_name);
172
173 scoped_ptr<PackageManager> const package_manager_; 147 scoped_ptr<PackageManager> const package_manager_;
174 // Loader management. 148 // Loader management.
175 // Loaders are chosen in the order they are listed here. 149 // Loaders are chosen in the order they are listed here.
176 URLToLoaderMap url_to_loader_; 150 URLToLoaderMap url_to_loader_;
177 scoped_ptr<ApplicationLoader> default_loader_; 151 scoped_ptr<ApplicationLoader> default_loader_;
178 scoped_ptr<NativeRunnerFactory> native_runner_factory_; 152 scoped_ptr<NativeRunnerFactory> native_runner_factory_;
179 153
180 IdentityToApplicationInstanceMap identity_to_instance_; 154 IdentityToInstanceMap identity_to_instance_;
181 URLToContentHandlerMap url_to_content_handler_; 155 IdentityToContentHandlerMap identity_to_content_handler_;
182 156
183 base::SequencedWorkerPool* blocking_pool_; 157 base::SequencedWorkerPool* blocking_pool_;
184 updater::UpdaterPtr updater_;
185 ScopedVector<NativeRunner> native_runners_; 158 ScopedVector<NativeRunner> native_runners_;
186 // Counter used to assign ids to content_handlers. 159 // Counter used to assign ids to content_handlers.
187 uint32_t content_handler_id_counter_; 160 uint32_t content_handler_id_counter_;
188 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; 161 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
189 162
190 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); 163 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
191 }; 164 };
192 165
193 Shell::ConnectToApplicationCallback EmptyConnectCallback(); 166 Shell::ConnectToApplicationCallback EmptyConnectCallback();
194 167
195 } // namespace shell 168 } // namespace shell
196 } // namespace mojo 169 } // namespace mojo
197 170
198 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ 171 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698