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/tracked_service.h"
12 TrackedService::TrackedService(TestRequestTrackerPtr tracker
,
13 const std::string
& service_name
,
14 const mojo::Callback
<void()>& callback
)
16 requests_since_upload_(0u),
17 service_name_(service_name
),
18 tracker_(tracker
.Pass()),
19 tracking_connected_callback_(callback
) {
20 tracker_
->SetNameAndReturnId(
21 service_name
, base::Bind(&TrackedService::SetId
, base::Unretained(this)));
24 TrackedService::~TrackedService() {
27 void TrackedService::RecordNewRequest() {
28 requests_since_upload_
++;
34 void TrackedService::SendStats() {
35 ServiceStatsPtr
stats(ServiceStats::New());
36 stats
->num_new_requests
= requests_since_upload_
;
38 tracker_
->RecordStats(id_
, stats
.Pass());
39 requests_since_upload_
= 0u;
42 void TrackedService::SetId(uint64_t id
) {
46 tracking_connected_callback_
.Run();
47 if (requests_since_upload_
== 0u)