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

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

Issue 2886203002: tracing: the recorder implementation (Closed)
Patch Set: rebase 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.cc
diff --git a/services/resource_coordinator/tracing/recorder.cc b/services/resource_coordinator/tracing/recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6300b51a83907dc3b296d49eb32fc5c90c5923eb
--- /dev/null
+++ b/services/resource_coordinator/tracing/recorder.cc
@@ -0,0 +1,54 @@
+// 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.h"
+
+#include "base/callback_forward.h"
+#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner.h"
+#include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom.h"
+
+namespace tracing {
+
+Recorder::Recorder(
+ 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(
+ &Recorder::OnConnectionError, base::Unretained(this)));
Primiano Tucci (use gerrit) 2017/05/25 13:15:01 Is this class going to be long lived? If yes, plea
chiniforooshan 2017/05/25 15:34:24 It's not long lived, but it's deleted after the co
+}
+
+Recorder::~Recorder() {}
+
+void Recorder::AddChunk(const std::string& chunk) {
+ if (chunk.size() == 0)
Primiano Tucci (use gerrit) 2017/05/25 13:15:01 chunk.empty()
chiniforooshan 2017/05/25 15:34:24 Done.
+ return;
+ if (!background_task_runner_->RunsTasksOnCurrentThread()) {
+ background_task_runner_->PostTask(
+ FROM_HERE, base::BindRepeating(&Recorder::AddChunk,
+ base::Unretained(this), chunk));
+ return;
+ }
+ if (is_array_ && data_.size() > 0)
+ data_.append(",");
+ data_.append(chunk);
+ recorder_change_callback_.Run();
+}
+
+void Recorder::AddMetadata(std::unique_ptr<base::DictionaryValue> metadata) {
+ metadata_.MergeDictionary(metadata.get());
+}
+
+void Recorder::OnConnectionError() {
+ is_recording_ = false;
+ background_task_runner_->PostTask(FROM_HERE, recorder_change_callback_);
+}
+
+} // namespace tracing

Powered by Google App Engine
This is Rietveld 408576698