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