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

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

Issue 2886203002: tracing: the recorder implementation (Closed)
Patch Set: review 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..b55482fc23baace2d06db396f7b385e2c0038de2
--- /dev/null
+++ b/services/resource_coordinator/tracing/recorder.cc
@@ -0,0 +1,55 @@
+// 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 data_is_array,
+ const base::Closure& on_data_change_callback,
+ const scoped_refptr<base::SequencedTaskRunner>& background_task_runner)
+ : is_recording_(true),
+ data_is_array_(data_is_array),
+ on_data_change_callback_(on_data_change_callback),
+ background_task_runner_(background_task_runner),
+ binding_(this, std::move(request)),
+ weak_factory_(this) {
+ binding_.set_connection_error_handler(base::BindRepeating(
+ &Recorder::OnConnectionError, weak_factory_.GetWeakPtr()));
+}
+
+Recorder::~Recorder() {}
oystein (OOO til 10th of July) 2017/05/25 16:55:26 nit: = default;
chiniforooshan 2017/05/25 19:45:32 Done.
+
+void Recorder::AddChunk(const std::string& chunk) {
+ if (chunk.empty())
+ return;
+ if (!background_task_runner_->RunsTasksOnCurrentThread()) {
+ background_task_runner_->PostTask(
+ FROM_HERE, base::BindRepeating(&Recorder::AddChunk,
+ weak_factory_.GetWeakPtr(), chunk));
+ return;
+ }
+ if (data_is_array_ && data_.size() > 0)
oystein (OOO til 10th of July) 2017/05/25 16:55:26 nit: !data_.empty()
chiniforooshan 2017/05/25 19:45:32 Done.
+ data_.append(",");
+ data_.append(chunk);
+ on_data_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, on_data_change_callback_);
+}
+
+} // namespace tracing

Powered by Google App Engine
This is Rietveld 408576698