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_impl.h" | 5 #include "services/test_service/test_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "mojo/public/cpp/application/application_impl.h" | |
11 #include "mojo/public/cpp/application/connect.h" | 10 #include "mojo/public/cpp/application/connect.h" |
12 #include "services/test_service/test_service_application.h" | 11 #include "services/test_service/test_service_application.h" |
13 #include "services/test_service/test_time_service_impl.h" | 12 #include "services/test_service/test_time_service_impl.h" |
14 #include "services/test_service/tracked_service.h" | 13 #include "services/test_service/tracked_service.h" |
15 | 14 |
16 namespace mojo { | 15 namespace mojo { |
17 namespace test { | 16 namespace test { |
18 | 17 |
19 TestServiceImpl::TestServiceImpl(ApplicationImpl* app_impl, | 18 TestServiceImpl::TestServiceImpl(TestServiceApplication* application, |
20 TestServiceApplication* application, | |
21 InterfaceRequest<TestService> request) | 19 InterfaceRequest<TestService> request) |
22 : application_(application), | 20 : application_(application), binding_(this, request.Pass()) { |
23 app_impl_(app_impl), | |
24 binding_(this, request.Pass()) { | |
25 binding_.set_connection_error_handler( | 21 binding_.set_connection_error_handler( |
26 [this]() { application_->ReleaseRef(); }); | 22 [this]() { application_->ReleaseRef(); }); |
27 } | 23 } |
28 | 24 |
29 TestServiceImpl::~TestServiceImpl() { | 25 TestServiceImpl::~TestServiceImpl() {} |
30 } | |
31 | 26 |
32 void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) { | 27 void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) { |
33 if (tracking_) | 28 if (tracking_) |
34 tracking_->RecordNewRequest(); | 29 tracking_->RecordNewRequest(); |
35 callback.Run(); | 30 callback.Run(); |
36 } | 31 } |
37 | 32 |
38 void SendTimeResponse( | 33 void SendTimeResponse( |
39 const mojo::Callback<void(int64_t)>& requestor_callback, | 34 const mojo::Callback<void(int64_t)>& requestor_callback, |
40 int64_t time_usec) { | 35 int64_t time_usec) { |
41 requestor_callback.Run(time_usec); | 36 requestor_callback.Run(time_usec); |
42 } | 37 } |
43 | 38 |
44 void TestServiceImpl::ConnectToAppAndGetTime( | 39 void TestServiceImpl::ConnectToAppAndGetTime( |
45 const mojo::String& app_url, | 40 const mojo::String& app_url, |
46 const mojo::Callback<void(int64_t)>& callback) { | 41 const mojo::Callback<void(int64_t)>& callback) { |
47 ConnectToService(app_impl_->shell(), app_url, GetProxy(&time_service_)); | 42 ConnectToService(application_->shell(), app_url, GetProxy(&time_service_)); |
48 if (tracking_) { | 43 if (tracking_) { |
49 tracking_->RecordNewRequest(); | 44 tracking_->RecordNewRequest(); |
50 time_service_->StartTrackingRequests(mojo::Callback<void()>()); | 45 time_service_->StartTrackingRequests(mojo::Callback<void()>()); |
51 } | 46 } |
52 time_service_->GetPartyTime(base::Bind(&SendTimeResponse, callback)); | 47 time_service_->GetPartyTime(base::Bind(&SendTimeResponse, callback)); |
53 } | 48 } |
54 | 49 |
55 void TestServiceImpl::StartTrackingRequests( | 50 void TestServiceImpl::StartTrackingRequests( |
56 const mojo::Callback<void()>& callback) { | 51 const mojo::Callback<void()>& callback) { |
57 TestRequestTrackerPtr tracker; | 52 TestRequestTrackerPtr tracker; |
58 ConnectToService(app_impl_->shell(), "mojo:test_request_tracker_app", | 53 ConnectToService(application_->shell(), "mojo:test_request_tracker_app", |
59 GetProxy(&tracker)); | 54 GetProxy(&tracker)); |
60 tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback)); | 55 tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback)); |
61 } | 56 } |
62 | 57 |
63 } // namespace test | 58 } // namespace test |
64 } // namespace mojo | 59 } // namespace mojo |
OLD | NEW |