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 #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/memory/weak_ptr.h" | |
| 11 #include "base/sequenced_task_runner.h" | |
| 12 #include "mojo/public/cpp/bindings/binding.h" | |
| 13 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h" | |
| 14 | |
| 15 namespace { | |
| 16 class DictionaryValue; | |
|
oystein (OOO til 10th of July)
2017/05/25 16:55:26
What's this? If was originally a forward declarati
chiniforooshan
2017/05/25 19:45:32
Done.
| |
| 17 } | |
| 18 | |
| 19 namespace tracing { | |
| 20 | |
| 21 class Recorder : public mojom::Recorder { | |
| 22 public: | |
| 23 // The tracing service creates instances of the |Recorder| class and send them | |
| 24 // to agents. The agents then use the recorder for sending trace data to the | |
| 25 // tracing service. | |
| 26 // | |
| 27 // |data_is_array| tells the recorder whether the data is of type array or | |
| 28 // string. Chunks of type array are concatenated using a comma as the | |
| 29 // separator; chuunks of type string are concatenated without a separator. | |
| 30 // | |
| 31 // |on_data_change_callback| is run whenever the recorder receives data from | |
| 32 // the agent or when the connection is lost to notify the tracing service of | |
| 33 // the data change. | |
| 34 // | |
| 35 // |background_task_runner| is used so that if the tracing service is run on | |
| 36 // the UI thread we do not block it. So buffering trace events and copying | |
| 37 // them to data pipes are done on a background thread. | |
| 38 Recorder( | |
|
oystein (OOO til 10th of July)
2017/05/25 16:55:26
The convention is usually that the Mojo interface
chiniforooshan
2017/05/25 19:45:32
It looks like the convention is to name the implem
oystein (OOO til 10th of July)
2017/05/25 20:01:24
Also ImageDecoderImpl, BatteryMonitorImpl, Clipb
| |
| 39 mojom::RecorderRequest request, | |
| 40 bool data_is_array, | |
| 41 const base::Closure& on_data_change_callback, | |
| 42 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); | |
| 43 ~Recorder() override; | |
| 44 | |
| 45 const std::string& data() const { | |
| 46 // All access to |data_| should be done on the background thread. | |
| 47 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | |
|
oystein (OOO til 10th of July)
2017/05/25 16:55:27
"base/logging.h" for these
chiniforooshan
2017/05/25 19:45:32
Done.
| |
| 48 return data_; | |
| 49 } | |
| 50 | |
| 51 void clear_data() { | |
| 52 // All access to |data_| should be done on the background thread. | |
| 53 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | |
| 54 data_.clear(); | |
| 55 } | |
| 56 | |
| 57 const base::DictionaryValue& metadata() const { return metadata_; } | |
| 58 bool is_recording() const { return is_recording_; } | |
| 59 bool data_is_array() const { return data_is_array_; } | |
| 60 | |
| 61 private: | |
| 62 friend class RecorderTest; // For testing. | |
| 63 // mojom::Recorder | |
| 64 // These are called by agents for sending trace data to the tracing service. | |
| 65 void AddChunk(const std::string& chunk) override; | |
| 66 void AddMetadata(std::unique_ptr<base::DictionaryValue> metadata) override; | |
| 67 | |
| 68 void OnConnectionError(); | |
| 69 | |
| 70 std::string data_; | |
| 71 base::DictionaryValue metadata_; | |
| 72 bool is_recording_; | |
| 73 bool data_is_array_; | |
| 74 base::Closure on_data_change_callback_; | |
| 75 // To avoid blocking the UI thread if the tracing service is run on the UI | |
| 76 // thread, we make sure that buffering trace events and copying them to the | |
| 77 // final stream is done on a background thread. | |
| 78 scoped_refptr<base::SequencedTaskRunner> background_task_runner_; | |
| 79 mojo::Binding<mojom::Recorder> binding_; | |
| 80 base::WeakPtrFactory<Recorder> weak_factory_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(Recorder); | |
|
oystein (OOO til 10th of July)
2017/05/25 16:55:26
nit: base/macros.h
chiniforooshan
2017/05/25 19:45:32
Done.
| |
| 83 }; | |
| 84 | |
| 85 } // namespace tracing | |
| 86 #endif // SERVICES_RESOURCE_COORDINATOR_TRACING_RECORDER_H_ | |
| OLD | NEW |