blob: 0f61f068e9bc562b82699d91e4d7f82f84f76570 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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 Gowan8e12b962015-02-09 16:45:05 -08006#include "mojo/public/cpp/application/application_impl.h"
Viet-Trung Luuc1248b22016-04-26 13:41:55 -07007#include "mojo/public/cpp/application/connect.h"
James Robinson63b637a2014-12-03 14:46:39 -08008#include "services/test_service/test_request_tracker.mojom.h"
James Robinson63b637a2014-12-03 14:46:39 -08009#include "services/test_service/test_time_service_impl.h"
James Robinson51b4cd62015-02-04 11:27:40 -080010#include "services/test_service/tracked_service.h"
James Robinson646469d2014-10-03 15:33:28 -070011
12namespace mojo {
13namespace test {
14
James Robinson43fd6832014-11-12 16:24:27 -080015TestTimeServiceImpl::TestTimeServiceImpl(
Geoffrey Gowan8e12b962015-02-09 16:45:05 -080016 ApplicationImpl* app_impl,
James Robinson43fd6832014-11-12 16:24:27 -080017 InterfaceRequest<TestTimeService> request)
Geoffrey Gowan8e12b962015-02-09 16:45:05 -080018 : app_impl_(app_impl), binding_(this, request.Pass()) {
James Robinson646469d2014-10-03 15:33:28 -070019}
20
21TestTimeServiceImpl::~TestTimeServiceImpl() {
22}
23
24void TestTimeServiceImpl::StartTrackingRequests(
25 const mojo::Callback<void()>& callback) {
26 TestRequestTrackerPtr tracker;
Viet-Trung Luuc1248b22016-04-26 13:41:55 -070027 ConnectToService(app_impl_->shell(), "mojo:test_request_tracker_app",
28 GetProxy(&tracker));
James Robinson51b4cd62015-02-04 11:27:40 -080029 tracking_.reset(new TrackedService(tracker.Pass(), Name_, callback));
James Robinson646469d2014-10-03 15:33:28 -070030}
31
32void 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