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

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

Issue 349303006: mojo: add some end-to-end shell tests and a new test sample app (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no icu Created 6 years, 5 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 | Annotate | Revision Log
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 "base/bind.h"
6 #include "mojo/services/test_service/test_request_tracker_impl.h"
7
8 namespace mojo {
9 namespace test {
10
11 TrackingContext::TrackingContext() : next_id(1) {}
12 TrackingContext::~TrackingContext() {}
13
14 TestRequestTrackerImpl::TestRequestTrackerImpl(
15 ApplicationConnection* connection,
16 TrackingContext* context) : context_(context), weak_factory_(this) {
17 }
18
19 TestRequestTrackerImpl::~TestRequestTrackerImpl() {
20 }
21
22 void TestRequestTrackerImpl::RecordStats(
23 uint64_t client_id,
24 ServiceStatsPtr stats) {
25 assert(context_->ids_to_names.find(client_id) !=
26 context_->ids_to_names.end());
27 context_->records[client_id].push_back(*stats);
28 }
29
30 void TestRequestTrackerImpl::OnConnectionEstablished() {
31 uint64_t id = context_->next_id++;
32 client()->SetIdAndReturnName(id,
33 base::Bind(&TestRequestTrackerImpl::UploaderNameCallback,
34 weak_factory_.GetWeakPtr(),
35 id));
36 }
37
38 void TestRequestTrackerImpl::UploaderNameCallback(
39 uint64_t id, const mojo::String& name) {
40 DCHECK(context_->ids_to_names.find(id) == context_->ids_to_names.end());
41 context_->ids_to_names[id] = name;
42 }
43
44 TestTrackedRequestServiceImpl::TestTrackedRequestServiceImpl(
45 ApplicationConnection* connection,
46 TrackingContext* context) : context_(context) {
47 }
48
49 TestTrackedRequestServiceImpl::~TestTrackedRequestServiceImpl() {
50 }
51
52 void TestTrackedRequestServiceImpl::GetReport(
53 const mojo::Callback<void(mojo::Array<ServiceReportPtr>)>& callback) {
54 mojo::Array<ServiceReportPtr> reports;
55 for (AllRecordsMap::const_iterator it1 = context_->records.begin();
56 it1 != context_->records.end(); ++it1) {
57 ServiceReportPtr report(ServiceReport::New());
58 report->service_name = context_->ids_to_names[it1->first];
59 double mean_health_numerator = 0;
60 size_t num_samples = it1->second.size();
61 if (num_samples == 0)
62 continue;
63
64 for (std::vector<ServiceStats>::const_iterator it2 = it1->second.begin();
65 it2 != it1->second.end(); ++it2) {
66 report->total_requests += it2->num_new_requests;
67 mean_health_numerator += it2->health;
68 }
69 report->mean_health = mean_health_numerator / num_samples;
70 reports.push_back(report.Pass());
71 }
72 callback.Run(reports.Pass());
73 }
74
75 } // namespace test
76 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/test_service/test_request_tracker_impl.h ('k') | mojo/services/test_service/test_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698