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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/test_service/test_request_tracker_impl.cc
diff --git a/mojo/services/test_service/test_request_tracker_impl.cc b/mojo/services/test_service/test_request_tracker_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7393cb49bb1197bc8e4bee43b23ea52a9dd28cb3
--- /dev/null
+++ b/mojo/services/test_service/test_request_tracker_impl.cc
@@ -0,0 +1,76 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "mojo/services/test_service/test_request_tracker_impl.h"
+
+namespace mojo {
+namespace test {
+
+ TrackingContext::TrackingContext() : next_id(1) {}
+ TrackingContext::~TrackingContext() {}
+
+ TestRequestTrackerImpl::TestRequestTrackerImpl(
+ ApplicationConnection* connection,
+ TrackingContext* context) : context_(context), weak_factory_(this) {
+ }
+
+ TestRequestTrackerImpl::~TestRequestTrackerImpl() {
+ }
+
+void TestRequestTrackerImpl::RecordStats(
+ uint64_t client_id,
+ ServiceStatsPtr stats) {
+ assert(context_->ids_to_names.find(client_id) !=
+ context_->ids_to_names.end());
+ context_->records[client_id].push_back(*stats);
+}
+
+void TestRequestTrackerImpl::OnConnectionEstablished() {
+ uint64_t id = context_->next_id++;
+ client()->SetIdAndReturnName(id,
+ base::Bind(&TestRequestTrackerImpl::UploaderNameCallback,
+ weak_factory_.GetWeakPtr(),
+ id));
+}
+
+void TestRequestTrackerImpl::UploaderNameCallback(
+ uint64_t id, const mojo::String& name) {
+ DCHECK(context_->ids_to_names.find(id) == context_->ids_to_names.end());
+ context_->ids_to_names[id] = name;
+}
+
+TestTrackedRequestServiceImpl::TestTrackedRequestServiceImpl(
+ ApplicationConnection* connection,
+ TrackingContext* context) : context_(context) {
+}
+
+TestTrackedRequestServiceImpl::~TestTrackedRequestServiceImpl() {
+}
+
+void TestTrackedRequestServiceImpl::GetReport(
+ const mojo::Callback<void(mojo::Array<ServiceReportPtr>)>& callback) {
+ mojo::Array<ServiceReportPtr> reports;
+ for (AllRecordsMap::const_iterator it1 = context_->records.begin();
+ it1 != context_->records.end(); ++it1) {
+ ServiceReportPtr report(ServiceReport::New());
+ report->service_name = context_->ids_to_names[it1->first];
+ double mean_health_numerator = 0;
+ size_t num_samples = it1->second.size();
+ if (num_samples == 0)
+ continue;
+
+ for (std::vector<ServiceStats>::const_iterator it2 = it1->second.begin();
+ it2 != it1->second.end(); ++it2) {
+ report->total_requests += it2->num_new_requests;
+ mean_health_numerator += it2->health;
+ }
+ report->mean_health = mean_health_numerator / num_samples;
+ reports.push_back(report.Pass());
+ }
+ callback.Run(reports.Pass());
+}
+
+} // namespace test
+} // namespace mojo
« 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