summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 21:26:29 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 21:26:29 +0000
commit88c8a27df0fb0f0090e321759c3400afeab591c6 (patch)
treefe67c0fb59c8b17fdadc62a1effa181190b6a565 /mojo
parent1bb5deb72789aacd9fbfa7ee636df01fa51cf615 (diff)
downloadchromium_src-88c8a27df0fb0f0090e321759c3400afeab591c6.zip
chromium_src-88c8a27df0fb0f0090e321759c3400afeab591c6.tar.gz
chromium_src-88c8a27df0fb0f0090e321759c3400afeab591c6.tar.bz2
Mojo: Make the TestService quit when there are no more connections.
(This makes mojo_shell_tests not hang.) R=sky@chromium.org Review URL: https://codereview.chromium.org/336483003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/mojo_services.gypi1
-rw-r--r--mojo/services/test_service/test_service_application.cc38
-rw-r--r--mojo/services/test_service/test_service_application.h33
-rw-r--r--mojo/services/test_service/test_service_impl.cc13
-rw-r--r--mojo/services/test_service/test_service_impl.h13
5 files changed, 81 insertions, 17 deletions
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index ee73af1..7fe3af6 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -358,6 +358,7 @@
'sources': [
'public/cpp/application/lib/mojo_main_standalone.cc',
'services/test_service/test_service_application.cc',
+ 'services/test_service/test_service_application.h',
'services/test_service/test_service_impl.cc',
'services/test_service/test_service_impl.h',
],
diff --git a/mojo/services/test_service/test_service_application.cc b/mojo/services/test_service/test_service_application.cc
index c2754c2..3737823 100644
--- a/mojo/services/test_service/test_service_application.cc
+++ b/mojo/services/test_service/test_service_application.cc
@@ -2,28 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/application/application.h"
-#include "mojo/public/cpp/system/macros.h"
+#include "mojo/services/test_service/test_service_application.h"
+
+#include <assert.h>
+
+#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/services/test_service/test_service_impl.h"
namespace mojo {
namespace test {
-namespace {
-class TestServiceApplication : public Application {
- public:
- TestServiceApplication() {}
- virtual ~TestServiceApplication() {}
+TestServiceApplication::TestServiceApplication() : ref_count_(0) {
+}
- virtual void Initialize() MOJO_OVERRIDE {
- AddService<TestServiceImpl>();
- }
+TestServiceApplication::~TestServiceApplication() {
+}
- private:
- MOJO_DISALLOW_COPY_AND_ASSIGN(TestServiceApplication);
-};
+void TestServiceApplication::Initialize() {
+ AddService<TestServiceImpl>(this);
+}
+
+void TestServiceApplication::AddRef() {
+ assert(ref_count_ >= 0);
+ ref_count_++;
+}
+
+void TestServiceApplication::ReleaseRef() {
+ assert(ref_count_ > 0);
+ ref_count_--;
+ if (ref_count_ <= 0)
+ RunLoop::current()->Quit();
+}
-} // namespace
} // namespace test
// static
diff --git a/mojo/services/test_service/test_service_application.h b/mojo/services/test_service/test_service_application.h
new file mode 100644
index 0000000..9f042c1
--- /dev/null
+++ b/mojo/services/test_service/test_service_application.h
@@ -0,0 +1,33 @@
+// 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_SERVICES_TEST_SERVICE_TEST_SERVICE_APPLICATION_H_
+#define MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_APPLICATION_H_
+
+#include "mojo/public/cpp/application/application.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace test {
+
+class TestServiceApplication : public Application {
+ public:
+ TestServiceApplication();
+ virtual ~TestServiceApplication();
+
+ virtual void Initialize() MOJO_OVERRIDE;
+
+ void AddRef();
+ void ReleaseRef();
+
+ private:
+ int ref_count_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(TestServiceApplication);
+};
+
+} // namespace test
+} // namespace mojo
+
+#endif // MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_APPLICATION_H_
diff --git a/mojo/services/test_service/test_service_impl.cc b/mojo/services/test_service/test_service_impl.cc
index b4e9c35..a38d619 100644
--- a/mojo/services/test_service/test_service_impl.cc
+++ b/mojo/services/test_service/test_service_impl.cc
@@ -4,15 +4,26 @@
#include "mojo/services/test_service/test_service_impl.h"
+#include "mojo/services/test_service/test_service_application.h"
+
namespace mojo {
namespace test {
-TestServiceImpl::TestServiceImpl() {
+TestServiceImpl::TestServiceImpl(TestServiceApplication* application)
+ : application_(application) {
}
TestServiceImpl::~TestServiceImpl() {
}
+void TestServiceImpl::OnConnectionEstablished() {
+ application_->AddRef();
+}
+
+void TestServiceImpl::OnConnectionError() {
+ application_->ReleaseRef();
+}
+
void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) {
callback.Run();
}
diff --git a/mojo/services/test_service/test_service_impl.h b/mojo/services/test_service/test_service_impl.h
index 78d0980..df2d4a1 100644
--- a/mojo/services/test_service/test_service_impl.h
+++ b/mojo/services/test_service/test_service_impl.h
@@ -2,25 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/application/application.h"
+#ifndef MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_IMPL_H_
+#define MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_IMPL_H_
+
#include "mojo/public/cpp/system/macros.h"
#include "mojo/services/test_service/test_service.mojom.h"
namespace mojo {
namespace test {
+class TestServiceApplication;
+
class TestServiceImpl : public InterfaceImpl<ITestService> {
public:
- TestServiceImpl();
+ explicit TestServiceImpl(TestServiceApplication* application);
virtual ~TestServiceImpl();
// |ITestService| methods:
+ virtual void OnConnectionEstablished() MOJO_OVERRIDE;
+ virtual void OnConnectionError() MOJO_OVERRIDE;
virtual void Ping(const mojo::Callback<void()>& callback) MOJO_OVERRIDE;
private:
+ TestServiceApplication* const application_;
+
MOJO_DISALLOW_COPY_AND_ASSIGN(TestServiceImpl);
};
} // namespace test
} // namespace mojo
+#endif // MOJO_SERVICES_TEST_SERVICE_TEST_SERVICE_IMPL_H_