Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / mojo / services / test_service / test_service_application.cc
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
3 // found in the LICENSE file.
4
5 #include "mojo/services/test_service/test_service_application.h"
6
7 #include <assert.h>
8
9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/utility/run_loop.h"
11 #include "mojo/services/test_service/test_service_impl.h"
12 #include "mojo/services/test_service/test_time_service_impl.h"
13
14 namespace mojo {
15 namespace test {
16
17 TestServiceApplication::TestServiceApplication() : ref_count_(0) {
18 }
19
20 TestServiceApplication::~TestServiceApplication() {
21 }
22
23 bool TestServiceApplication::ConfigureIncomingConnection(
24     ApplicationConnection* connection) {
25   connection->AddService<TestService>(this);
26   connection->AddService<TestTimeService>(this);
27   return true;
28 }
29
30 void TestServiceApplication::Create(ApplicationConnection* connection,
31                                     InterfaceRequest<TestService> request) {
32   BindToRequest(new TestServiceImpl(connection, this), &request);
33 }
34
35 void TestServiceApplication::Create(ApplicationConnection* connection,
36                                     InterfaceRequest<TestTimeService> request) {
37   BindToRequest(new TestTimeServiceImpl(connection), &request);
38 }
39
40 void TestServiceApplication::AddRef() {
41   assert(ref_count_ >= 0);
42   ref_count_++;
43 }
44
45 void TestServiceApplication::ReleaseRef() {
46   assert(ref_count_ > 0);
47   ref_count_--;
48   if (ref_count_ <= 0)
49     RunLoop::current()->Quit();
50 }
51
52 }  // namespace test
53
54 // static
55 ApplicationDelegate* ApplicationDelegate::Create() {
56   return new mojo::test::TestServiceApplication();
57 }
58
59 }  // namespace mojo