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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_
11 #include "base/memory/weak_ptr.h"
12 #include "base/trace_event/trace_event.h"
13 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h"
14 #include "content/public/browser/tracing_controller.h"
17 class RefCountedString
;
24 class DevToolsIOContext
;
28 class TracingHandler
{
30 typedef DevToolsProtocolClient::Response Response
;
32 enum Target
{ Browser
, Renderer
};
33 TracingHandler(Target target
, DevToolsIOContext
* io_context
);
34 virtual ~TracingHandler();
36 void SetClient(scoped_ptr
<Client
> client
);
39 void OnTraceDataCollected(const std::string
& trace_fragment
);
40 void OnTraceComplete();
41 void OnTraceToStreamComplete(const std::string
& stream_handle
);
44 Response
Start(DevToolsCommandId command_id
,
45 const std::string
* categories
,
46 const std::string
* options
,
47 const double* buffer_usage_reporting_interval
,
48 const std::string
* transfer_mode
);
49 Response
End(DevToolsCommandId command_id
);
50 Response
GetCategories(DevToolsCommandId command
);
51 Response
RequestMemoryDump(DevToolsCommandId command_id
);
53 bool did_initiate_recording() { return did_initiate_recording_
; }
56 void OnRecordingEnabled(DevToolsCommandId command_id
);
57 void OnBufferUsage(float percent_full
, size_t approximate_event_count
);
58 void OnCategoriesReceived(DevToolsCommandId command_id
,
59 const std::set
<std::string
>& category_set
);
60 void OnMemoryDumpFinished(DevToolsCommandId command_id
,
64 void SetupTimer(double usage_reporting_interval
);
65 void DisableRecording(
66 const scoped_refptr
<TracingController::TraceDataSink
>& trace_data_sink
);
67 bool IsRecording() const;
68 static bool IsStartupTracingActive();
70 scoped_ptr
<base::Timer
> buffer_usage_poll_timer_
;
73 scoped_ptr
<Client
> client_
;
74 DevToolsIOContext
* io_context_
;
75 bool did_initiate_recording_
;
76 bool return_as_stream_
;
77 base::WeakPtrFactory
<TracingHandler
> weak_factory_
;
79 DISALLOW_COPY_AND_ASSIGN(TracingHandler
);
82 } // namespace tracing
83 } // namespace devtools
84 } // namespace content
86 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TRACING_HANDLER_H_