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

Unified Diff: services/resource_coordinator/tracing/recorder_impl.cc

Issue 2833873003: WIP: The tracing service prototype
Patch Set: sync Created 3 years, 7 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: services/resource_coordinator/tracing/recorder_impl.cc
diff --git a/services/resource_coordinator/tracing/recorder_impl.cc b/services/resource_coordinator/tracing/recorder_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8aeca7928533f600414297f8815a23db900ee6d8
--- /dev/null
+++ b/services/resource_coordinator/tracing/recorder_impl.cc
@@ -0,0 +1,68 @@
+// Copyright 2017 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 "services/resource_coordinator/tracing/recorder_impl.h"
+
+#include "base/sequenced_task_runner.h"
+#include "base/strings/string_split.h"
+#include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom.h"
+
+namespace resource_coordinator {
+namespace tracing {
+
+RecorderImpl::RecorderImpl(
+ mojom::RecorderRequest request,
+ bool is_array,
+ const base::Closure& recorder_change_callback,
+ const scoped_refptr<base::SequencedTaskRunner>& background_task_runner)
+ : is_recording_(true),
+ is_array_(is_array),
+ recorder_change_callback_(recorder_change_callback),
+ background_task_runner_(background_task_runner),
+ binding_(this, std::move(request)) {
+ binding_.set_connection_error_handler(base::BindRepeating(
+ &RecorderImpl::OnConnectionError, base::Unretained(this)));
+}
+
+RecorderImpl::~RecorderImpl() {}
+
+void RecorderImpl::AddCategories(const std::string& categories) {
+ const std::vector<std::string> split = base::SplitString(
+ categories, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ for (const auto& category : split) {
+ category_set_.insert(category);
+ }
+}
+
+void RecorderImpl::AddChunk(const std::string& chunk) {
+ if (!background_task_runner_->RunsTasksOnCurrentThread()) {
+ background_task_runner_->PostTask(
+ FROM_HERE, base::BindRepeating(&RecorderImpl::AddChunk,
+ base::Unretained(this), chunk));
+ return;
+ }
+ if (chunk.size() == 0)
+ return;
+ if (is_array_ && data_.size() > 0)
+ data_.append(",");
+ data_.append(chunk);
+ recorder_change_callback_.Run();
+}
+
+void RecorderImpl::AddMetadata(
+ std::unique_ptr<base::DictionaryValue> metadata) {}
+
+void RecorderImpl::OnConnectionError() {
+ if (!background_task_runner_->RunsTasksOnCurrentThread()) {
+ background_task_runner_->PostTask(
+ FROM_HERE, base::BindRepeating(&RecorderImpl::OnConnectionError,
+ base::Unretained(this)));
+ return;
+ }
+ is_recording_ = false;
+ recorder_change_callback_.Run();
+}
+
+} // namespace tracing
+} // namespace resource_coordinator
« no previous file with comments | « services/resource_coordinator/tracing/recorder_impl.h ('k') | services/resource_coordinator/tracing/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698