summaryrefslogtreecommitdiffstats
path: root/mojo/service_manager
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-27 04:16:00 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-27 04:16:00 +0000
commit5d90df57ef7e51d47130b55bb9fa8477457f7c1c (patch)
tree4d322020e1044453e38dc9e0a35087c50b66a50d /mojo/service_manager
parenta79f5907951398486fb349332f429db45bb559e0 (diff)
downloadchromium_src-5d90df57ef7e51d47130b55bb9fa8477457f7c1c.zip
chromium_src-5d90df57ef7e51d47130b55bb9fa8477457f7c1c.tar.gz
chromium_src-5d90df57ef7e51d47130b55bb9fa8477457f7c1c.tar.bz2
Add creation of ServiceManager to Content (2nd try)
Original cl: https://codereview.chromium.org/187183002/ BUG= TBR=jam@chromium.org Review URL: https://codereview.chromium.org/213313004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/service_manager')
-rw-r--r--mojo/service_manager/service_loader.h5
-rw-r--r--mojo/service_manager/service_manager.cc24
-rw-r--r--mojo/service_manager/service_manager.h16
-rw-r--r--mojo/service_manager/service_manager_export.h32
-rw-r--r--mojo/service_manager/service_manager_unittest.cc12
5 files changed, 77 insertions, 12 deletions
diff --git a/mojo/service_manager/service_loader.h b/mojo/service_manager/service_loader.h
index 7da0540..6d5be9a 100644
--- a/mojo/service_manager/service_loader.h
+++ b/mojo/service_manager/service_loader.h
@@ -6,6 +6,7 @@
#define MOJO_SERVICE_MANAGER_SERVICE_LOADER_H_
#include "mojo/public/shell/shell.mojom.h"
+#include "mojo/service_manager/service_manager_export.h"
#include "url/gurl.h"
namespace mojo {
@@ -14,12 +15,14 @@ class ServiceManager;
// Interface to allowing default loading behavior to be overridden for a
// specific url.
-class ServiceLoader {
+class MOJO_SERVICE_MANAGER_EXPORT ServiceLoader {
public:
virtual ~ServiceLoader() {};
virtual void LoadService(ServiceManager* manager,
const GURL& url,
ScopedShellHandle service_handle) = 0;
+ virtual void OnServiceError(ServiceManager* manager, const GURL& url) = 0;
+
protected:
ServiceLoader() {}
};
diff --git a/mojo/service_manager/service_manager.cc b/mojo/service_manager/service_manager.cc
index b5843cf4..fe8575d 100644
--- a/mojo/service_manager/service_manager.cc
+++ b/mojo/service_manager/service_manager.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdio.h>
+
#include "mojo/service_manager/service_manager.h"
#include "base/lazy_instance.h"
@@ -14,6 +16,11 @@
namespace mojo {
+namespace {
+// Used by TestAPI.
+bool has_created_instance = false;
+}
+
class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
public:
ServiceFactory(ServiceManager* manager, const GURL& url)
@@ -40,7 +47,7 @@ class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
}
virtual void OnError() OVERRIDE {
- manager_->RemoveServiceFactory(this);
+ manager_->OnServiceFactoryError(this);
}
const GURL& url() const { return url_; }
@@ -52,6 +59,11 @@ class ServiceManager::ServiceFactory : public Shell, public ErrorHandler {
DISALLOW_COPY_AND_ASSIGN(ServiceFactory);
};
+// static
+bool ServiceManager::TestAPI::HasCreatedInstance() {
+ return has_created_instance;
+}
+
bool ServiceManager::TestAPI::HasFactoryForURL(const GURL& url) const {
return manager_->url_to_service_factory_.find(url) !=
manager_->url_to_service_factory_.end();
@@ -69,9 +81,10 @@ ServiceManager::~ServiceManager() {
}
// static
-ServiceManager* GetInstance() {
+ServiceManager* ServiceManager::GetInstance() {
static base::LazyInstance<ServiceManager> instance =
LAZY_INSTANCE_INITIALIZER;
+ has_created_instance = true;
return &instance.Get();
}
@@ -102,12 +115,13 @@ void ServiceManager::Connect(const GURL& url,
service_factory->ConnectToClient(client_handle.Pass());
}
-void ServiceManager::RemoveServiceFactory(ServiceFactory* service_factory) {
- ServiceFactoryMap::iterator it =
- url_to_service_factory_.find(service_factory->url());
+void ServiceManager::OnServiceFactoryError(ServiceFactory* service_factory) {
+ const GURL url = service_factory->url();
+ ServiceFactoryMap::iterator it = url_to_service_factory_.find(url);
DCHECK(it != url_to_service_factory_.end());
delete it->second;
url_to_service_factory_.erase(it);
+ GetLoaderForURL(url)->OnServiceError(this, url);
}
} // namespace mojo
diff --git a/mojo/service_manager/service_manager.h b/mojo/service_manager/service_manager.h
index c05e177..cf4c385 100644
--- a/mojo/service_manager/service_manager.h
+++ b/mojo/service_manager/service_manager.h
@@ -9,20 +9,30 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/gtest_prod_util.h"
#include "mojo/public/shell/shell.mojom.h"
+#include "mojo/service_manager/service_manager_export.h"
#include "url/gurl.h"
+namespace content {
+ class MojoTest;
+}
+
namespace mojo {
class ServiceLoader;
-class ServiceManager {
+class MOJO_SERVICE_MANAGER_EXPORT ServiceManager {
public:
// API for testing.
- class TestAPI {
+ class MOJO_SERVICE_MANAGER_EXPORT TestAPI {
private:
friend class ServiceManagerTest;
+ friend class content::MojoTest;
+
explicit TestAPI(ServiceManager* manager) : manager_(manager) {}
+ // Returns true if the shared instance has been created.
+ static bool HasCreatedInstance();
// Returns true if there is a ServiceFactory for this URL.
bool HasFactoryForURL(const GURL& url) const;
@@ -50,7 +60,7 @@ class ServiceManager {
class ServiceFactory;
// Removes a ServiceFactory when it no longer has any connections.
- void RemoveServiceFactory(ServiceFactory* service_factory);
+ void OnServiceFactoryError(ServiceFactory* service_factory);
ServiceLoader* default_loader_;
typedef std::map<GURL, ServiceFactory*> ServiceFactoryMap;
diff --git a/mojo/service_manager/service_manager_export.h b/mojo/service_manager/service_manager_export.h
new file mode 100644
index 0000000..251aad9
--- /dev/null
+++ b/mojo/service_manager/service_manager_export.h
@@ -0,0 +1,32 @@
+// 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_MANAGER_EXPORT_H_
+#define MOJO_SERVICE_MANAGER_SERVICE_MANAGER_EXPORT_H_
+
+#if defined(COMPONENT_BUILD)
+
+#if defined(WIN32)
+
+#if defined(MOJO_SERVICE_MANAGER_IMPLEMENTATION)
+#define MOJO_SERVICE_MANAGER_EXPORT __declspec(dllexport)
+#else
+#define MOJO_SERVICE_MANAGER_EXPORT __declspec(dllimport)
+#endif
+
+#else // !defined(WIN32)
+
+#if defined(MOJO_SERVICE_MANAGER_IMPLEMENTATION)
+#define MOJO_SERVICE_MANAGER_EXPORT __attribute__((visibility("default")))
+#else
+#define MOJO_SERVICE_MANAGER_EXPORT
+#endif
+
+#endif // defined(WIN32)
+
+#else // !defined(COMPONENT_BUILD)
+#define MOJO_SERVICE_MANAGER_EXPORT
+#endif
+
+#endif // MOJO_SERVICE_MANAGER_SERVICE_MANAGER_EXPORT_H_
diff --git a/mojo/service_manager/service_manager_unittest.cc b/mojo/service_manager/service_manager_unittest.cc
index 6941be6..26273e7 100644
--- a/mojo/service_manager/service_manager_unittest.cc
+++ b/mojo/service_manager/service_manager_unittest.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop/message_loop.h"
#include "mojo/public/bindings/allocation_scope.h"
#include "mojo/public/bindings/remote_ptr.h"
#include "mojo/public/environment/environment.h"
#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"
@@ -57,7 +57,7 @@ class TestClientImpl : public TestClient {
virtual void AckTest() OVERRIDE {
if (quit_after_ack_)
- mojo::RunLoop::current()->Quit();
+ base::MessageLoop::current()->Quit();
}
void Test(std::string test_string) {
@@ -103,6 +103,12 @@ class ServiceManagerTest : public testing::Test, public ServiceLoader {
new ServiceFactory<TestServiceImpl, TestContext>(&context_));
}
+ virtual void OnServiceError(ServiceManager* manager,
+ const GURL& url) OVERRIDE {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::MessageLoop::QuitClosure());
+ }
+
bool HasFactoryForTestURL() {
ServiceManager::TestAPI manager_test_api(service_manager_.get());
return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
@@ -110,7 +116,7 @@ class ServiceManagerTest : public testing::Test, public ServiceLoader {
protected:
mojo::Environment env_;
- mojo::RunLoop loop_;
+ base::MessageLoop loop_;
TestContext context_;
scoped_ptr<Application> test_app_;
scoped_ptr<TestClientImpl> test_client_;