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 #ifndef SERVICES_RESOURCE_COORDINATOR_TRACING_RECORDER_H_ | |
6 #define SERVICES_RESOURCE_COORDINATOR_TRACING_RECORDER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/sequenced_task_runner.h" | |
11 #include "mojo/public/cpp/bindings/binding.h" | |
12 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h" | |
13 | |
14 namespace { | |
15 class DictionaryValue; | |
16 } | |
17 | |
18 namespace tracing { | |
19 | |
20 class Recorder : public mojom::Recorder { | |
21 public: | |
22 Recorder( | |
Primiano Tucci (use gerrit)
2017/05/25 13:15:01
can you add some comments to explain what these ar
chiniforooshan
2017/05/25 15:34:24
Done.
| |
23 mojom::RecorderRequest request, | |
24 bool is_array, | |
Primiano Tucci (use gerrit)
2017/05/25 13:15:01
data_is_array ? I understood what this was only at
chiniforooshan
2017/05/25 15:34:24
Done.
| |
25 const base::Closure& recorder_change_callback, | |
Primiano Tucci (use gerrit)
2017/05/25 13:15:01
Isn't this clearer if you call it on_data_change_c
chiniforooshan
2017/05/25 15:34:24
Yes, although the callback is also run when the co
| |
26 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); | |
27 ~Recorder() override; | |
28 | |
29 const std::string& data() const { | |
30 // All access to |data_| should be done on the background thread. | |
31 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | |
32 return data_; | |
33 } | |
34 | |
35 void clear_data() { | |
36 // All access to |data_| should be done on the background thread. | |
37 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | |
38 data_.clear(); | |
39 } | |
40 | |
41 const base::DictionaryValue& metadata() const { return metadata_; } | |
42 bool is_recording() const { return is_recording_; } | |
43 bool is_array() const { return is_array_; } | |
44 | |
45 private: | |
46 friend class RecorderTest; // For testing. | |
47 // mojom::Recorder | |
Primiano Tucci (use gerrit)
2017/05/25 13:15:01
small¬-strong style thing: not sure if there is
chiniforooshan
2017/05/25 15:34:25
There are examples of both in the code base. I can
| |
48 void AddChunk(const std::string& chunk) override; | |
Primiano Tucci (use gerrit)
2017/05/25 13:15:01
Can you please add some comments to specify who ad
chiniforooshan
2017/05/25 15:34:24
Done.
| |
49 void AddMetadata(std::unique_ptr<base::DictionaryValue> metadata) override; | |
50 | |
51 void OnConnectionError(); | |
52 | |
53 std::string data_; | |
54 base::DictionaryValue metadata_; | |
55 bool is_recording_; | |
56 bool is_array_; | |
57 base::Closure recorder_change_callback_; | |
58 // To avoid blocking the UI thread if the tracing service is run on the UI | |
59 // thread, we make sure that buffering trace events and copying them to the | |
60 // final stream is done on a background thread. | |
61 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
62 mojo::Binding<mojom::Recorder> binding_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(Recorder); | |
65 }; | |
66 | |
67 } // namespace tracing | |
68 #endif // SERVICES_RESOURCE_COORDINATOR_TRACING_RECORDER_H_ | |
OLD | NEW |