OLD | NEW |
(Empty) | |
| 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 "mojo/services/test_service/test_request_tracker_client_impl.h" |
| 6 |
| 7 namespace mojo { |
| 8 namespace test { |
| 9 |
| 10 TestRequestTrackerClientImpl::TestRequestTrackerClientImpl( |
| 11 TestRequestTrackerPtr tracker, |
| 12 const std::string& service_name, |
| 13 const mojo::Callback<void()>& callback) |
| 14 : id_(0), |
| 15 requests_since_upload_(0), |
| 16 service_name_(service_name), |
| 17 tracker_(tracker.Pass()), |
| 18 tracking_connected_callback_(callback) { |
| 19 tracker_.set_client(this); |
| 20 } |
| 21 |
| 22 TestRequestTrackerClientImpl::~TestRequestTrackerClientImpl() { |
| 23 } |
| 24 |
| 25 void TestRequestTrackerClientImpl::RecordNewRequest() { |
| 26 requests_since_upload_++; |
| 27 if (id_ == kInvalidId) |
| 28 return; |
| 29 SendStats(); |
| 30 } |
| 31 |
| 32 void TestRequestTrackerClientImpl::SendStats() { |
| 33 ServiceStatsPtr stats(ServiceStats::New()); |
| 34 stats->num_new_requests = requests_since_upload_; |
| 35 stats->health = 0.7; |
| 36 tracker_->RecordStats(id_, stats.Pass()); |
| 37 requests_since_upload_ = 0; |
| 38 } |
| 39 |
| 40 void TestRequestTrackerClientImpl::SetIdAndReturnName( |
| 41 uint64_t id, |
| 42 const mojo::Callback<void(mojo::String)>& callback) { |
| 43 assert(id != kInvalidId); |
| 44 assert(id_ == kInvalidId); |
| 45 id_ = id; |
| 46 callback.Run(service_name_); |
| 47 tracking_connected_callback_.Run(); |
| 48 if (requests_since_upload_ == 0) |
| 49 return; |
| 50 SendStats(); |
| 51 } |
| 52 |
| 53 } // namespace test |
| 54 } // namespace mojo |
OLD | NEW |