Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: mojo/services/test_service/test_service_application.cc

Issue 336483003: Mojo: Make the TestService quit when there are no more connections. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops, forgot some stuff Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/test_service/test_service_application.cc
diff --git a/mojo/services/test_service/test_service_application.cc b/mojo/services/test_service/test_service_application.cc
index c2754c21f41d0ac8f519adb6ce45e8dba268a643..3737823c9d2947b78a8f9179eee970395033c85c 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
« no previous file with comments | « mojo/services/test_service/test_service_application.h ('k') | mojo/services/test_service/test_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698