| OLD | NEW |
| 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 "services/test_service/test_service_application.h" | 5 #include "services/test_service/test_service_application.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include <memory> | |
| 10 | |
| 11 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
| 12 #include "mojo/public/cpp/application/application_runner.h" | 10 #include "mojo/public/cpp/application/run_application.h" |
| 13 #include "mojo/public/cpp/application/service_provider_impl.h" | 11 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 14 #include "mojo/public/cpp/utility/run_loop.h" | |
| 15 #include "services/test_service/test_service_impl.h" | 12 #include "services/test_service/test_service_impl.h" |
| 16 #include "services/test_service/test_time_service_impl.h" | 13 #include "services/test_service/test_time_service_impl.h" |
| 17 | 14 |
| 18 namespace mojo { | 15 namespace mojo { |
| 19 namespace test { | 16 namespace test { |
| 20 | 17 |
| 21 TestServiceApplication::TestServiceApplication() | 18 TestServiceApplication::TestServiceApplication() : ref_count_(0) {} |
| 22 : ref_count_(0), app_impl_(nullptr) {} | |
| 23 | 19 |
| 24 TestServiceApplication::~TestServiceApplication() {} | 20 TestServiceApplication::~TestServiceApplication() {} |
| 25 | 21 |
| 26 void TestServiceApplication::Initialize(ApplicationImpl* app) { | 22 bool TestServiceApplication::OnAcceptConnection( |
| 27 app_impl_ = app; | |
| 28 } | |
| 29 | |
| 30 bool TestServiceApplication::ConfigureIncomingConnection( | |
| 31 ServiceProviderImpl* service_provider_impl) { | 23 ServiceProviderImpl* service_provider_impl) { |
| 32 service_provider_impl->AddService<TestService>( | 24 service_provider_impl->AddService<TestService>( |
| 33 [this](const ConnectionContext& connection_context, | 25 [this](const ConnectionContext& connection_context, |
| 34 InterfaceRequest<TestService> request) { | 26 InterfaceRequest<TestService> request) { |
| 35 new TestServiceImpl(app_impl_, this, request.Pass()); | 27 new TestServiceImpl(this, request.Pass()); |
| 36 AddRef(); | 28 AddRef(); |
| 37 }); | 29 }); |
| 38 service_provider_impl->AddService<TestTimeService>( | 30 service_provider_impl->AddService<TestTimeService>( |
| 39 [this](const ConnectionContext& connection_context, | 31 [this](const ConnectionContext& connection_context, |
| 40 InterfaceRequest<TestTimeService> request) { | 32 InterfaceRequest<TestTimeService> request) { |
| 41 new TestTimeServiceImpl(app_impl_, request.Pass()); | 33 new TestTimeServiceImpl(this, request.Pass()); |
| 42 }); | 34 }); |
| 43 return true; | 35 return true; |
| 44 } | 36 } |
| 45 | 37 |
| 46 void TestServiceApplication::AddRef() { | 38 void TestServiceApplication::AddRef() { |
| 47 assert(ref_count_ >= 0); | 39 assert(ref_count_ >= 0); |
| 48 ref_count_++; | 40 ref_count_++; |
| 49 } | 41 } |
| 50 | 42 |
| 51 void TestServiceApplication::ReleaseRef() { | 43 void TestServiceApplication::ReleaseRef() { |
| 52 assert(ref_count_ > 0); | 44 assert(ref_count_ > 0); |
| 53 ref_count_--; | 45 ref_count_--; |
| 54 if (ref_count_ <= 0) | 46 if (ref_count_ <= 0) |
| 55 RunLoop::current()->Quit(); | 47 TerminateApplication(); |
| 56 } | 48 } |
| 57 | 49 |
| 58 } // namespace test | 50 } // namespace test |
| 59 } // namespace mojo | 51 } // namespace mojo |
| 60 | 52 |
| 61 MojoResult MojoMain(MojoHandle application_request) { | 53 MojoResult MojoMain(MojoHandle application_request) { |
| 62 mojo::ApplicationRunner runner( | 54 mojo::test::TestServiceApplication app; |
| 63 std::unique_ptr<mojo::test::TestServiceApplication>( | 55 mojo::RunApplication(application_request, &app); |
| 64 new mojo::test::TestServiceApplication())); | 56 return MOJO_RESULT_OK; |
| 65 return runner.Run(application_request); | |
| 66 } | 57 } |
| OLD | NEW |