| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/debugger/devtools_tracing_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/values.h" | |
| 11 #include "content/browser/debugger/devtools_http_handler_impl.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/browser/trace_controller.h" | |
| 14 #include "content/public/browser/trace_subscriber.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 DevToolsTracingHandler::DevToolsTracingHandler() | |
| 19 : has_completed_(false), | |
| 20 buffer_data_size_(0) { | |
| 21 } | |
| 22 | |
| 23 DevToolsTracingHandler::~DevToolsTracingHandler() { | |
| 24 } | |
| 25 | |
| 26 std::string DevToolsTracingHandler::Domain() { | |
| 27 return "Tracing"; | |
| 28 } | |
| 29 | |
| 30 void DevToolsTracingHandler::OnEndTracingComplete() { | |
| 31 has_completed_ = true; | |
| 32 } | |
| 33 | |
| 34 void DevToolsTracingHandler::OnTraceDataCollected( | |
| 35 const scoped_refptr<base::RefCountedString>& trace_fragment) { | |
| 36 buffer_.push_back(trace_fragment->data()); | |
| 37 buffer_data_size_ += trace_fragment->data().size(); | |
| 38 } | |
| 39 | |
| 40 base::Value* DevToolsTracingHandler::OnProtocolCommand( | |
| 41 const std::string& method, | |
| 42 const base::DictionaryValue* params, | |
| 43 base::Value** error_out) { | |
| 44 if (method == "Tracing.start") | |
| 45 return Start(params); | |
| 46 else if (method == "Tracing.end") | |
| 47 return End(params); | |
| 48 else if (method == "Tracing.hasCompleted") | |
| 49 return HasCompleted(params); | |
| 50 else if (method == "Tracing.getTraceAndReset") | |
| 51 return GetTraceAndReset(params); | |
| 52 | |
| 53 base::DictionaryValue* error_object = new base::DictionaryValue(); | |
| 54 error_object->SetInteger("code", -1); | |
| 55 error_object->SetString("message", "Invalid method"); | |
| 56 | |
| 57 *error_out = error_object; | |
| 58 | |
| 59 return NULL; | |
| 60 } | |
| 61 | |
| 62 base::Value* DevToolsTracingHandler::Start( | |
| 63 const base::DictionaryValue* params) { | |
| 64 std::string categories; | |
| 65 if (params && params->HasKey("categories")) | |
| 66 params->GetString("categories", &categories); | |
| 67 TraceController::GetInstance()->BeginTracing(this, categories); | |
| 68 | |
| 69 return base::Value::CreateBooleanValue(true); | |
| 70 } | |
| 71 | |
| 72 base::Value* DevToolsTracingHandler::End( | |
| 73 const base::DictionaryValue* /* params */) { | |
| 74 TraceController::GetInstance()->EndTracingAsync(this); | |
| 75 | |
| 76 return base::Value::CreateBooleanValue(true); | |
| 77 } | |
| 78 | |
| 79 | |
| 80 base::Value* DevToolsTracingHandler::HasCompleted( | |
| 81 const base::DictionaryValue* /* params */) { | |
| 82 | |
| 83 return base::Value::CreateBooleanValue(has_completed_); | |
| 84 } | |
| 85 | |
| 86 base::Value* DevToolsTracingHandler::GetTraceAndReset( | |
| 87 const base::DictionaryValue* /* params */) { | |
| 88 std::string ret; | |
| 89 ret.reserve(buffer_data_size_); | |
| 90 for (std::vector<std::string>::const_iterator i = buffer_.begin(); | |
| 91 i != buffer_.end(); ++i) { | |
| 92 if (!ret.empty()) | |
| 93 ret.append(","); | |
| 94 ret.append(*i); | |
| 95 } | |
| 96 buffer_.clear(); | |
| 97 has_completed_ = false; | |
| 98 buffer_data_size_ = 0; | |
| 99 | |
| 100 return base::Value::CreateStringValue(ret); | |
| 101 } | |
| 102 | |
| 103 } // namespace content | |
| OLD | NEW |