OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "mojo/services/test_service/test_request_tracker_impl.h" | 6 #include "mojo/services/test_service/test_request_tracker_impl.h" |
7 | 7 |
8 namespace mojo { | 8 namespace mojo { |
9 namespace test { | 9 namespace test { |
10 | 10 |
11 TrackingContext::TrackingContext() : next_id(1) {} | 11 TrackingContext::TrackingContext() : next_id(1) {} |
12 TrackingContext::~TrackingContext() {} | 12 TrackingContext::~TrackingContext() {} |
13 | 13 |
14 TestRequestTrackerImpl::TestRequestTrackerImpl( | 14 TestRequestTrackerImpl::TestRequestTrackerImpl(TrackingContext* context) |
15 ApplicationConnection* connection, | 15 : context_(context), weak_factory_(this) { |
16 TrackingContext* context) : context_(context), weak_factory_(this) { | |
17 } | 16 } |
18 | 17 |
19 TestRequestTrackerImpl::~TestRequestTrackerImpl() { | 18 TestRequestTrackerImpl::~TestRequestTrackerImpl() { |
20 } | 19 } |
21 | 20 |
22 void TestRequestTrackerImpl::RecordStats( | 21 void TestRequestTrackerImpl::RecordStats( |
23 uint64_t client_id, | 22 uint64_t client_id, |
24 ServiceStatsPtr stats) { | 23 ServiceStatsPtr stats) { |
25 assert(context_->ids_to_names.find(client_id) != | 24 assert(context_->ids_to_names.find(client_id) != |
26 context_->ids_to_names.end()); | 25 context_->ids_to_names.end()); |
27 context_->records[client_id].push_back(*stats); | 26 context_->records[client_id].push_back(*stats); |
28 } | 27 } |
29 | 28 |
30 void TestRequestTrackerImpl::OnConnectionEstablished() { | 29 void TestRequestTrackerImpl::OnConnectionEstablished() { |
31 uint64_t id = context_->next_id++; | 30 uint64_t id = context_->next_id++; |
32 client()->SetIdAndReturnName(id, | 31 client()->SetIdAndReturnName(id, |
33 base::Bind(&TestRequestTrackerImpl::UploaderNameCallback, | 32 base::Bind(&TestRequestTrackerImpl::UploaderNameCallback, |
34 weak_factory_.GetWeakPtr(), | 33 weak_factory_.GetWeakPtr(), |
35 id)); | 34 id)); |
36 } | 35 } |
37 | 36 |
38 void TestRequestTrackerImpl::UploaderNameCallback( | 37 void TestRequestTrackerImpl::UploaderNameCallback( |
39 uint64_t id, const mojo::String& name) { | 38 uint64_t id, const mojo::String& name) { |
40 DCHECK(context_->ids_to_names.find(id) == context_->ids_to_names.end()); | 39 DCHECK(context_->ids_to_names.find(id) == context_->ids_to_names.end()); |
41 context_->ids_to_names[id] = name; | 40 context_->ids_to_names[id] = name; |
42 } | 41 } |
43 | 42 |
44 TestTrackedRequestServiceImpl::TestTrackedRequestServiceImpl( | 43 TestTrackedRequestServiceImpl::TestTrackedRequestServiceImpl( |
45 ApplicationConnection* connection, | 44 TrackingContext* context) |
46 TrackingContext* context) : context_(context) { | 45 : context_(context) { |
47 } | 46 } |
48 | 47 |
49 TestTrackedRequestServiceImpl::~TestTrackedRequestServiceImpl() { | 48 TestTrackedRequestServiceImpl::~TestTrackedRequestServiceImpl() { |
50 } | 49 } |
51 | 50 |
52 void TestTrackedRequestServiceImpl::GetReport( | 51 void TestTrackedRequestServiceImpl::GetReport( |
53 const mojo::Callback<void(mojo::Array<ServiceReportPtr>)>& callback) { | 52 const mojo::Callback<void(mojo::Array<ServiceReportPtr>)>& callback) { |
54 mojo::Array<ServiceReportPtr> reports; | 53 mojo::Array<ServiceReportPtr> reports; |
55 for (AllRecordsMap::const_iterator it1 = context_->records.begin(); | 54 for (AllRecordsMap::const_iterator it1 = context_->records.begin(); |
56 it1 != context_->records.end(); ++it1) { | 55 it1 != context_->records.end(); ++it1) { |
(...skipping 10 matching lines...) Expand all Loading... |
67 mean_health_numerator += it2->health; | 66 mean_health_numerator += it2->health; |
68 } | 67 } |
69 report->mean_health = mean_health_numerator / num_samples; | 68 report->mean_health = mean_health_numerator / num_samples; |
70 reports.push_back(report.Pass()); | 69 reports.push_back(report.Pass()); |
71 } | 70 } |
72 callback.Run(reports.Pass()); | 71 callback.Run(reports.Pass()); |
73 } | 72 } |
74 | 73 |
75 } // namespace test | 74 } // namespace test |
76 } // namespace mojo | 75 } // namespace mojo |
OLD | NEW |