summaryrefslogtreecommitdiffstats
path: root/mojo/service_manager
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/service_manager
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/service_manager')
-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
4 files changed, 58 insertions, 32 deletions
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