Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: mojo/services/test_service/tracked_service.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/services/test_service/tracked_service.h ('k') | mojo/services/tracing/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/tracked_service.h"
6
7 #include "base/bind.h"
8
9 namespace mojo {
10 namespace test {
11
12 TrackedService::TrackedService(TestRequestTrackerPtr tracker,
13 const std::string& service_name,
14 const mojo::Callback<void()>& callback)
15 : id_(0u),
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)));
22 }
23
24 TrackedService::~TrackedService() {
25 }
26
27 void TrackedService::RecordNewRequest() {
28 requests_since_upload_++;
29 if (id_ == 0u)
30 return;
31 SendStats();
32 }
33
34 void TrackedService::SendStats() {
35 ServiceStatsPtr stats(ServiceStats::New());
36 stats->num_new_requests = requests_since_upload_;
37 stats->health = 0.7;
38 tracker_->RecordStats(id_, stats.Pass());
39 requests_since_upload_ = 0u;
40 }
41
42 void TrackedService::SetId(uint64_t id) {
43 assert(id != 0u);
44 assert(id_ == 0u);
45 id_ = id;
46 tracking_connected_callback_.Run();
47 if (requests_since_upload_ == 0u)
48 return;
49 SendStats();
50 }
51
52 } // namespace test
53 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/test_service/tracked_service.h ('k') | mojo/services/tracing/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698