summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-04 18:29:48 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-04 18:29:48 +0000
commitd656e1042e3bc0cbe3f35ab34a193904763a2f8b (patch)
treed2e58c6bf158c53250928265f9c061745e7f84b3 /mojo
parentecc5f2ed558344ab1fa0b0e0c3b97395a50cad03 (diff)
downloadchromium_src-d656e1042e3bc0cbe3f35ab34a193904763a2f8b.zip
chromium_src-d656e1042e3bc0cbe3f35ab34a193904763a2f8b.tar.gz
chromium_src-d656e1042e3bc0cbe3f35ab34a193904763a2f8b.tar.bz2
Add ServiceManager::GetInstance() and change ServiceManager::Loader to ServiceLoader
BUG=None TESTS=Existing R=darin@chromium.org, darin Review URL: https://codereview.chromium.org/185553012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254783 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/mojo.gyp5
-rw-r--r--mojo/service_manager/service_loader.h29
-rw-r--r--mojo/service_manager/service_manager.cc22
-rw-r--r--mojo/service_manager/service_manager.h28
-rw-r--r--mojo/service_manager/service_manager_unittest.cc11
-rw-r--r--mojo/shell/android/mojo_main.cc8
-rw-r--r--mojo/shell/dynamic_service_loader.cc5
-rw-r--r--mojo/shell/dynamic_service_loader.h9
8 files changed, 76 insertions, 41 deletions
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 3625682..9bbbaa9 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -336,14 +336,19 @@
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
+ '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../net/net.gyp:net',
'../url/url.gyp:url_lib',
'mojo_shell_bindings',
],
'sources': [
+ 'service_manager/service_loader.h',
'service_manager/service_manager.cc',
'service_manager/service_manager.h',
],
+ 'export_dependent_settings': [
+ '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
+ ],
},
{
'target_name': 'mojo_shell_lib',
diff --git a/mojo/service_manager/service_loader.h b/mojo/service_manager/service_loader.h
new file mode 100644
index 0000000..7da0540
--- /dev/null
+++ b/mojo/service_manager/service_loader.h
@@ -0,0 +1,29 @@
+// Copyright 2014 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_SERVICE_MANAGER_SERVICE_LOADER_H_
+#define MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_
+
+#include "mojo/public/shell/shell.mojom.h"
+#include "url/gurl.h"
+
+namespace mojo {
+
+class ServiceManager;
+
+// Interface to allowing default loading behavior to be overridden for a
+// specific url.
+class ServiceLoader {
+ public:
+ virtual ~ServiceLoader() {};
+ virtual void LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedShellHandle service_handle) = 0;
+ protected:
+ ServiceLoader() {}
+};
+
+} // namespace mojo
+
+#endif // MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_
diff --git a/mojo/service_manager/service_manager.cc b/mojo/service_manager/service_manager.cc
index bfc2bd7..0f63478 100644
--- a/mojo/service_manager/service_manager.cc
+++ b/mojo/service_manager/service_manager.cc
@@ -4,13 +4,14 @@
#include "mojo/service_manager/service_manager.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/error_handler.h"
#include "mojo/public/bindings/remote_ptr.h"
+#include "mojo/service_manager/service_loader.h"
namespace mojo {
-namespace shell {
class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
public:
@@ -19,7 +20,9 @@ class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
url_(url) {
InterfacePipe<Shell> pipe;
shell_client_.reset(pipe.handle_to_peer.Pass(), this, this);
- manager_->GetLoaderForURL(url)->Load(url, pipe.handle_to_self.Pass());
+ manager_->GetLoaderForURL(url)->LoadService(manager_,
+ url,
+ pipe.handle_to_self.Pass());
}
virtual ~ServiceFactory() {}
@@ -48,9 +51,6 @@ class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
};
-ServiceManager::Loader::Loader() {}
-ServiceManager::Loader::~Loader() {}
-
bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
return manager_->url_to_service_factory_.find(url) !=
manager_->url_to_service_factory_.end();
@@ -67,12 +67,19 @@ ServiceManager::~ServiceManager() {
url_to_service_factory_.clear();
}
-void ServiceManager::SetLoaderForURL(Loader* loader, const GURL& gurl) {
+// static
+ServiceManager* GetInstance() {
+ static base::LazyInstance<ServiceManager> instance =
+ LAZY_INSTANCE_INITIALIZER;
+ return &instance.Get();
+}
+
+void ServiceManager::SetLoaderForURL(ServiceLoader* loader, const GURL& gurl) {
DCHECK(url_to_loader_.find(gurl) == url_to_loader_.end());
url_to_loader_[gurl] = loader;
}
-ServiceManager::Loader* ServiceManager::GetLoaderForURL(const GURL& gurl) {
+ServiceLoader* ServiceManager::GetLoaderForURL(const GURL& gurl) {
LoaderMap::const_iterator it = url_to_loader_.find(gurl);
if (it != url_to_loader_.end())
return it->second;
@@ -102,5 +109,4 @@ void ServiceManager::RemoveServiceFactory(ServiceFactory* service_factory) {
url_to_service_factory_.erase(it);
}
-} // namespace shell
} // namespace mojo
diff --git a/mojo/service_manager/service_manager.h b/mojo/service_manager/service_manager.h
index 4c7cfd58..c05e177 100644
--- a/mojo/service_manager/service_manager.h
+++ b/mojo/service_manager/service_manager.h
@@ -10,24 +10,14 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "mojo/public/shell/shell.mojom.h"
-#include "mojo/public/system/core_cpp.h"
#include "url/gurl.h"
namespace mojo {
-namespace shell {
+
+class ServiceLoader;
class ServiceManager {
public:
- // Interface to allowing default loading behavior to be overridden for a
- // specific url.
- class Loader {
- public:
- virtual ~Loader();
- virtual void Load(const GURL& url, ScopedShellHandle service_handle) = 0;
- protected:
- Loader();
- };
-
// API for testing.
class TestAPI {
private:
@@ -42,14 +32,17 @@ class ServiceManager {
ServiceManager();
~ServiceManager();
+ // Returns a shared instance, creating it if necessary.
+ static ServiceManager* GetInstance();
+
// Sets the default Loader to be used if not overridden by SetLoaderForURL().
// Does not take ownership of |loader|.
- void set_default_loader(Loader* loader) { default_loader_ = loader; }
+ void set_default_loader(ServiceLoader* loader) { default_loader_ = loader; }
// Sets a Loader to be used for a specific url.
// Does not take ownership of |loader|.
- void SetLoaderForURL(Loader* loader, const GURL& gurl);
+ void SetLoaderForURL(ServiceLoader* loader, const GURL& gurl);
// Returns the Loader to use for a url (using default if not overridden.)
- Loader* GetLoaderForURL(const GURL& gurl);
+ ServiceLoader* GetLoaderForURL(const GURL& gurl);
// Loads a service if necessary and establishes a new client connection.
void Connect(const GURL& url, ScopedMessagePipeHandle client_handle);
@@ -59,15 +52,14 @@ class ServiceManager {
// Removes a ServiceFactory when it no longer has any connections.
void RemoveServiceFactory(ServiceFactory* service_factory);
- Loader* default_loader_;
+ ServiceLoader* default_loader_;
typedef std::map<GURL, ServiceFactory*> ServiceFactoryMap;
ServiceFactoryMap url_to_service_factory_;
- typedef std::map<GURL, Loader*> LoaderMap;
+ typedef std::map<GURL, ServiceLoader*> LoaderMap;
LoaderMap url_to_loader_;
DISALLOW_COPY_AND_ASSIGN(ServiceManager);
};
-} // namespace shell
} // namespace mojo
#endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_H_
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc
index fba2044..6941be6 100644
--- a/mojo/service_manager/service_manager_unittest.cc
+++ b/mojo/service_manager/service_manager_unittest.cc
@@ -8,12 +8,12 @@
#include "mojo/public/shell/application.h"
#include "mojo/public/shell/shell.mojom.h"
#include "mojo/public/utility/run_loop.h"
+#include "mojo/service_manager/service_loader.h"
#include "mojo/service_manager/service_manager.h"
#include "mojo/service_manager/test.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
-namespace shell {
namespace {
const char kTestURLString[] = "test:testService";
@@ -73,8 +73,7 @@ class TestClientImpl : public TestClient {
};
} // namespace
-class ServiceManagerTest : public testing::Test,
- public ServiceManager::Loader {
+class ServiceManagerTest : public testing::Test, public ServiceLoader {
public:
ServiceManagerTest() {}
@@ -96,8 +95,9 @@ class ServiceManagerTest : public testing::Test,
service_manager_.reset(NULL);
}
- virtual void Load(const GURL& url,
- ScopedShellHandle shell_handle) OVERRIDE {
+ virtual void LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedShellHandle shell_handle) OVERRIDE {
test_app_.reset(new Application(shell_handle.Pass()));
test_app_->AddServiceFactory(
new ServiceFactory<TestServiceImpl, TestContext>(&context_));
@@ -134,5 +134,4 @@ TEST_F(ServiceManagerTest, ClientError) {
EXPECT_EQ(0, context_.num_impls);
EXPECT_FALSE(HasFactoryForTestURL());
}
-} // namespace shell
} // namespace mojo
diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc
index 987cdfd..55fa8111 100644
--- a/mojo/shell/android/mojo_main.cc
+++ b/mojo/shell/android/mojo_main.cc
@@ -13,6 +13,7 @@
#include "base/message_loop/message_loop.h"
#include "jni/MojoMain_jni.h"
#include "mojo/public/shell/application.h"
+#include "mojo/service_manager/service_loader.h"
#include "mojo/service_manager/service_manager.h"
#include "mojo/services/native_viewport/native_viewport_service.h"
#include "mojo/shell/context.h"
@@ -32,14 +33,15 @@ LazyInstance<scoped_ptr<base::MessageLoop> > g_java_message_loop =
LazyInstance<scoped_ptr<shell::Context> > g_context =
LAZY_INSTANCE_INITIALIZER;
-class NativeViewportServiceLoader : public shell::ServiceManager::Loader {
+class NativeViewportServiceLoader : public ServiceLoader {
public:
NativeViewportServiceLoader() {}
virtual ~NativeViewportServiceLoader() {}
private:
- virtual void Load(const GURL& url,
- ScopedShellHandle service_handle)
+ virtual void LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedShellHandle service_handle)
MOJO_OVERRIDE {
app_.reset(CreateNativeViewportService(g_context.Get().get(),
service_handle.Pass()));
diff --git a/mojo/shell/dynamic_service_loader.cc b/mojo/shell/dynamic_service_loader.cc
index 4168fdf..7d5e8a4 100644
--- a/mojo/shell/dynamic_service_loader.cc
+++ b/mojo/shell/dynamic_service_loader.cc
@@ -130,8 +130,9 @@ DynamicServiceLoader::~DynamicServiceLoader() {
DCHECK(url_to_load_context_.empty());
}
-void DynamicServiceLoader::Load(const GURL& url,
- ScopedShellHandle service_handle) {
+void DynamicServiceLoader::LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedShellHandle service_handle) {
DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end());
url_to_load_context_[url] = new LoadContext(this, url, service_handle.Pass());
}
diff --git a/mojo/shell/dynamic_service_loader.h b/mojo/shell/dynamic_service_loader.h
index 7337e53..b6bd3c5 100644
--- a/mojo/shell/dynamic_service_loader.h
+++ b/mojo/shell/dynamic_service_loader.h
@@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "mojo/public/shell/shell.mojom.h"
#include "mojo/public/system/core_cpp.h"
-#include "mojo/service_manager/service_manager.h"
+#include "mojo/service_manager/service_loader.h"
#include "mojo/shell/keep_alive.h"
#include "url/gurl.h"
@@ -21,7 +21,7 @@ class Context;
// A subclass of ServiceManager::Loader that loads a dynamic library containing
// the implementation of the service.
-class DynamicServiceLoader : public ServiceManager::Loader {
+class DynamicServiceLoader : public ServiceLoader {
public:
explicit DynamicServiceLoader(Context* context);
virtual ~DynamicServiceLoader();
@@ -30,8 +30,9 @@ class DynamicServiceLoader : public ServiceManager::Loader {
// specified will be modified to the platform's naming scheme. Also the
// value specified to the --origin command line argument will be used as the
// host / port.
- virtual void Load(const GURL& url,
- ScopedShellHandle service_handle) MOJO_OVERRIDE;
+ virtual void LoadService(ServiceManager* manager,
+ const GURL& url,
+ ScopedShellHandle service_handle) MOJO_OVERRIDE;
private:
class LoadContext;