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

Side by Side 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 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_impl.h"
6
7 #include "base/sequenced_task_runner.h"
8 #include "base/strings/string_split.h"
9 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h"
10
11 namespace resource_coordinator {
12 namespace tracing {
13
14 RecorderImpl::RecorderImpl(
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 &RecorderImpl::OnConnectionError, base::Unretained(this)));
26 }
27
28 RecorderImpl::~RecorderImpl() {}
29
30 void RecorderImpl::AddCategories(const std::string& categories) {
31 const std::vector<std::string> split = base::SplitString(
32 categories, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
33 for (const auto& category : split) {
34 category_set_.insert(category);
35 }
36 }
37
38 void RecorderImpl::AddChunk(const std::string& chunk) {
39 if (!background_task_runner_->RunsTasksOnCurrentThread()) {
40 background_task_runner_->PostTask(
41 FROM_HERE, base::BindRepeating(&RecorderImpl::AddChunk,
42 base::Unretained(this), chunk));
43 return;
44 }
45 if (chunk.size() == 0)
46 return;
47 if (is_array_ && data_.size() > 0)
48 data_.append(",");
49 data_.append(chunk);
50 recorder_change_callback_.Run();
51 }
52
53 void RecorderImpl::AddMetadata(
54 std::unique_ptr<base::DictionaryValue> metadata) {}
55
56 void RecorderImpl::OnConnectionError() {
57 if (!background_task_runner_->RunsTasksOnCurrentThread()) {
58 background_task_runner_->PostTask(
59 FROM_HERE, base::BindRepeating(&RecorderImpl::OnConnectionError,
60 base::Unretained(this)));
61 return;
62 }
63 is_recording_ = false;
64 recorder_change_callback_.Run();
65 }
66
67 } // namespace tracing
68 } // namespace resource_coordinator
OLDNEW
« 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