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

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 is_array,
17 const base::Closure& recorder_change_callback,
18 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner)
19 : is_recording_(true),
20 is_array_(is_array),
21 recorder_change_callback_(recorder_change_callback),
22 background_task_runner_(background_task_runner),
23 binding_(this, std::move(request)) {
24 binding_.set_connection_error_handler(base::BindRepeating(
25 &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
26 }
27
28 Recorder::~Recorder() {}
29
30 void Recorder::AddChunk(const std::string& chunk) {
31 if (chunk.size() == 0)
Primiano Tucci (use gerrit) 2017/05/25 13:15:01 chunk.empty()
chiniforooshan 2017/05/25 15:34:24 Done.
32 return;
33 if (!background_task_runner_->RunsTasksOnCurrentThread()) {
34 background_task_runner_->PostTask(
35 FROM_HERE, base::BindRepeating(&Recorder::AddChunk,
36 base::Unretained(this), chunk));
37 return;
38 }
39 if (is_array_ && data_.size() > 0)
40 data_.append(",");
41 data_.append(chunk);
42 recorder_change_callback_.Run();
43 }
44
45 void Recorder::AddMetadata(std::unique_ptr<base::DictionaryValue> metadata) {
46 metadata_.MergeDictionary(metadata.get());
47 }
48
49 void Recorder::OnConnectionError() {
50 is_recording_ = false;
51 background_task_runner_->PostTask(FROM_HERE, recorder_change_callback_);
52 }
53
54 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698