James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 "base/time/time.h" |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 6 | #include "mojo/public/cpp/application/application_impl.h" |
Viet-Trung Luu | c1248b2 | 2016-04-26 13:41:55 -0700 | [diff] [blame] | 7 | #include "mojo/public/cpp/application/connect.h" |
James Robinson | 63b637a | 2014-12-03 14:46:39 -0800 | [diff] [blame] | 8 | #include "services/test_service/test_request_tracker.mojom.h" |
James Robinson | 63b637a | 2014-12-03 14:46:39 -0800 | [diff] [blame] | 9 | #include "services/test_service/test_time_service_impl.h" |
James Robinson | 51b4cd6 | 2015-02-04 11:27:40 -0800 | [diff] [blame] | 10 | #include "services/test_service/tracked_service.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 11 | |
| 12 | namespace mojo { |
| 13 | namespace test { |
| 14 | |
James Robinson | 43fd683 | 2014-11-12 16:24:27 -0800 | [diff] [blame] | 15 | TestTimeServiceImpl::TestTimeServiceImpl( |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 16 | ApplicationImpl* app_impl, |
James Robinson | 43fd683 | 2014-11-12 16:24:27 -0800 | [diff] [blame] | 17 | InterfaceRequest<TestTimeService> request) |
Geoffrey Gowan | 8e12b96 | 2015-02-09 16:45:05 -0800 | [diff] [blame] | 18 | : app_impl_(app_impl), binding_(this, request.Pass()) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | TestTimeServiceImpl::~TestTimeServiceImpl() { |
| 22 | } |
| 23 | |
| 24 | void TestTimeServiceImpl::StartTrackingRequests( |
| 25 | const mojo::Callback<void()>& callback) { |
| 26 | TestRequestTrackerPtr tracker; |
Viet-Trung Luu | c1248b2 | 2016-04-26 13:41:55 -0700 | [diff] [blame] | 27 | ConnectToService(app_impl_->shell(), "mojo:test_request_tracker_app", |
| 28 | GetProxy(&tracker)); |
James Robinson | 51b4cd6 | 2015-02-04 11:27:40 -0800 | [diff] [blame] | 29 | tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void TestTimeServiceImpl::GetPartyTime( |
| 33 | const mojo::Callback<void(int64_t)>& callback) { |
| 34 | if (tracking_) |
| 35 | tracking_->RecordNewRequest(); |
| 36 | base::Time frozen_time(base::Time::UnixEpoch() |
| 37 | + base::TimeDelta::FromDays(10957) |
| 38 | + base::TimeDelta::FromHours(7) |
| 39 | + base::TimeDelta::FromMinutes(59)); |
| 40 | int64 time(frozen_time.ToInternalValue()); |
| 41 | callback.Run(time); |
| 42 | } |
| 43 | |
| 44 | } // namespace test |
| 45 | } // namespace mojo |