Chromium Code Reviews| Index: content/browser/devtools/protocol/tracing_handler.cc |
| diff --git a/content/browser/devtools/protocol/tracing_handler.cc b/content/browser/devtools/protocol/tracing_handler.cc |
| index 97c08edbe5e16cef729967f0aeb00e651ae8d44f..ae65ddddbbfdcf2b540af054ec6e61f7a297db46 100644 |
| --- a/content/browser/devtools/protocol/tracing_handler.cc |
| +++ b/content/browser/devtools/protocol/tracing_handler.cc |
| @@ -22,10 +22,7 @@ |
| #include "content/browser/tracing/tracing_controller_impl.h" |
| namespace content { |
| -namespace devtools { |
| -namespace tracing { |
| - |
| -using Response = DevToolsProtocolClient::Response; |
| +namespace protocol { |
| namespace { |
| @@ -131,13 +128,19 @@ TracingHandler::TracingHandler(TracingHandler::Target target, |
| TracingHandler::~TracingHandler() { |
| } |
| -void TracingHandler::SetClient(std::unique_ptr<Client> client) { |
| - client_.swap(client); |
| +void TracingHandler::Wire(UberDispatcher* dispatcher) { |
| + frontend_.reset(new Tracing::Frontend(dispatcher->channel())); |
| + Tracing::Dispatcher::wire(dispatcher, this); |
| } |
| void TracingHandler::Detached() { |
| + Disable(); |
| +} |
| + |
| +Response TracingHandler::Disable() { |
| if (did_initiate_recording_) |
| StopTracing(scoped_refptr<TracingController::TraceDataSink>()); |
| + return Response::OK(); |
| } |
| void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) { |
| @@ -149,74 +152,82 @@ void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) { |
| message.reserve(message.size() + trace_fragment.size() + messageSuffixSize); |
| message += trace_fragment; |
| message += "] } }"; |
| - client_->SendRawNotification(message); |
| + frontend_->sendRawNotification(message); |
| } |
| void TracingHandler::OnTraceComplete() { |
| - client_->TracingComplete(TracingCompleteParams::Create()); |
| + frontend_->TracingComplete(); |
| } |
| void TracingHandler::OnTraceToStreamComplete(const std::string& stream_handle) { |
| - client_->TracingComplete( |
| - TracingCompleteParams::Create()->set_stream(stream_handle)); |
| + frontend_->TracingComplete(stream_handle); |
| } |
| -Response TracingHandler::Start( |
| - DevToolsCommandId command_id, |
| - const std::string* categories, |
| - const std::string* options, |
| - const double* buffer_usage_reporting_interval, |
| - const std::string* transfer_mode, |
| - const std::unique_ptr<base::DictionaryValue>& config) { |
| +void TracingHandler::Start(Maybe<std::string> categories, |
| + Maybe<std::string> options, |
| + Maybe<double> buffer_usage_reporting_interval, |
| + Maybe<std::string> transfer_mode, |
| + Maybe<Tracing::TraceConfig> config, |
| + std::unique_ptr<StartCallback> callback) { |
| + bool return_as_stream = transfer_mode.fromMaybe("") == |
| + Tracing::Start::TransferModeEnum::ReturnAsStream; |
| if (IsTracing()) { |
| if (!did_initiate_recording_ && IsStartupTracingActive()) { |
| // If tracing is already running because it was initiated by startup |
| // tracing, honor the transfer mode update, as that's the only way |
| // for the client to communicate it. |
| - return_as_stream_ = |
| - transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream; |
| + return_as_stream_ = return_as_stream; |
| } |
| - return Response::InternalError("Tracing is already started"); |
| + callback->sendFailure(Response::Error("Tracing is already started")); |
| + return; |
| } |
| - if (config && (categories || options)) { |
| - return Response::InternalError( |
| + if (config.isJust() && (categories.isJust() || options.isJust())) { |
| + callback->sendFailure(Response::Error( |
|
caseq
2016/11/15 18:33:59
InvalidParams
dgozman
2016/11/17 21:51:07
Done.
|
| "Either trace config (preferred), or categories+options should be " |
| - "specified, but not both."); |
| + "specified, but not both.")); |
| + return; |
| } |
| did_initiate_recording_ = true; |
| - return_as_stream_ = |
| - transfer_mode && *transfer_mode == start::kTransferModeReturnAsStream; |
| - if (buffer_usage_reporting_interval) |
| - SetupTimer(*buffer_usage_reporting_interval); |
| + return_as_stream_ = return_as_stream; |
| + if (buffer_usage_reporting_interval.isJust()) |
| + SetupTimer(buffer_usage_reporting_interval.fromJust()); |
| base::trace_event::TraceConfig trace_config; |
| - if (config) { |
| - trace_config = GetTraceConfigFromDevToolsConfig(*config); |
| - } else if (categories || options) { |
| + if (config.isJust()) { |
| + std::unique_ptr<base::Value> value = |
| + protocol::toBaseValue(config.fromJust()->serialize().get(), 1000); |
| + if (value && value->IsType(base::Value::TYPE_DICTIONARY)) { |
| + trace_config = GetTraceConfigFromDevToolsConfig( |
| + *static_cast<base::DictionaryValue*>(value.get())); |
| + } |
| + } else if (categories.isJust() || options.isJust()) { |
| trace_config = base::trace_event::TraceConfig( |
| - categories ? *categories : std::string(), |
| - options ? *options : std::string()); |
| + categories.fromMaybe(std::string()), |
|
caseq
2016/11/15 18:33:59
""
dgozman
2016/11/17 21:51:07
Done.
|
| + options.fromMaybe(std::string())); |
|
caseq
2016/11/15 18:33:59
""
|
| } |
| // If inspected target is a render process Tracing.start will be handled by |
| // tracing agent in the renderer. |
| + if (target_ == Renderer) |
| + callback->fallThrough(); |
| + |
| TracingController::GetInstance()->StartTracing( |
| trace_config, |
| base::Bind(&TracingHandler::OnRecordingEnabled, |
| weak_factory_.GetWeakPtr(), |
| - command_id)); |
| - |
| - return target_ == Renderer ? Response::FallThrough() : Response::OK(); |
| + base::Passed(std::move(callback)))); |
| } |
| -Response TracingHandler::End(DevToolsCommandId command_id) { |
| +void TracingHandler::End(std::unique_ptr<EndCallback> callback) { |
| // Startup tracing triggered by --trace-config-file is a special case, where |
| // tracing is started automatically upon browser startup and can be stopped |
| // via DevTools. |
| - if (!did_initiate_recording_ && !IsStartupTracingActive()) |
| - return Response::InternalError("Tracing is not started"); |
| + if (!did_initiate_recording_ && !IsStartupTracingActive()) { |
| + callback->sendFailure(Response::Error("Tracing is not started")); |
| + return; |
| + } |
| scoped_refptr<TracingController::TraceDataSink> sink; |
| if (return_as_stream_) { |
| @@ -228,70 +239,71 @@ Response TracingHandler::End(DevToolsCommandId command_id) { |
| StopTracing(sink); |
| // If inspected target is a render process Tracing.end will be handled by |
| // tracing agent in the renderer. |
| - return target_ == Renderer ? Response::FallThrough() : Response::OK(); |
| + if (target_ == Renderer) |
| + callback->fallThrough(); |
| + else |
| + callback->sendSuccess(); |
| } |
| -Response TracingHandler::GetCategories(DevToolsCommandId command_id) { |
| +void TracingHandler::GetCategories( |
| + std::unique_ptr<GetCategoriesCallback> callback) { |
| TracingController::GetInstance()->GetCategories( |
| base::Bind(&TracingHandler::OnCategoriesReceived, |
| weak_factory_.GetWeakPtr(), |
| - command_id)); |
| - return Response::OK(); |
| + base::Passed(std::move(callback)))); |
| } |
| -void TracingHandler::OnRecordingEnabled(DevToolsCommandId command_id) { |
| +void TracingHandler::OnRecordingEnabled( |
| + std::unique_ptr<StartCallback> callback) { |
| TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| "TracingStartedInBrowser", TRACE_EVENT_SCOPE_THREAD, |
| "frameTreeNodeId", frame_tree_node_id_); |
| if (target_ != Renderer) |
| - client_->SendStartResponse(command_id, StartResponse::Create()); |
| + callback->sendSuccess(); |
| } |
| void TracingHandler::OnBufferUsage(float percent_full, |
| size_t approximate_event_count) { |
| // TODO(crbug426117): remove set_value once all clients have switched to |
| // the new interface of the event. |
| - client_->BufferUsage(BufferUsageParams::Create() |
| - ->set_value(percent_full) |
| - ->set_percent_full(percent_full) |
| - ->set_event_count(approximate_event_count)); |
| + frontend_->BufferUsage(percent_full, percent_full, approximate_event_count); |
| } |
| void TracingHandler::OnCategoriesReceived( |
| - DevToolsCommandId command_id, |
| + std::unique_ptr<GetCategoriesCallback> callback, |
| const std::set<std::string>& category_set) { |
| - std::vector<std::string> categories; |
| + std::unique_ptr<protocol::Array<std::string>> categories = |
| + protocol::Array<std::string>::create(); |
| for (const std::string& category : category_set) |
| - categories.push_back(category); |
| - client_->SendGetCategoriesResponse(command_id, |
| - GetCategoriesResponse::Create()->set_categories(categories)); |
| + categories->addItem(category); |
| + callback->sendSuccess(std::move(categories)); |
| } |
| -Response TracingHandler::RequestMemoryDump(DevToolsCommandId command_id) { |
| - if (!IsTracing()) |
| - return Response::InternalError("Tracing is not started"); |
| +void TracingHandler::RequestMemoryDump( |
| + std::unique_ptr<RequestMemoryDumpCallback> callback) { |
| + if (!IsTracing()) { |
| + callback->sendFailure(Response::Error("Tracing is not started")); |
| + return; |
| + } |
| base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump( |
| base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, |
| base::trace_event::MemoryDumpLevelOfDetail::DETAILED, |
| base::Bind(&TracingHandler::OnMemoryDumpFinished, |
| - weak_factory_.GetWeakPtr(), command_id)); |
| - return Response::OK(); |
| + weak_factory_.GetWeakPtr(), |
| + base::Passed(std::move(callback)))); |
| } |
| -void TracingHandler::OnMemoryDumpFinished(DevToolsCommandId command_id, |
| - uint64_t dump_guid, |
| - bool success) { |
| - client_->SendRequestMemoryDumpResponse( |
| - command_id, |
| - RequestMemoryDumpResponse::Create() |
| - ->set_dump_guid(base::StringPrintf("0x%" PRIx64, dump_guid)) |
| - ->set_success(success)); |
| +void TracingHandler::OnMemoryDumpFinished( |
| + std::unique_ptr<RequestMemoryDumpCallback> callback, |
| + uint64_t dump_guid, |
| + bool success) { |
| + callback->sendSuccess(base::StringPrintf("0x%" PRIx64, dump_guid), success); |
| } |
| Response TracingHandler::RecordClockSyncMarker(const std::string& sync_id) { |
| if (!IsTracing()) |
| - return Response::InternalError("Tracing is not started"); |
| + return Response::Error("Tracing is not started"); |
| TracingControllerImpl::GetInstance()->RecordClockSyncMarker( |
| sync_id, |
| @@ -350,5 +362,4 @@ base::trace_event::TraceConfig TracingHandler::GetTraceConfigFromDevToolsConfig( |
| } |
| } // namespace tracing |
| -} // namespace devtools |
| -} // namespace content |
| +} // namespace protocol |