Update broken references to image assets
[chromium-blink-merge.git] / mojo / services / test_service / test_service_impl.cc
blob44d1818d8d9c0784bf6d00832a70ad14a0508fe4
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.
5 #include "mojo/services/test_service/test_service_impl.h"
7 #include "base/bind.h"
8 #include "base/i18n/time_formatting.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "mojo/application/public/cpp/application_impl.h"
11 #include "mojo/services/test_service/test_service_application.h"
12 #include "mojo/services/test_service/test_time_service_impl.h"
13 #include "mojo/services/test_service/tracked_service.h"
15 namespace mojo {
16 namespace test {
18 TestServiceImpl::TestServiceImpl(ApplicationImpl* app_impl,
19 TestServiceApplication* application,
20 InterfaceRequest<TestService> request)
21 : application_(application),
22 app_impl_(app_impl),
23 binding_(this, request.Pass()) {
24 binding_.set_connection_error_handler(
25 [this]() { application_->ReleaseRef(); });
28 TestServiceImpl::~TestServiceImpl() {
31 void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) {
32 if (tracking_)
33 tracking_->RecordNewRequest();
34 callback.Run();
37 void SendTimeResponse(
38 const mojo::Callback<void(int64_t)>& requestor_callback,
39 int64_t time_usec) {
40 requestor_callback.Run(time_usec);
43 void TestServiceImpl::ConnectToAppAndGetTime(
44 const mojo::String& app_url,
45 const mojo::Callback<void(int64_t)>& callback) {
46 mojo::URLRequestPtr request(mojo::URLRequest::New());
47 request->url = mojo::String::From(app_url);
48 app_impl_->ConnectToService(request.Pass(), &time_service_);
49 if (tracking_) {
50 tracking_->RecordNewRequest();
51 time_service_->StartTrackingRequests(mojo::Callback<void()>());
53 time_service_->GetPartyTime(base::Bind(&SendTimeResponse, callback));
56 void TestServiceImpl::StartTrackingRequests(
57 const mojo::Callback<void()>& callback) {
58 TestRequestTrackerPtr tracker;
59 mojo::URLRequestPtr request(mojo::URLRequest::New());
60 request->url = mojo::String::From("mojo:test_request_tracker_app");
61 app_impl_->ConnectToService(request.Pass(), &tracker);
62 tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback));
65 } // namespace test
66 } // namespace mojo