| 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 #include "mojo/shell/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "mojo/shell/switches.h" | 25 #include "mojo/shell/switches.h" |
| 26 | 26 |
| 27 namespace mojo { | 27 namespace mojo { |
| 28 namespace shell { | 28 namespace shell { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Used by TestAPI. | 32 // Used by TestAPI. |
| 33 bool has_created_instance = false; | 33 bool has_created_instance = false; |
| 34 | 34 |
| 35 void OnEmptyOnConnectCallback(uint32_t content_handler_id) {} | 35 void OnEmptyOnConnectCallback(uint32_t remote_id, uint32_t content_handler_id) { |
| 36 } |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 // static | 40 // static |
| 40 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) | 41 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) |
| 41 : manager_(manager) { | 42 : manager_(manager) { |
| 42 } | 43 } |
| 43 | 44 |
| 44 ApplicationManager::TestAPI::~TestAPI() { | 45 ApplicationManager::TestAPI::~TestAPI() { |
| 45 } | 46 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 native_runner_factory_(std::move(native_runner_factory)), | 68 native_runner_factory_(std::move(native_runner_factory)), |
| 68 weak_ptr_factory_(this) { | 69 weak_ptr_factory_(this) { |
| 69 package_manager_->SetApplicationManager(this); | 70 package_manager_->SetApplicationManager(this); |
| 70 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)), | 71 SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)), |
| 71 GURL("mojo:shell")); | 72 GURL("mojo:shell")); |
| 72 } | 73 } |
| 73 | 74 |
| 74 ApplicationManager::~ApplicationManager() { | 75 ApplicationManager::~ApplicationManager() { |
| 75 TerminateShellConnections(); | 76 TerminateShellConnections(); |
| 76 STLDeleteValues(&url_to_loader_); | 77 STLDeleteValues(&url_to_loader_); |
| 78 for (auto& runner : native_runners_) |
| 79 runner.reset(); |
| 77 } | 80 } |
| 78 | 81 |
| 79 void ApplicationManager::TerminateShellConnections() { | 82 void ApplicationManager::TerminateShellConnections() { |
| 80 STLDeleteValues(&identity_to_instance_); | 83 STLDeleteValues(&identity_to_instance_); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void ApplicationManager::ConnectToApplication( | 86 void ApplicationManager::ConnectToApplication( |
| 84 scoped_ptr<ConnectToApplicationParams> params) { | 87 scoped_ptr<ConnectToApplicationParams> params) { |
| 85 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", | 88 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", |
| 86 TRACE_EVENT_SCOPE_THREAD, "original_url", | 89 TRACE_EVENT_SCOPE_THREAD, "original_url", |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 mojom::ApplicationManagerListenerPtr listener) { | 152 mojom::ApplicationManagerListenerPtr listener) { |
| 150 Array<mojom::ApplicationInfoPtr> applications; | 153 Array<mojom::ApplicationInfoPtr> applications; |
| 151 for (auto& entry : identity_to_instance_) | 154 for (auto& entry : identity_to_instance_) |
| 152 applications.push_back(CreateApplicationInfoForInstance(entry.second)); | 155 applications.push_back(CreateApplicationInfoForInstance(entry.second)); |
| 153 listener->SetRunningApplications(std::move(applications)); | 156 listener->SetRunningApplications(std::move(applications)); |
| 154 | 157 |
| 155 listeners_.AddInterfacePtr(std::move(listener)); | 158 listeners_.AddInterfacePtr(std::move(listener)); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void ApplicationManager::ApplicationPIDAvailable( | 161 void ApplicationManager::ApplicationPIDAvailable( |
| 159 int id, | 162 uint32_t id, |
| 160 base::ProcessId pid) { | 163 base::ProcessId pid) { |
| 161 for (auto& instance : identity_to_instance_) { | 164 for (auto& instance : identity_to_instance_) { |
| 162 if (instance.second->id() == id) { | 165 if (instance.second->id() == id) { |
| 163 instance.second->set_pid(pid); | 166 instance.second->set_pid(pid); |
| 164 break; | 167 break; |
| 165 } | 168 } |
| 166 } | 169 } |
| 167 listeners_.ForAllPtrs( | 170 listeners_.ForAllPtrs( |
| 168 [this, id, pid](mojom::ApplicationManagerListener* listener) { | 171 [this, id, pid](mojom::ApplicationManagerListener* listener) { |
| 169 listener->ApplicationPIDAvailable(id, pid); | 172 listener->ApplicationPIDAvailable(id, pid); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 182 return application_request; | 185 return application_request; |
| 183 } | 186 } |
| 184 | 187 |
| 185 InterfaceRequest<Application> ApplicationManager::CreateInstance( | 188 InterfaceRequest<Application> ApplicationManager::CreateInstance( |
| 186 const Identity& target_id, | 189 const Identity& target_id, |
| 187 const base::Closure& on_application_end, | 190 const base::Closure& on_application_end, |
| 188 ApplicationInstance** resulting_instance) { | 191 ApplicationInstance** resulting_instance) { |
| 189 ApplicationPtr application; | 192 ApplicationPtr application; |
| 190 InterfaceRequest<Application> application_request = GetProxy(&application); | 193 InterfaceRequest<Application> application_request = GetProxy(&application); |
| 191 ApplicationInstance* instance = new ApplicationInstance( | 194 ApplicationInstance* instance = new ApplicationInstance( |
| 192 std::move(application), this, target_id, Shell::kInvalidContentHandlerID, | 195 std::move(application), this, target_id, Shell::kInvalidApplicationID, |
| 193 on_application_end); | 196 on_application_end); |
| 194 DCHECK(identity_to_instance_.find(target_id) == | 197 DCHECK(identity_to_instance_.find(target_id) == |
| 195 identity_to_instance_.end()); | 198 identity_to_instance_.end()); |
| 196 identity_to_instance_[target_id] = instance; | 199 identity_to_instance_[target_id] = instance; |
| 197 mojom::ApplicationInfoPtr application_info = | 200 mojom::ApplicationInfoPtr application_info = |
| 198 CreateApplicationInfoForInstance(instance); | 201 CreateApplicationInfoForInstance(instance); |
| 199 listeners_.ForAllPtrs( | 202 listeners_.ForAllPtrs( |
| 200 [this, &application_info](mojom::ApplicationManagerListener* listener) { | 203 [this, &application_info](mojom::ApplicationManagerListener* listener) { |
| 201 listener->ApplicationInstanceCreated(application_info.Clone()); | 204 listener->ApplicationInstanceCreated(application_info.Clone()); |
| 202 }); | 205 }); |
| 203 instance->InitializeApplication(); | 206 instance->InitializeApplication(); |
| 204 if (resulting_instance) | 207 if (resulting_instance) |
| 205 *resulting_instance = instance; | 208 *resulting_instance = instance; |
| 206 return application_request; | 209 return application_request; |
| 207 } | 210 } |
| 208 | 211 |
| 209 void ApplicationManager::HandleFetchCallback( | 212 void ApplicationManager::HandleFetchCallback( |
| 210 scoped_ptr<ConnectToApplicationParams> params, | 213 scoped_ptr<ConnectToApplicationParams> params, |
| 211 scoped_ptr<Fetcher> fetcher) { | 214 scoped_ptr<Fetcher> fetcher) { |
| 212 if (!fetcher) { | 215 if (!fetcher) { |
| 213 // Network error. Drop |params| to tell the requestor. | 216 // Network error. Drop |params| to tell the requestor. |
| 214 params->connect_callback().Run(Shell::kInvalidContentHandlerID); | 217 params->connect_callback().Run(Shell::kInvalidApplicationID, |
| 218 Shell::kInvalidApplicationID); |
| 215 return; | 219 return; |
| 216 } | 220 } |
| 217 | 221 |
| 218 GURL redirect_url = fetcher->GetRedirectURL(); | 222 GURL redirect_url = fetcher->GetRedirectURL(); |
| 219 if (!redirect_url.is_empty()) { | 223 if (!redirect_url.is_empty()) { |
| 220 // And around we go again... Whee! | 224 // And around we go again... Whee! |
| 221 // TODO(sky): this loses the original URL info. | 225 // TODO(sky): this loses the original URL info. |
| 222 URLRequestPtr new_request = URLRequest::New(); | 226 URLRequestPtr new_request = URLRequest::New(); |
| 223 new_request->url = redirect_url.spec(); | 227 new_request->url = redirect_url.spec(); |
| 224 HttpHeaderPtr header = HttpHeader::New(); | 228 HttpHeaderPtr header = HttpHeader::New(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 240 Identity target = params->target(); | 244 Identity target = params->target(); |
| 241 Shell::ConnectToApplicationCallback connect_callback = | 245 Shell::ConnectToApplicationCallback connect_callback = |
| 242 params->connect_callback(); | 246 params->connect_callback(); |
| 243 params->set_connect_callback(EmptyConnectCallback()); | 247 params->set_connect_callback(EmptyConnectCallback()); |
| 244 ApplicationInstance* app = nullptr; | 248 ApplicationInstance* app = nullptr; |
| 245 InterfaceRequest<Application> request( | 249 InterfaceRequest<Application> request( |
| 246 CreateAndConnectToInstance(std::move(params), &app)); | 250 CreateAndConnectToInstance(std::move(params), &app)); |
| 247 | 251 |
| 248 uint32_t content_handler_id = package_manager_->HandleWithContentHandler( | 252 uint32_t content_handler_id = package_manager_->HandleWithContentHandler( |
| 249 fetcher.get(), source, target.url(), target.filter(), &request); | 253 fetcher.get(), source, target.url(), target.filter(), &request); |
| 250 if (content_handler_id != Shell::kInvalidContentHandlerID) { | 254 if (content_handler_id != Shell::kInvalidApplicationID) { |
| 251 app->set_requesting_content_handler_id(content_handler_id); | 255 app->set_requesting_content_handler_id(content_handler_id); |
| 252 connect_callback.Run(content_handler_id); | 256 connect_callback.Run(app->id(), content_handler_id); |
| 253 return; | 257 return; |
| 254 } | 258 } |
| 255 | 259 |
| 256 // TODO(erg): Have a better way of switching the sandbox on. For now, switch | 260 // TODO(erg): Have a better way of switching the sandbox on. For now, switch |
| 257 // it on hard coded when we're using some of the sandboxable core services. | 261 // it on hard coded when we're using some of the sandboxable core services. |
| 258 bool start_sandboxed = false; | 262 bool start_sandboxed = false; |
| 259 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 263 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 260 switches::kMojoNoSandbox)) { | 264 switches::kMojoNoSandbox)) { |
| 261 start_sandboxed = (target.url() == GURL("mojo://core_services/") && | 265 start_sandboxed = (target.url() == GURL("mojo://core_services/") && |
| 262 target.qualifier() == "Core") || | 266 target.qualifier() == "Core") || |
| 263 target.url() == GURL("mojo://html_viewer/"); | 267 target.url() == GURL("mojo://html_viewer/"); |
| 264 } | 268 } |
| 265 | 269 |
| 266 connect_callback.Run(Shell::kInvalidContentHandlerID); | 270 connect_callback.Run(app->id(), Shell::kInvalidApplicationID); |
| 267 | 271 |
| 268 fetcher->AsPath( | 272 fetcher->AsPath( |
| 269 task_runner_, | 273 task_runner_, |
| 270 base::Bind(&ApplicationManager::RunNativeApplication, | 274 base::Bind(&ApplicationManager::RunNativeApplication, |
| 271 weak_ptr_factory_.GetWeakPtr(), | 275 weak_ptr_factory_.GetWeakPtr(), |
| 272 base::Passed(std::move(request)), start_sandboxed, | 276 base::Passed(std::move(request)), start_sandboxed, |
| 273 base::Passed(std::move(fetcher)), base::Unretained(app))); | 277 base::Passed(std::move(fetcher)), base::Unretained(app))); |
| 274 } | 278 } |
| 275 | 279 |
| 276 void ApplicationManager::RunNativeApplication( | 280 void ApplicationManager::RunNativeApplication( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 362 } |
| 359 } | 363 } |
| 360 } | 364 } |
| 361 | 365 |
| 362 Shell::ConnectToApplicationCallback EmptyConnectCallback() { | 366 Shell::ConnectToApplicationCallback EmptyConnectCallback() { |
| 363 return base::Bind(&OnEmptyOnConnectCallback); | 367 return base::Bind(&OnEmptyOnConnectCallback); |
| 364 } | 368 } |
| 365 | 369 |
| 366 } // namespace shell | 370 } // namespace shell |
| 367 } // namespace mojo | 371 } // namespace mojo |
| OLD | NEW |