[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / mojo / services / test_service / test_service_impl.cc
blob4195e50ba8961af3f9ba351b131320885c011e62
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_error_handler(this);
27 TestServiceImpl::~TestServiceImpl() {
30 void TestServiceImpl::OnConnectionError() {
31 application_->ReleaseRef();
34 void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) {
35 if (tracking_)
36 tracking_->RecordNewRequest();
37 callback.Run();
40 void SendTimeResponse(
41 const mojo::Callback<void(int64_t)>& requestor_callback,
42 int64_t time_usec) {
43 requestor_callback.Run(time_usec);
46 void TestServiceImpl::ConnectToAppAndGetTime(
47 const mojo::String& app_url,
48 const mojo::Callback<void(int64_t)>& callback) {
49 mojo::URLRequestPtr request(mojo::URLRequest::New());
50 request->url = mojo::String::From(app_url);
51 app_impl_->ConnectToService(request.Pass(), &time_service_);
52 if (tracking_) {
53 tracking_->RecordNewRequest();
54 time_service_->StartTrackingRequests(mojo::Callback<void()>());
56 time_service_->GetPartyTime(base::Bind(&SendTimeResponse, callback));
59 void TestServiceImpl::StartTrackingRequests(
60 const mojo::Callback<void()>& callback) {
61 TestRequestTrackerPtr tracker;
62 mojo::URLRequestPtr request(mojo::URLRequest::New());
63 request->url = mojo::String::From("mojo:test_request_tracker_app");
64 app_impl_->ConnectToService(request.Pass(), &tracker);
65 tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback));
68 } // namespace test
69 } // namespace mojo