| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/devtools_tracing_handler.h" | 5 #include "content/browser/devtools/devtools_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/callback.h" | 10 #include "base/callback.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 base::DeleteFile(path, false); | 41 base::DeleteFile(path, false); |
| 42 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 42 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 43 base::Bind(callback, make_scoped_refptr( | 43 base::Bind(callback, make_scoped_refptr( |
| 44 base::RefCountedString::TakeString(&trace_data)))); | 44 base::RefCountedString::TakeString(&trace_data)))); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 DevToolsTracingHandler::DevToolsTracingHandler( | 49 DevToolsTracingHandler::DevToolsTracingHandler( |
| 50 DevToolsTracingHandler::Target target) | 50 DevToolsTracingHandler::Target target) |
| 51 : weak_factory_(this), target_(target) { | 51 : weak_factory_(this), target_(target), is_recording_(false) { |
| 52 RegisterCommandHandler(devtools::Tracing::start::kName, | 52 RegisterCommandHandler(devtools::Tracing::start::kName, |
| 53 base::Bind(&DevToolsTracingHandler::OnStart, | 53 base::Bind(&DevToolsTracingHandler::OnStart, |
| 54 base::Unretained(this))); | 54 base::Unretained(this))); |
| 55 RegisterCommandHandler(devtools::Tracing::end::kName, | 55 RegisterCommandHandler(devtools::Tracing::end::kName, |
| 56 base::Bind(&DevToolsTracingHandler::OnEnd, | 56 base::Bind(&DevToolsTracingHandler::OnEnd, |
| 57 base::Unretained(this))); | 57 base::Unretained(this))); |
| 58 RegisterCommandHandler(devtools::Tracing::getCategories::kName, | 58 RegisterCommandHandler(devtools::Tracing::getCategories::kName, |
| 59 base::Bind(&DevToolsTracingHandler::OnGetCategories, | 59 base::Bind(&DevToolsTracingHandler::OnGetCategories, |
| 60 base::Unretained(this))); | 60 base::Unretained(this))); |
| 61 } | 61 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } else if (*iter == kEnableSampling) { | 131 } else if (*iter == kEnableSampling) { |
| 132 ret |= TracingController::ENABLE_SAMPLING; | 132 ret |= TracingController::ENABLE_SAMPLING; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 return static_cast<TracingController::Options>(ret); | 135 return static_cast<TracingController::Options>(ret); |
| 136 } | 136 } |
| 137 | 137 |
| 138 scoped_refptr<DevToolsProtocol::Response> | 138 scoped_refptr<DevToolsProtocol::Response> |
| 139 DevToolsTracingHandler::OnStart( | 139 DevToolsTracingHandler::OnStart( |
| 140 scoped_refptr<DevToolsProtocol::Command> command) { | 140 scoped_refptr<DevToolsProtocol::Command> command) { |
| 141 is_recording_ = true; |
| 141 std::string categories; | 142 std::string categories; |
| 142 base::DictionaryValue* params = command->params(); | 143 base::DictionaryValue* params = command->params(); |
| 143 if (params) | 144 if (params) |
| 144 params->GetString(devtools::Tracing::start::kParamCategories, &categories); | 145 params->GetString(devtools::Tracing::start::kParamCategories, &categories); |
| 145 | 146 |
| 146 TracingController::Options options = TracingController::DEFAULT_OPTIONS; | 147 TracingController::Options options = TracingController::DEFAULT_OPTIONS; |
| 147 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) { | 148 if (params && params->HasKey(devtools::Tracing::start::kParamOptions)) { |
| 148 std::string options_param; | 149 std::string options_param; |
| 149 params->GetString(devtools::Tracing::start::kParamOptions, &options_param); | 150 params->GetString(devtools::Tracing::start::kParamOptions, &options_param); |
| 150 options = TraceOptionsFromString(options_param); | 151 options = TraceOptionsFromString(options_param); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 DevToolsTracingHandler::OnEnd( | 205 DevToolsTracingHandler::OnEnd( |
| 205 scoped_refptr<DevToolsProtocol::Command> command) { | 206 scoped_refptr<DevToolsProtocol::Command> command) { |
| 206 DisableRecording( | 207 DisableRecording( |
| 207 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, | 208 base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, |
| 208 weak_factory_.GetWeakPtr())); | 209 weak_factory_.GetWeakPtr())); |
| 209 return command->SuccessResponse(NULL); | 210 return command->SuccessResponse(NULL); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void DevToolsTracingHandler::DisableRecording( | 213 void DevToolsTracingHandler::DisableRecording( |
| 213 const TracingController::TracingFileResultCallback& callback) { | 214 const TracingController::TracingFileResultCallback& callback) { |
| 215 is_recording_ = false; |
| 214 buffer_usage_poll_timer_.reset(); | 216 buffer_usage_poll_timer_.reset(); |
| 215 TracingController::GetInstance()->DisableRecording(base::FilePath(), | 217 TracingController::GetInstance()->DisableRecording(base::FilePath(), |
| 216 callback); | 218 callback); |
| 217 } | 219 } |
| 218 | 220 |
| 219 void DevToolsTracingHandler::OnClientDetached() { | 221 void DevToolsTracingHandler::OnClientDetached() { |
| 222 if (is_recording_) |
| 220 DisableRecording(); | 223 DisableRecording(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 scoped_refptr<DevToolsProtocol::Response> | 226 scoped_refptr<DevToolsProtocol::Response> |
| 224 DevToolsTracingHandler::OnGetCategories( | 227 DevToolsTracingHandler::OnGetCategories( |
| 225 scoped_refptr<DevToolsProtocol::Command> command) { | 228 scoped_refptr<DevToolsProtocol::Command> command) { |
| 226 TracingController::GetInstance()->GetCategories( | 229 TracingController::GetInstance()->GetCategories( |
| 227 base::Bind(&DevToolsTracingHandler::OnCategoriesReceived, | 230 base::Bind(&DevToolsTracingHandler::OnCategoriesReceived, |
| 228 weak_factory_.GetWeakPtr(), | 231 weak_factory_.GetWeakPtr(), |
| 229 command)); | 232 command)); |
| 230 return command->AsyncResponsePromise(); | 233 return command->AsyncResponsePromise(); |
| 231 } | 234 } |
| 232 | 235 |
| 233 void DevToolsTracingHandler::OnCategoriesReceived( | 236 void DevToolsTracingHandler::OnCategoriesReceived( |
| 234 scoped_refptr<DevToolsProtocol::Command> command, | 237 scoped_refptr<DevToolsProtocol::Command> command, |
| 235 const std::set<std::string>& category_set) { | 238 const std::set<std::string>& category_set) { |
| 236 base::DictionaryValue* response = new base::DictionaryValue; | 239 base::DictionaryValue* response = new base::DictionaryValue; |
| 237 base::ListValue* category_list = new base::ListValue; | 240 base::ListValue* category_list = new base::ListValue; |
| 238 for (std::set<std::string>::const_iterator it = category_set.begin(); | 241 for (std::set<std::string>::const_iterator it = category_set.begin(); |
| 239 it != category_set.end(); ++it) { | 242 it != category_set.end(); ++it) { |
| 240 category_list->AppendString(*it); | 243 category_list->AppendString(*it); |
| 241 } | 244 } |
| 242 | 245 |
| 243 response->Set(devtools::Tracing::getCategories::kResponseCategories, | 246 response->Set(devtools::Tracing::getCategories::kResponseCategories, |
| 244 category_list); | 247 category_list); |
| 245 SendAsyncResponse(command->SuccessResponse(response)); | 248 SendAsyncResponse(command->SuccessResponse(response)); |
| 246 } | 249 } |
| 247 | 250 |
| 248 } // namespace content | 251 } // namespace content |
| OLD | NEW |