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