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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/resource_coordinator/tracing/recorder.h"
6
7 #include "base/callback_forward.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/sequenced_task_runner.h"
10 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h"
11
12 namespace tracing {
13
14 Recorder::Recorder(
15 mojom::RecorderRequest request,
16 bool data_is_array,
17 const base::Closure& on_data_change_callback,
18 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner)
19 : is_recording_(true),
20 data_is_array_(data_is_array),
21 on_data_change_callback_(on_data_change_callback),
22 background_task_runner_(background_task_runner),
23 binding_(this, std::move(request)),
24 weak_factory_(this) {
25 binding_.set_connection_error_handler(base::BindRepeating(
26 &Recorder::OnConnectionError, weak_factory_.GetWeakPtr()));
27 }
28
29 Recorder::~Recorder() = default;
30
31 void Recorder::AddChunk(const std::string& chunk) {
32 if (chunk.empty())
33 return;
34 if (!background_task_runner_->RunsTasksOnCurrentThread()) {
35 background_task_runner_->PostTask(
36 FROM_HERE, base::BindRepeating(&Recorder::AddChunk,
37 weak_factory_.GetWeakPtr(), chunk));
38 return;
39 }
40 if (data_is_array_ && !data_.empty())
41 data_.append(",");
42 data_.append(chunk);
43 on_data_change_callback_.Run();
44 }
45
46 void Recorder::AddMetadata(std::unique_ptr<base::DictionaryValue> metadata) {
47 metadata_.MergeDictionary(metadata.get());
48 }
49
50 void Recorder::OnConnectionError() {
51 is_recording_ = false;
52 background_task_runner_->PostTask(FROM_HERE, on_data_change_callback_);
53 }
54
55 } // namespace tracing
OLDNEW
« no previous file with comments | « services/resource_coordinator/tracing/recorder.h ('k') | services/resource_coordinator/tracing/recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698