OLD | NEW |
---|---|
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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 static bool HasCreatedInstance(); | 48 static bool HasCreatedInstance(); |
49 // Returns true if there is a ApplicationInstance for this URL. | 49 // Returns true if there is a ApplicationInstance for this URL. |
50 bool HasRunningInstanceForURL(const GURL& url) const; | 50 bool HasRunningInstanceForURL(const GURL& url) const; |
51 private: | 51 private: |
52 ApplicationManager* manager_; | 52 ApplicationManager* manager_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(TestAPI); | 54 DISALLOW_COPY_AND_ASSIGN(TestAPI); |
55 }; | 55 }; |
56 | 56 |
57 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); | 57 explicit ApplicationManager(scoped_ptr<PackageManager> package_manager); |
58 ApplicationManager(scoped_ptr<PackageManager> package_manager, | |
59 scoped_ptr<NativeRunnerFactory> native_runner_factory, | |
60 base::TaskRunner* task_runner); | |
yzshen1
2015/09/23 16:53:46
Please comment on what this task_runner is used fo
| |
58 ~ApplicationManager(); | 61 ~ApplicationManager(); |
59 | 62 |
60 // Loads a service if necessary and establishes a new client connection. | 63 // Loads a service if necessary and establishes a new client connection. |
61 // 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 |
62 // about the parameters. | 65 // about the parameters. |
63 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); | 66 void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params); |
64 | 67 |
65 // 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(). |
66 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { | 69 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { |
67 default_loader_ = loader.Pass(); | 70 default_loader_ = loader.Pass(); |
68 } | 71 } |
69 void set_native_runner_factory( | 72 |
70 scoped_ptr<NativeRunnerFactory> runner_factory) { | |
71 native_runner_factory_ = runner_factory.Pass(); | |
72 } | |
73 void set_blocking_pool(base::SequencedWorkerPool* blocking_pool) { | |
74 blocking_pool_ = blocking_pool; | |
75 } | |
76 // Sets a Loader to be used for a specific url. | 73 // Sets a Loader to be used for a specific url. |
77 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); | 74 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); |
78 | 75 |
79 // Destroys all Shell-ends of connections established with Applications. | 76 // Destroys all Shell-ends of connections established with Applications. |
80 // Applications connected by this ApplicationManager will observe pipe errors | 77 // Applications connected by this ApplicationManager will observe pipe errors |
81 // and have a chance to shutdown. | 78 // and have a chance to shutdown. |
82 void TerminateShellConnections(); | 79 void TerminateShellConnections(); |
83 | 80 |
84 // Removes a ApplicationInstance when it encounters an error. | 81 // Removes a ApplicationInstance when it encounters an error. |
85 void OnApplicationInstanceError(ApplicationInstance* instance); | 82 void OnApplicationInstanceError(ApplicationInstance* instance); |
86 | 83 |
87 // Removes a ContentHandler when its connection is closed. | |
88 void OnContentHandlerConnectionClosed( | |
89 ContentHandlerConnection* content_handler); | |
90 | |
91 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; | 84 ApplicationInstance* GetApplicationInstance(const Identity& identity) const; |
92 | 85 |
93 private: | 86 private: |
94 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; | 87 using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>; |
95 using IdentityToContentHandlerMap = | |
96 std::map<Identity, ContentHandlerConnection*>; | |
97 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; | 88 using URLToLoaderMap = std::map<GURL, ApplicationLoader*>; |
98 | 89 |
99 // Takes the contents of |params| only when it returns true. | 90 // Takes the contents of |params| only when it returns true. |
100 bool ConnectToRunningApplication( | 91 bool ConnectToRunningApplication( |
101 scoped_ptr<ConnectToApplicationParams>* params); | 92 scoped_ptr<ConnectToApplicationParams>* params); |
102 | 93 |
103 InterfaceRequest<Application> CreateInstance( | 94 InterfaceRequest<Application> CreateInstance( |
104 scoped_ptr<ConnectToApplicationParams> params, | 95 scoped_ptr<ConnectToApplicationParams> params, |
105 ApplicationInstance** instance); | 96 ApplicationInstance** instance); |
106 | 97 |
107 // Called once |fetcher| has found app. |params->app_url()| is the url of | 98 // Called once |fetcher| has found app. |params->app_url()| is the url of |
108 // the requested application before any mappings/resolution have been applied. | 99 // the requested application before any mappings/resolution have been applied. |
109 // The corresponding URLRequest struct in |params| has been taken. | 100 // The corresponding URLRequest struct in |params| has been taken. |
110 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, | 101 void HandleFetchCallback(scoped_ptr<ConnectToApplicationParams> params, |
111 scoped_ptr<Fetcher> fetcher); | 102 scoped_ptr<Fetcher> fetcher); |
112 | 103 |
113 void RunNativeApplication(InterfaceRequest<Application> application_request, | 104 void RunNativeApplication(InterfaceRequest<Application> application_request, |
114 bool start_sandboxed, | 105 bool start_sandboxed, |
115 scoped_ptr<Fetcher> fetcher, | 106 scoped_ptr<Fetcher> fetcher, |
116 const base::FilePath& file_path, | 107 const base::FilePath& file_path, |
117 bool path_exists); | 108 bool path_exists); |
118 | 109 |
119 void LoadWithContentHandler( | |
120 const Identity& source, | |
121 const Identity& content_handler, | |
122 const Shell::ConnectToApplicationCallback& connect_callback, | |
123 ApplicationInstance* app, | |
124 InterfaceRequest<Application> application_request, | |
125 URLResponsePtr url_response); | |
126 | |
127 // Returns the appropriate loader for |url|, or the default loader if there is | 110 // Returns the appropriate loader for |url|, or the default loader if there is |
128 // no loader configured for the URL. | 111 // no loader configured for the URL. |
129 ApplicationLoader* GetLoaderForURL(const GURL& url); | 112 ApplicationLoader* GetLoaderForURL(const GURL& url); |
130 | 113 |
131 void CleanupRunner(NativeRunner* runner); | 114 void CleanupRunner(NativeRunner* runner); |
132 | 115 |
133 scoped_ptr<PackageManager> const package_manager_; | 116 scoped_ptr<PackageManager> const package_manager_; |
134 // Loader management. | 117 // Loader management. |
135 // Loaders are chosen in the order they are listed here. | 118 // Loaders are chosen in the order they are listed here. |
136 URLToLoaderMap url_to_loader_; | 119 URLToLoaderMap url_to_loader_; |
137 scoped_ptr<ApplicationLoader> default_loader_; | 120 scoped_ptr<ApplicationLoader> default_loader_; |
138 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | |
139 | 121 |
140 IdentityToInstanceMap identity_to_instance_; | 122 IdentityToInstanceMap identity_to_instance_; |
141 IdentityToContentHandlerMap identity_to_content_handler_; | |
142 | 123 |
143 base::SequencedWorkerPool* blocking_pool_; | 124 base::TaskRunner* task_runner_; |
125 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | |
144 ScopedVector<NativeRunner> native_runners_; | 126 ScopedVector<NativeRunner> native_runners_; |
145 // Counter used to assign ids to content_handlers. | |
146 uint32_t content_handler_id_counter_; | |
147 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; | 127 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; |
148 | 128 |
149 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); | 129 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); |
150 }; | 130 }; |
151 | 131 |
152 Shell::ConnectToApplicationCallback EmptyConnectCallback(); | 132 Shell::ConnectToApplicationCallback EmptyConnectCallback(); |
153 | 133 |
154 } // namespace shell | 134 } // namespace shell |
155 } // namespace mojo | 135 } // namespace mojo |
156 | 136 |
157 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ | 137 #endif // MOJO_SHELL_APPLICATION_MANAGER_H_ |
OLD | NEW |