Chromium Code Reviews| OLD | NEW |
|---|---|
| (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() {} | |
|
oystein (OOO til 10th of July)
2017/05/25 16:55:26
nit: = default;
chiniforooshan
2017/05/25 19:45:32
Done.
| |
| 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_.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.
| |
| 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 | |
| OLD | NEW |