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