| 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 Response Disable() override; |
| 45 | 42 |
| 46 void OnTraceDataCollected(const std::string& trace_fragment); | 43 void OnTraceDataCollected(const std::string& trace_fragment); |
| 47 void OnTraceComplete(); | 44 void OnTraceComplete(); |
| 48 void OnTraceToStreamComplete(const std::string& stream_handle); | 45 void OnTraceToStreamComplete(const std::string& stream_handle); |
| 49 | 46 |
| 50 // Protocol methods. | 47 // Protocol methods. |
| 51 Response Start(DevToolsCommandId command_id, | 48 void Start(Maybe<std::string> categories, |
| 52 const std::string* categories, | 49 Maybe<std::string> options, |
| 53 const std::string* options, | 50 Maybe<double> buffer_usage_reporting_interval, |
| 54 const double* buffer_usage_reporting_interval, | 51 Maybe<std::string> transfer_mode, |
| 55 const std::string* transfer_mode, | 52 Maybe<Tracing::TraceConfig> config, |
| 56 const std::unique_ptr<base::DictionaryValue>& config); | 53 std::unique_ptr<StartCallback> callback) override; |
| 57 Response End(DevToolsCommandId command_id); | 54 void End(std::unique_ptr<EndCallback> callback) override; |
| 58 Response GetCategories(DevToolsCommandId command); | 55 void GetCategories(std::unique_ptr<GetCategoriesCallback> callback) override; |
| 59 Response RequestMemoryDump(DevToolsCommandId command_id); | 56 void RequestMemoryDump( |
| 60 Response RecordClockSyncMarker(const std::string& sync_id); | 57 std::unique_ptr<RequestMemoryDumpCallback> callback) override; |
| 58 Response RecordClockSyncMarker(const std::string& sync_id) override; |
| 61 | 59 |
| 62 bool did_initiate_recording() { return did_initiate_recording_; } | 60 bool did_initiate_recording() { return did_initiate_recording_; } |
| 63 | 61 |
| 64 private: | 62 private: |
| 65 void OnRecordingEnabled(DevToolsCommandId command_id); | 63 void OnRecordingEnabled(std::unique_ptr<StartCallback> callback); |
| 66 void OnBufferUsage(float percent_full, size_t approximate_event_count); | 64 void OnBufferUsage(float percent_full, size_t approximate_event_count); |
| 67 void OnCategoriesReceived(DevToolsCommandId command_id, | 65 void OnCategoriesReceived(std::unique_ptr<GetCategoriesCallback> callback, |
| 68 const std::set<std::string>& category_set); | 66 const std::set<std::string>& category_set); |
| 69 void OnMemoryDumpFinished(DevToolsCommandId command_id, | 67 void OnMemoryDumpFinished(std::unique_ptr<RequestMemoryDumpCallback> callback, |
| 70 uint64_t dump_guid, | 68 uint64_t dump_guid, |
| 71 bool success); | 69 bool success); |
| 72 | 70 |
| 73 void SetupTimer(double usage_reporting_interval); | 71 void SetupTimer(double usage_reporting_interval); |
| 74 void StopTracing( | 72 void StopTracing( |
| 75 const scoped_refptr<TracingController::TraceDataSink>& trace_data_sink); | 73 const scoped_refptr<TracingController::TraceDataSink>& trace_data_sink); |
| 76 bool IsTracing() const; | 74 bool IsTracing() const; |
| 77 static bool IsStartupTracingActive(); | 75 static bool IsStartupTracingActive(); |
| 78 CONTENT_EXPORT static base::trace_event::TraceConfig | 76 CONTENT_EXPORT static base::trace_event::TraceConfig |
| 79 GetTraceConfigFromDevToolsConfig( | 77 GetTraceConfigFromDevToolsConfig( |
| 80 const base::DictionaryValue& devtools_config); | 78 const base::DictionaryValue& devtools_config); |
| 81 | 79 |
| 82 std::unique_ptr<base::Timer> buffer_usage_poll_timer_; | 80 std::unique_ptr<base::Timer> buffer_usage_poll_timer_; |
| 83 Target target_; | 81 Target target_; |
| 84 | 82 |
| 85 std::unique_ptr<Client> client_; | 83 std::unique_ptr<Tracing::Frontend> frontend_; |
| 86 DevToolsIOContext* io_context_; | 84 DevToolsIOContext* io_context_; |
| 87 int frame_tree_node_id_; | 85 int frame_tree_node_id_; |
| 88 bool did_initiate_recording_; | 86 bool did_initiate_recording_; |
| 89 bool return_as_stream_; | 87 bool return_as_stream_; |
| 90 base::WeakPtrFactory<TracingHandler> weak_factory_; | 88 base::WeakPtrFactory<TracingHandler> weak_factory_; |
| 91 | 89 |
| 92 FRIEND_TEST_ALL_PREFIXES(TracingHandlerTest, | 90 FRIEND_TEST_ALL_PREFIXES(TracingHandlerTest, |
| 93 GetTraceConfigFromDevToolsConfig); | 91 GetTraceConfigFromDevToolsConfig); |
| 94 DISALLOW_COPY_AND_ASSIGN(TracingHandler); | 92 DISALLOW_COPY_AND_ASSIGN(TracingHandler); |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 } // namespace tracing | 95 } // namespace protocol |
| 98 } // namespace devtools | |
| 99 } // namespace content | 96 } // namespace content |
| 100 | 97 |
| 101 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ | 98 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_ |
| OLD | NEW |