summaryrefslogtreecommitdiffstats
path: root/mojo/shell
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/shell')
-rw-r--r--mojo/shell/BUILD.gn2
-rw-r--r--mojo/shell/application_instance.cc13
-rw-r--r--mojo/shell/application_manager.cc66
-rw-r--r--mojo/shell/application_manager.h44
-rw-r--r--mojo/shell/application_manager_unittest.cc41
-rw-r--r--mojo/shell/capability_filter_unittest.cc13
-rw-r--r--mojo/shell/connect_util.cc30
-rw-r--r--mojo/shell/connect_util.h39
8 files changed, 135 insertions, 113 deletions
diff --git a/mojo/shell/BUILD.gn b/mojo/shell/BUILD.gn
index 38fca1e..0d57c43 100644
--- a/mojo/shell/BUILD.gn
+++ b/mojo/shell/BUILD.gn
@@ -17,6 +17,8 @@ source_set("shell") {
"capability_filter.h",
"connect_to_application_params.cc",
"connect_to_application_params.h",
+ "connect_util.cc",
+ "connect_util.h",
"content_handler_connection.cc",
"content_handler_connection.h",
"data_pipe_peek.cc",
diff --git a/mojo/shell/application_instance.cc b/mojo/shell/application_instance.cc
index 18aa4e0..643cfa2 100644
--- a/mojo/shell/application_instance.cc
+++ b/mojo/shell/application_instance.cc
@@ -94,9 +94,16 @@ void ApplicationInstance::ConnectToApplication(
CapabilityFilter capability_filter = GetPermissiveCapabilityFilter();
if (!filter.is_null())
capability_filter = filter->filter.To<CapabilityFilter>();
- manager_->ConnectToApplication(
- this, app_request.Pass(), std::string(), services.Pass(),
- exposed_services.Pass(), capability_filter, base::Closure(), callback);
+
+ scoped_ptr<ConnectToApplicationParams> params(
+ new ConnectToApplicationParams);
+ params->SetOriginatorInfo(this);
+ params->SetURLInfo(app_request.Pass());
+ params->set_services(services.Pass());
+ params->set_exposed_services(exposed_services.Pass());
+ params->set_filter(capability_filter);
+ params->set_connect_callback(callback);
+ manager_->ConnectToApplication(params.Pass());
} else {
LOG(WARNING) << "CapabilityFilter prevented connection from: " <<
identity_.url << " to: " << url.spec();
diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc
index d520304..715e6e7 100644
--- a/mojo/shell/application_manager.cc
+++ b/mojo/shell/application_manager.cc
@@ -59,8 +59,9 @@ ApplicationManager::ApplicationManager(
}
ApplicationManager::~ApplicationManager() {
- URLToContentHandlerMap url_to_content_handler(url_to_content_handler_);
- for (auto& pair : url_to_content_handler)
+ IdentityToContentHandlerMap identity_to_content_handler(
+ identity_to_content_handler_);
+ for (auto& pair : identity_to_content_handler)
pair.second->CloseConnection();
TerminateShellConnections();
STLDeleteValues(&url_to_loader_);
@@ -71,28 +72,6 @@ void ApplicationManager::TerminateShellConnections() {
}
void ApplicationManager::ConnectToApplication(
- ApplicationInstance* originator,
- URLRequestPtr app_url_request,
- const std::string& qualifier,
- InterfaceRequest<ServiceProvider> services,
- ServiceProviderPtr exposed_services,
- const CapabilityFilter& filter,
- const base::Closure& on_application_end,
- const Shell::ConnectToApplicationCallback& connect_callback) {
- scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
- params->SetOriginatorInfo(originator);
- params->SetURLInfo(app_url_request.Pass());
- params->set_qualifier(qualifier);
- params->set_services(services.Pass());
- params->set_exposed_services(exposed_services.Pass());
- params->set_filter(filter);
- params->set_on_application_end(on_application_end);
- params->set_connect_callback(connect_callback);
-
- ConnectToApplication(params.Pass());
-}
-
-void ApplicationManager::ConnectToApplication(
scoped_ptr<ConnectToApplicationParams> params) {
GURL original_url = params->app_url();
URLRequestPtr original_url_request = params->TakeAppURLRequest();
@@ -148,10 +127,10 @@ void ApplicationManager::ConnectToApplicationWithLoader(
if (!(*params)->app_url().SchemeIs("mojo"))
(*params)->SetURLInfo(resolved_url);
- loader->Load(resolved_url, RegisterInstance(params->Pass(), nullptr));
+ loader->Load(resolved_url, CreateInstance(params->Pass(), nullptr));
}
-InterfaceRequest<Application> ApplicationManager::RegisterInstance(
+InterfaceRequest<Application> ApplicationManager::CreateInstance(
scoped_ptr<ConnectToApplicationParams> params,
ApplicationInstance** resulting_instance) {
Identity app_identity(params->app_url(), params->qualifier());
@@ -225,7 +204,7 @@ void ApplicationManager::HandleFetchCallback(
params->connect_callback();
params->set_connect_callback(EmptyConnectCallback());
ApplicationInstance* app = nullptr;
- InterfaceRequest<Application> request(RegisterInstance(params.Pass(), &app));
+ InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app));
GURL content_handler_url;
@@ -299,17 +278,18 @@ void ApplicationManager::LoadWithContentHandler(
InterfaceRequest<Application> application_request,
URLResponsePtr url_response) {
ContentHandlerConnection* connection = nullptr;
- std::pair<GURL, std::string> key(content_handler_url, qualifier);
+ Identity content_handler_identity(content_handler_url, qualifier);
// TODO(beng): Figure out the extent to which capability filter should be
// factored into handler identity.
- URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key);
- if (iter != url_to_content_handler_.end()) {
+ IdentityToContentHandlerMap::iterator iter =
+ identity_to_content_handler_.find(content_handler_identity);
+ if (iter != identity_to_content_handler_.end()) {
connection = iter->second;
} else {
connection = new ContentHandlerConnection(
this, originator_identity, originator_filter, content_handler_url,
qualifier, filter, ++content_handler_id_counter_);
- url_to_content_handler_[key] = connection;
+ identity_to_content_handler_[content_handler_identity] = connection;
}
app->set_requesting_content_handler_id(connection->id());
@@ -350,11 +330,11 @@ void ApplicationManager::OnApplicationInstanceError(
void ApplicationManager::OnContentHandlerConnectionClosed(
ContentHandlerConnection* content_handler) {
// Remove the mapping to the content handler.
- auto it = url_to_content_handler_.find(
- std::make_pair(content_handler->content_handler_url(),
- content_handler->content_handler_qualifier()));
- DCHECK(it != url_to_content_handler_.end());
- url_to_content_handler_.erase(it);
+ auto it = identity_to_content_handler_.find(
+ Identity(content_handler->content_handler_url(),
+ content_handler->content_handler_qualifier()));
+ DCHECK(it != identity_to_content_handler_.end());
+ identity_to_content_handler_.erase(it);
}
void ApplicationManager::CleanupRunner(NativeRunner* runner) {
@@ -362,20 +342,6 @@ void ApplicationManager::CleanupRunner(NativeRunner* runner) {
std::find(native_runners_.begin(), native_runners_.end(), runner));
}
-ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
- const GURL& application_url,
- const std::string& interface_name) {
- ServiceProviderPtr services;
- scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
- params->SetURLInfo(application_url);
- params->set_services(GetProxy(&services));
- params->set_filter(GetPermissiveCapabilityFilter());
- ConnectToApplication(params.Pass());
- MessagePipe pipe;
- services->ConnectToService(interface_name, pipe.handle1.Pass());
- return pipe.handle0.Pass();
-}
-
Shell::ConnectToApplicationCallback EmptyConnectCallback() {
return base::Bind(&OnEmptyOnConnectCallback);
}
diff --git a/mojo/shell/application_manager.h b/mojo/shell/application_manager.h
index 0ec2a6e..25b23a55 100644
--- a/mojo/shell/application_manager.h
+++ b/mojo/shell/application_manager.h
@@ -16,7 +16,6 @@
#include "mojo/application/public/interfaces/shell.mojom.h"
#include "mojo/public/cpp/bindings/interface_ptr_info.h"
#include "mojo/public/cpp/bindings/interface_request.h"
-#include "mojo/services/updater/updater.mojom.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/capability_filter.h"
#include "mojo/shell/connect_to_application_params.h"
@@ -59,33 +58,10 @@ class ApplicationManager {
~ApplicationManager();
// Loads a service if necessary and establishes a new client connection.
- // |originator| can be NULL (e.g. for the first application or in tests), but
- // typically is non-NULL and identifies the instance initiating the
- // connection.
// Please see the comments in connect_to_application_params.h for more details
// about the parameters.
- void ConnectToApplication(
- ApplicationInstance* originator,
- URLRequestPtr app_url_request,
- const std::string& qualifier,
- InterfaceRequest<ServiceProvider> services,
- ServiceProviderPtr exposed_services,
- const CapabilityFilter& filter,
- const base::Closure& on_application_end,
- const Shell::ConnectToApplicationCallback& connect_callback);
-
void ConnectToApplication(scoped_ptr<ConnectToApplicationParams> params);
- // Must only be used by shell internals and test code as it does not forward
- // capability filters.
- template <typename Interface>
- inline void ConnectToService(const GURL& application_url,
- InterfacePtr<Interface>* ptr) {
- ScopedMessagePipeHandle service_handle =
- ConnectToServiceByName(application_url, Interface::Name_);
- ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u));
- }
-
// Sets the default Loader to be used if not overridden by SetLoaderForURL().
void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
default_loader_ = loader.Pass();
@@ -115,10 +91,9 @@ class ApplicationManager {
ApplicationInstance* GetApplicationInstance(const Identity& identity) const;
private:
- using IdentityToApplicationInstanceMap =
- std::map<Identity, ApplicationInstance*>;
- using URLToContentHandlerMap =
- std::map<std::pair<GURL, std::string>, ContentHandlerConnection*>;
+ using IdentityToInstanceMap = std::map<Identity, ApplicationInstance*>;
+ using IdentityToContentHandlerMap =
+ std::map<Identity, ContentHandlerConnection*>;
using URLToLoaderMap = std::map<GURL, ApplicationLoader*>;
// Takes the contents of |params| only when it returns true.
@@ -133,9 +108,9 @@ class ApplicationManager {
const GURL& resolved_url,
ApplicationLoader* loader);
- InterfaceRequest<Application> RegisterInstance(
+ InterfaceRequest<Application> CreateInstance(
scoped_ptr<ConnectToApplicationParams> params,
- ApplicationInstance** resulting_instance);
+ ApplicationInstance** instance);
// Called once |fetcher| has found app. |params->app_url()| is the url of
// the requested application before any mappings/resolution have been applied.
@@ -166,10 +141,6 @@ class ApplicationManager {
void CleanupRunner(NativeRunner* runner);
- ScopedMessagePipeHandle ConnectToServiceByName(
- const GURL& application_url,
- const std::string& interface_name);
-
scoped_ptr<PackageManager> const package_manager_;
// Loader management.
// Loaders are chosen in the order they are listed here.
@@ -177,11 +148,10 @@ class ApplicationManager {
scoped_ptr<ApplicationLoader> default_loader_;
scoped_ptr<NativeRunnerFactory> native_runner_factory_;
- IdentityToApplicationInstanceMap identity_to_instance_;
- URLToContentHandlerMap url_to_content_handler_;
+ IdentityToInstanceMap identity_to_instance_;
+ IdentityToContentHandlerMap identity_to_content_handler_;
base::SequencedWorkerPool* blocking_pool_;
- updater::UpdaterPtr updater_;
ScopedVector<NativeRunner> native_runners_;
// Counter used to assign ids to content_handlers.
uint32_t content_handler_id_counter_;
diff --git a/mojo/shell/application_manager_unittest.cc b/mojo/shell/application_manager_unittest.cc
index 77a959c..c626b01 100644
--- a/mojo/shell/application_manager_unittest.cc
+++ b/mojo/shell/application_manager_unittest.cc
@@ -17,6 +17,7 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/shell/application_loader.h"
#include "mojo/shell/application_manager.h"
+#include "mojo/shell/connect_util.h"
#include "mojo/shell/fetcher.h"
#include "mojo/shell/test.mojom.h"
#include "mojo/shell/test_package_manager.h"
@@ -512,8 +513,8 @@ class ApplicationManagerTest : public testing::Test {
scoped_ptr<ApplicationLoader>(test_loader_));
TestServicePtr service_proxy;
- application_manager_->ConnectToService(GURL(kTestURLString),
- &service_proxy);
+ ConnectToService(application_manager_.get(), GURL(kTestURLString),
+ &service_proxy);
test_client_.reset(new TestClient(service_proxy.Pass()));
}
@@ -589,12 +590,14 @@ TEST_F(ApplicationManagerTest, SetLoaders) {
// test::test1 should go to url_loader.
TestServicePtr test_service;
- application_manager_->ConnectToService(GURL("test:test1"), &test_service);
+ ConnectToService(application_manager_.get(), GURL("test:test1"),
+ &test_service);
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(0, default_loader->num_loads());
// http::test1 should go to default loader.
- application_manager_->ConnectToService(GURL("http:test1"), &test_service);
+ ConnectToService(application_manager_.get(), GURL("http:test1"),
+ &test_service);
EXPECT_EQ(1, url_loader->num_loads());
EXPECT_EQ(1, default_loader->num_loads());
}
@@ -609,7 +612,7 @@ TEST_F(ApplicationManagerTest, ACallB) {
AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
TestAPtr a;
- application_manager_->ConnectToService(GURL(kTestAURLString), &a);
+ ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
a->CallB();
loop_.Run();
EXPECT_EQ(1, tester_context_.num_b_calls());
@@ -625,7 +628,7 @@ TEST_F(ApplicationManagerTest, BCallC) {
AddLoaderForURL(GURL(kTestBURLString), kTestAURLString);
TestAPtr a;
- application_manager_->ConnectToService(GURL(kTestAURLString), &a);
+ ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
a->CallCFromB();
loop_.Run();
@@ -641,7 +644,7 @@ TEST_F(ApplicationManagerTest, BDeleted) {
AddLoaderForURL(GURL(kTestBURLString), std::string());
TestAPtr a;
- application_manager_->ConnectToService(GURL(kTestAURLString), &a);
+ ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
a->CallB();
loop_.Run();
@@ -664,7 +667,7 @@ TEST_F(ApplicationManagerTest, ANoLoadB) {
AddLoaderForURL(GURL(kTestBURLString), "test:TestC");
TestAPtr a;
- application_manager_->ConnectToService(GURL(kTestAURLString), &a);
+ ConnectToService(application_manager_.get(), GURL(kTestAURLString), &a);
a->CallB();
loop_.Run();
EXPECT_EQ(0, tester_context_.num_b_calls());
@@ -679,7 +682,7 @@ TEST_F(ApplicationManagerTest, NoServiceNoLoad) {
// There is no TestC service implementation registered with
// ApplicationManager, so this cannot succeed (but also shouldn't crash).
TestCPtr c;
- application_manager_->ConnectToService(GURL(kTestAURLString), &c);
+ ConnectToService(application_manager_.get(), GURL(kTestAURLString), &c);
c.set_connection_error_handler(
[]() { base::MessageLoop::current()->QuitWhenIdle(); });
@@ -742,29 +745,29 @@ TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
EXPECT_EQ(1, test_loader_->num_loads());
TestServicePtr test_service;
- application_manager_->ConnectToService(GURL("http://www.example.org/abc?def"),
- &test_service);
+ ConnectToService(application_manager_.get(),
+ GURL("http://www.example.org/abc?def"), &test_service);
EXPECT_EQ(2, test_loader_->num_loads());
// Exactly the same URL as above.
- application_manager_->ConnectToService(GURL("http://www.example.org/abc?def"),
- &test_service);
+ ConnectToService(application_manager_.get(),
+ GURL("http://www.example.org/abc?def"), &test_service);
EXPECT_EQ(2, test_loader_->num_loads());
// The same identity as the one above because only the query string is
// different.
- application_manager_->ConnectToService(GURL("http://www.example.org/abc"),
- &test_service);
+ ConnectToService(application_manager_.get(),
+ GURL("http://www.example.org/abc"), &test_service);
EXPECT_EQ(2, test_loader_->num_loads());
// A different identity because the path is different.
- application_manager_->ConnectToService(
- GURL("http://www.example.org/another_path"), &test_service);
+ ConnectToService(application_manager_.get(),
+ GURL("http://www.example.org/another_path"), &test_service);
EXPECT_EQ(3, test_loader_->num_loads());
// A different identity because the domain is different.
- application_manager_->ConnectToService(
- GURL("http://www.another_domain.org/abc"), &test_service);
+ ConnectToService(application_manager_.get(),
+ GURL("http://www.another_domain.org/abc"), &test_service);
EXPECT_EQ(4, test_loader_->num_loads());
}
diff --git a/mojo/shell/capability_filter_unittest.cc b/mojo/shell/capability_filter_unittest.cc
index 0c33a8f..1dbc35b 100644
--- a/mojo/shell/capability_filter_unittest.cc
+++ b/mojo/shell/capability_filter_unittest.cc
@@ -343,10 +343,15 @@ class CapabilityFilterTest : public testing::Test {
AddService<Validator>(validator_);
URLRequestPtr request(URLRequest::New());
request->url = String::From(url);
- application_manager_->ConnectToApplication(
- nullptr, request.Pass(), std::string(), GetProxy(&services),
- exposed_services.Pass(), filter,
- base::MessageLoop::QuitWhenIdleClosure(), EmptyConnectCallback());
+
+ scoped_ptr<ConnectToApplicationParams> params(
+ new ConnectToApplicationParams);
+ params->SetURLInfo(request.Pass());
+ params->set_services(GetProxy(&services));
+ params->set_exposed_services(exposed_services.Pass());
+ params->set_filter(filter);
+ params->set_on_application_end(base::MessageLoop::QuitWhenIdleClosure());
+ application_manager_->ConnectToApplication(params.Pass());
}
void InitValidator(const std::set<std::string>& expectations) {
diff --git a/mojo/shell/connect_util.cc b/mojo/shell/connect_util.cc
new file mode 100644
index 0000000..0bffc5a4
--- /dev/null
+++ b/mojo/shell/connect_util.cc
@@ -0,0 +1,30 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/connect_util.h"
+
+#include "mojo/shell/application_manager.h"
+#include "mojo/shell/capability_filter.h"
+#include "mojo/shell/connect_to_application_params.h"
+
+namespace mojo {
+namespace shell {
+
+ScopedMessagePipeHandle ConnectToServiceByName(
+ ApplicationManager* application_manager,
+ const GURL& application_url,
+ const std::string& interface_name) {
+ ServiceProviderPtr services;
+ scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams);
+ params->SetURLInfo(application_url);
+ params->set_services(GetProxy(&services));
+ params->set_filter(GetPermissiveCapabilityFilter());
+ application_manager->ConnectToApplication(params.Pass());
+ MessagePipe pipe;
+ services->ConnectToService(interface_name, pipe.handle1.Pass());
+ return pipe.handle0.Pass();
+}
+
+} // namespace shell
+} // namespace mojo
diff --git a/mojo/shell/connect_util.h b/mojo/shell/connect_util.h
new file mode 100644
index 0000000..780f7a9
--- /dev/null
+++ b/mojo/shell/connect_util.h
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SHELL_CONNECT_UTIL_H_
+#define MOJO_SHELL_CONNECT_UTIL_H_
+
+#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
+#include "third_party/mojo/src/mojo/public/cpp/system/handle.h"
+
+class GURL;
+
+namespace mojo {
+namespace shell {
+
+class ApplicationManager;
+
+ScopedMessagePipeHandle ConnectToServiceByName(
+ ApplicationManager* application_manager,
+ const GURL& application_url,
+ const std::string& interface_name);
+
+// Must only be used by shell internals and test code as it does not forward
+// capability filters.
+template <typename Interface>
+inline void ConnectToService(ApplicationManager* application_manager,
+ const GURL& application_url,
+ InterfacePtr<Interface>* ptr) {
+ ScopedMessagePipeHandle service_handle =
+ ConnectToServiceByName(application_manager, application_url,
+ Interface::Name_);
+ ptr->Bind(InterfacePtrInfo<Interface>(service_handle.Pass(), 0u));
+}
+
+} // namespace shell
+} // namespace mojo
+
+
+#endif // MOJO_SHELL_CONNECT_UTIL_H_