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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/application/application.h" 5 #include "mojo/services/test_service/test_service_application.h"
6 #include "mojo/public/cpp/system/macros.h" 6
7 #include <assert.h>
8
9 #include "mojo/public/cpp/utility/run_loop.h"
7 #include "mojo/services/test_service/test_service_impl.h" 10 #include "mojo/services/test_service/test_service_impl.h"
8 11
9 namespace mojo { 12 namespace mojo {
10 namespace test { 13 namespace test {
11 namespace {
12 14
13 class TestServiceApplication : public Application { 15 TestServiceApplication::TestServiceApplication() : ref_count_(0) {
14 public: 16 }
15 TestServiceApplication() {}
16 virtual ~TestServiceApplication() {}
17 17
18 virtual void Initialize() MOJO_OVERRIDE { 18 TestServiceApplication::~TestServiceApplication() {
19 AddService<TestServiceImpl>(); 19 }
20 }
21 20
22 private: 21 void TestServiceApplication::Initialize() {
23 MOJO_DISALLOW_COPY_AND_ASSIGN(TestServiceApplication); 22 AddService<TestServiceImpl>(this);
24 }; 23 }
25 24
26 } // namespace 25 void TestServiceApplication::AddRef() {
26 assert(ref_count_ >= 0);
27 ref_count_++;
28 }
29
30 void TestServiceApplication::ReleaseRef() {
31 assert(ref_count_ > 0);
32 ref_count_--;
33 if (ref_count_ <= 0)
34 RunLoop::current()->Quit();
35 }
36
27 } // namespace test 37 } // namespace test
28 38
29 // static 39 // static
30 Application* Application::Create() { 40 Application* Application::Create() {
31 return new mojo::test::TestServiceApplication(); 41 return new mojo::test::TestServiceApplication();
32 } 42 }
33 43
34 } // namespace mojo 44 } // namespace mojo
OLDNEW
« 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