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