summaryrefslogtreecommitdiffstats
path: root/mojo/services/test_service/test_time_service_impl.cc
blob: c69673d502c1c08752b4ff2ab7d66e0ce86c193e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/services/test_service/test_time_service_impl.h"

#include <stdint.h>

#include <utility>

#include "base/time/time.h"
#include "mojo/services/test_service/test_request_tracker.mojom.h"
#include "mojo/services/test_service/tracked_service.h"
#include "mojo/shell/public/cpp/shell.h"

namespace mojo {
namespace test {

TestTimeServiceImpl::TestTimeServiceImpl(
      Shell* shell,
      InterfaceRequest<TestTimeService> request)
    : shell_(shell), binding_(this, std::move(request)) {}

TestTimeServiceImpl::~TestTimeServiceImpl() {
}

void TestTimeServiceImpl::StartTrackingRequests(
    const mojo::Callback<void()>& callback) {
  TestRequestTrackerPtr tracker;
  shell_->ConnectToService("mojo:test_request_tracker_app", &tracker);
  tracking_.reset(new TrackedService(std::move(tracker), Name_, callback));
}

void TestTimeServiceImpl::GetPartyTime(
    const mojo::Callback<void(int64_t)>& callback) {
  if (tracking_)
    tracking_->RecordNewRequest();
  base::Time frozen_time(base::Time::UnixEpoch()
      + base::TimeDelta::FromDays(10957)
      + base::TimeDelta::FromHours(7)
      + base::TimeDelta::FromMinutes(59));
  int64_t time(frozen_time.ToInternalValue());
  callback.Run(time);
}

}  // namespace test
}  // namespace mojo