| 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 #include "content/browser/devtools/protocol/tracing_handler.h" | 5 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 if (isupper(c)) { | 41 if (isupper(c)) { |
| 42 out_str.push_back(separator); | 42 out_str.push_back(separator); |
| 43 out_str.push_back(tolower(c)); | 43 out_str.push_back(tolower(c)); |
| 44 } else { | 44 } else { |
| 45 out_str.push_back(c); | 45 out_str.push_back(c); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 return out_str; | 48 return out_str; |
| 49 } | 49 } |
| 50 | 50 |
| 51 scoped_ptr<base::Value> ConvertDictKeyStyle(const base::Value& value) { | 51 std::unique_ptr<base::Value> ConvertDictKeyStyle(const base::Value& value) { |
| 52 const base::DictionaryValue* dict = nullptr; | 52 const base::DictionaryValue* dict = nullptr; |
| 53 if (value.GetAsDictionary(&dict)) { | 53 if (value.GetAsDictionary(&dict)) { |
| 54 scoped_ptr<base::DictionaryValue> out_dict(new base::DictionaryValue()); | 54 std::unique_ptr<base::DictionaryValue> out_dict( |
| 55 new base::DictionaryValue()); |
| 55 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); | 56 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
| 56 it.Advance()) { | 57 it.Advance()) { |
| 57 out_dict->Set(ConvertFromCamelCase(it.key(), '_'), | 58 out_dict->Set(ConvertFromCamelCase(it.key(), '_'), |
| 58 ConvertDictKeyStyle(it.value())); | 59 ConvertDictKeyStyle(it.value())); |
| 59 } | 60 } |
| 60 return std::move(out_dict); | 61 return std::move(out_dict); |
| 61 } | 62 } |
| 62 | 63 |
| 63 const base::ListValue* list = nullptr; | 64 const base::ListValue* list = nullptr; |
| 64 if (value.GetAsList(&list)) { | 65 if (value.GetAsList(&list)) { |
| 65 scoped_ptr<base::ListValue> out_list(new base::ListValue()); | 66 std::unique_ptr<base::ListValue> out_list(new base::ListValue()); |
| 66 for (const auto& value : *list) | 67 for (const auto& value : *list) |
| 67 out_list->Append(ConvertDictKeyStyle(*value)); | 68 out_list->Append(ConvertDictKeyStyle(*value)); |
| 68 return std::move(out_list); | 69 return std::move(out_list); |
| 69 } | 70 } |
| 70 | 71 |
| 71 return value.CreateDeepCopy(); | 72 return value.CreateDeepCopy(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 class DevToolsTraceSinkProxy : public TracingController::TraceDataSink { | 75 class DevToolsTraceSinkProxy : public TracingController::TraceDataSink { |
| 75 public: | 76 public: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 : target_(target), | 135 : target_(target), |
| 135 io_context_(io_context), | 136 io_context_(io_context), |
| 136 frame_tree_node_id_(frame_tree_node_id), | 137 frame_tree_node_id_(frame_tree_node_id), |
| 137 did_initiate_recording_(false), | 138 did_initiate_recording_(false), |
| 138 return_as_stream_(false), | 139 return_as_stream_(false), |
| 139 weak_factory_(this) {} | 140 weak_factory_(this) {} |
| 140 | 141 |
| 141 TracingHandler::~TracingHandler() { | 142 TracingHandler::~TracingHandler() { |
| 142 } | 143 } |
| 143 | 144 |
| 144 void TracingHandler::SetClient(scoped_ptr<Client> client) { | 145 void TracingHandler::SetClient(std::unique_ptr<Client> client) { |
| 145 client_.swap(client); | 146 client_.swap(client); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void TracingHandler::Detached() { | 149 void TracingHandler::Detached() { |
| 149 if (did_initiate_recording_) | 150 if (did_initiate_recording_) |
| 150 StopTracing(scoped_refptr<TracingController::TraceDataSink>()); | 151 StopTracing(scoped_refptr<TracingController::TraceDataSink>()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) { | 154 void TracingHandler::OnTraceDataCollected(const std::string& trace_fragment) { |
| 154 // Hand-craft protocol notification message so we can substitute JSON | 155 // Hand-craft protocol notification message so we can substitute JSON |
| (...skipping 15 matching lines...) Expand all Loading... |
| 170 client_->TracingComplete( | 171 client_->TracingComplete( |
| 171 TracingCompleteParams::Create()->set_stream(stream_handle)); | 172 TracingCompleteParams::Create()->set_stream(stream_handle)); |
| 172 } | 173 } |
| 173 | 174 |
| 174 Response TracingHandler::Start( | 175 Response TracingHandler::Start( |
| 175 DevToolsCommandId command_id, | 176 DevToolsCommandId command_id, |
| 176 const std::string* categories, | 177 const std::string* categories, |
| 177 const std::string* options, | 178 const std::string* options, |
| 178 const double* buffer_usage_reporting_interval, | 179 const double* buffer_usage_reporting_interval, |
| 179 const std::string* transfer_mode, | 180 const std::string* transfer_mode, |
| 180 const scoped_ptr<base::DictionaryValue>& config) { | 181 const std::unique_ptr<base::DictionaryValue>& config) { |
| 181 if (IsTracing()) | 182 if (IsTracing()) |
| 182 return Response::InternalError("Tracing is already started"); | 183 return Response::InternalError("Tracing is already started"); |
| 183 | 184 |
| 184 if (config && (categories || options)) { | 185 if (config && (categories || options)) { |
| 185 return Response::InternalError( | 186 return Response::InternalError( |
| 186 "Either trace config (preferred), or categories+options should be " | 187 "Either trace config (preferred), or categories+options should be " |
| 187 "specified, but not both."); | 188 "specified, but not both."); |
| 188 } | 189 } |
| 189 | 190 |
| 190 did_initiate_recording_ = true; | 191 did_initiate_recording_ = true; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 333 } |
| 333 | 334 |
| 334 bool TracingHandler::IsStartupTracingActive() { | 335 bool TracingHandler::IsStartupTracingActive() { |
| 335 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() && | 336 return ::tracing::TraceConfigFile::GetInstance()->IsEnabled() && |
| 336 TracingController::GetInstance()->IsTracing(); | 337 TracingController::GetInstance()->IsTracing(); |
| 337 } | 338 } |
| 338 | 339 |
| 339 // static | 340 // static |
| 340 base::trace_event::TraceConfig TracingHandler::GetTraceConfigFromDevToolsConfig( | 341 base::trace_event::TraceConfig TracingHandler::GetTraceConfigFromDevToolsConfig( |
| 341 const base::DictionaryValue& devtools_config) { | 342 const base::DictionaryValue& devtools_config) { |
| 342 scoped_ptr<base::Value> value = ConvertDictKeyStyle(devtools_config); | 343 std::unique_ptr<base::Value> value = ConvertDictKeyStyle(devtools_config); |
| 343 DCHECK(value && value->IsType(base::Value::TYPE_DICTIONARY)); | 344 DCHECK(value && value->IsType(base::Value::TYPE_DICTIONARY)); |
| 344 scoped_ptr<base::DictionaryValue> tracing_dict( | 345 std::unique_ptr<base::DictionaryValue> tracing_dict( |
| 345 static_cast<base::DictionaryValue*>(value.release())); | 346 static_cast<base::DictionaryValue*>(value.release())); |
| 346 | 347 |
| 347 std::string mode; | 348 std::string mode; |
| 348 if (tracing_dict->GetString(kRecordModeParam, &mode)) | 349 if (tracing_dict->GetString(kRecordModeParam, &mode)) |
| 349 tracing_dict->SetString(kRecordModeParam, ConvertFromCamelCase(mode, '-')); | 350 tracing_dict->SetString(kRecordModeParam, ConvertFromCamelCase(mode, '-')); |
| 350 | 351 |
| 351 return base::trace_event::TraceConfig(*tracing_dict); | 352 return base::trace_event::TraceConfig(*tracing_dict); |
| 352 } | 353 } |
| 353 | 354 |
| 354 } // namespace tracing | 355 } // namespace tracing |
| 355 } // namespace devtools | 356 } // namespace devtools |
| 356 } // namespace content | 357 } // namespace content |
| OLD | NEW |