| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" | 18 #include "content/browser/devtools/protocol/tracing.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/public/browser/tracing_controller.h" | 20 #include "content/public/browser/tracing_controller.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class Timer; | 23 class Timer; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 namespace devtools { | |
| 28 | 27 |
| 29 class DevToolsIOContext; | 28 class DevToolsIOContext; |
| 30 | 29 |
| 31 namespace tracing { | 30 namespace protocol { |
| 32 | 31 |
| 33 class TracingHandler { | 32 class TracingHandler : public Tracing::Backend { |
| 34 public: | 33 public: |
| 35 typedef DevToolsProtocolClient::Response Response; | |
| 36 | |
| 37 enum Target { Browser, Renderer }; | 34 enum Target { Browser, Renderer }; |
| 38 TracingHandler(Target target, | 35 TracingHandler(Target target, |
| 39 int frame_tree_node_id, | 36 int frame_tree_node_id, |
| 40 DevToolsIOContext* io_context); | 37 DevToolsIOContext* io_context); |
| 41 virtual ~TracingHandler(); | 38 ~TracingHandler() override; |
| 42 | 39 |
| 43 void SetClient(std::unique_ptr<Client> client); | 40 void Wire(UberDispatcher*); |
| 44 void Detached(); | 41 void Detached(); |
| 42 Response Disable() override; |
| 45 | 43 |
| 46 void OnTraceDataCollected(const std::string& trace_fragment); | 44 void OnTraceDataCollected(const std::string& trace_fragment); |
| 47 void OnTraceComplete(); | 45 void OnTraceComplete(); |
| 48 void OnTraceToStreamComplete(const std::string& stream_handle); | 46 void OnTraceToStreamComplete(const std::string& stream_handle); |
| 49 | 47 |
| 50 // Protocol methods. | 48 // Protocol methods. |
| 51 Response Start(DevToolsCommandId command_id, | 49 void Start(Maybe<std::string> categories, |
| 52 const std::string* categories, | 50 Maybe<std::string> options, |
| 53 const std::string* options, | 51 Maybe<double> buffer_usage_reporting_interval, |
| 54 const double* buffer_usage_reporting_interval, | 52 Maybe<std::string> transfer_mode, |
| 55 const std::string* transfer_mode, | 53 Maybe<Tracing::TraceConfig> config, |
| 56 const std::unique_ptr<base::DictionaryValue>& config); | 54 std::unique_ptr<StartCallback> callback) override; |
| 57 Response End(DevToolsCommandId command_id); | 55 void End(std::unique_ptr<EndCallback> callback) override; |
| 58 Response GetCategories(DevToolsCommandId command); | 56 void GetCategories(std::unique_ptr<GetCategoriesCallback> callback) override; |
| 59 Response RequestMemoryDump(DevToolsCommandId command_id); | 57 void RequestMemoryDump( |
| 60 Response RecordClockSyncMarker(const std::string& sync_id); | 58 std::unique_ptr<RequestMemoryDumpCallback> callback) override; |
| 59 Response RecordClockSyncMarker(const std::string& sync_id) override; |
| 61 | 60 |
| 62 bool did_initiate_recording() { return did_initiate_recording_; } | 61 bool did_initiate_recording() { return did_initiate_recording_; } |
| 63 | 62 |
| 64 private: | 63 private: |
| 65 void OnRecordingEnabled(DevToolsCommandId command_id); | 64 void OnRecordingEnabled(std::unique_ptr<StartCallback> callback); |
| 66 void OnBufferUsage(float percent_full, size_t approximate_event_count); | 65 void OnBufferUsage(float percent_full, size_t approximate_event_count); |
| 67 void OnCategoriesReceived(DevToolsCommandId command_id, | 66 void OnCategoriesReceived(std::unique_ptr<GetCategoriesCallback> callback, |
| 68 const std::set<std::string>& category_set); | 67 const std::set<std::string>& category_set); |
| 69 void OnMemoryDumpFinished(DevToolsCommandId command_id, | 68 void OnMemoryDumpFinished(std::unique_ptr<RequestMemoryDumpCallback> callback, |
| 70 uint64_t dump_guid, | 69 uint64_t dump_guid, |
| 71 bool success); | 70 bool success); |
| 72 | 71 |
| 73 void SetupTimer(double usage_reporting_interval); | 72 void SetupTimer(double usage_reporting_interval); |
| 74 void StopTracing( | 73 void StopTracing( |
| 75 const scoped_refptr<TracingController::TraceDataSink>& trace_data_sink); | 74 const scoped_refptr<TracingController::TraceDataSink>& trace_data_sink); |
| 76 bool IsTracing() const; | 75 bool IsTracing() const; |
| 77 static bool IsStartupTracingActive(); | 76 static bool IsStartupTracingActive(); |
| 78 CONTENT_EXPORT static base::trace_event::TraceConfig | 77 CONTENT_EXPORT static base::trace_event::TraceConfig |
| 79 GetTraceConfigFromDevToolsConfig( | 78 GetTraceConfigFromDevToolsConfig( |
| 80 const base::DictionaryValue& devtools_config); | 79 const base::DictionaryValue& devtools_config); |
| 81 | 80 |
| 82 std::unique_ptr<base::Timer> buffer_usage_poll_timer_; | 81 std::unique_ptr<base::Timer> buffer_usage_poll_timer_; |
| 83 Target target_; | 82 Target target_; |
| 84 | 83 |
| 85 std::unique_ptr<Client> client_; | 84 std::unique_ptr<Tracing::Frontend> frontend_; |
| 86 DevToolsIOContext* io_context_; | 85 DevToolsIOContext* io_context_; |
| 87 int frame_tree_node_id_; | 86 int frame_tree_node_id_; |
| 88 bool did_initiate_recording_; | 87 bool did_initiate_recording_; |
| 89 bool return_as_stream_; | 88 bool return_as_stream_; |
| 90 base::WeakPtrFactory<TracingHandler> weak_factory_; | 89 base::WeakPtrFactory<TracingHandler> weak_factory_; |
| 91 | 90 |
| 92 FRIEND_TEST_ALL_PREFIXES(TracingHandlerTest, | 91 FRIEND_TEST_ALL_PREFIXES(TracingHandlerTest, |
| 93 GetTraceConfigFromDevToolsConfig); | 92 GetTraceConfigFromDevToolsConfig); |
| 94 DISALLOW_COPY_AND_ASSIGN(TracingHandler); | 93 DISALLOW_COPY_AND_ASSIGN(TracingHandler); |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 } // namespace tracing | 96 } // namespace protocol |
| 98 } // namespace devtools | |
| 99 } // namespace content | 97 } // namespace content |
| 100 | 98 |
| 101 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ | 99 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ |
| OLD | NEW |