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_trace_domain_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 DevToolsTraceDomainHandler::DevToolsTraceDomainHandler() | |
pfeldman
2012/12/14 10:39:33
I think it should be called *TracingHandler
bulach
2012/12/14 16:03:52
Done.
| |
19 : has_completed_(false) { | |
20 } | |
21 | |
22 DevToolsTraceDomainHandler::~DevToolsTraceDomainHandler() { | |
23 } | |
24 | |
25 void DevToolsTraceDomainHandler::OnEndTracingComplete() { | |
26 has_completed_ = true; | |
27 } | |
28 | |
29 void DevToolsTraceDomainHandler::OnTraceDataCollected( | |
30 const scoped_refptr<base::RefCountedString>& trace_fragment) { | |
31 if (!buffer_.empty()) | |
32 buffer_.append(","); | |
33 buffer_.append(trace_fragment->data()); | |
pfeldman
2012/12/14 10:39:33
nit: You might want to store them in a vector of s
bulach
2012/12/14 16:03:52
good point. although it requires more memory when
| |
34 } | |
35 | |
36 base::Value* DevToolsTraceDomainHandler::OnProtocolCommand( | |
37 int connection_id, | |
pfeldman
2012/12/14 10:39:33
So no connection_id, no request_id usage here!
bulach
2012/12/14 16:03:52
Done.
| |
38 int request_id, | |
39 const std::string& method, | |
40 const base::DictionaryValue* params) { | |
41 if (method == "Trace.BeginTracing") | |
pfeldman
2012/12/14 10:39:33
Tracing.start / end
bulach
2012/12/14 16:03:52
Done.
| |
42 return BeginTracing(params); | |
43 else if (method == "Trace.EndTracingAsync") | |
44 return EndTracingAsync(params); | |
45 else if (method == "Trace.HasCompleted") | |
46 return HasCompleted(params); | |
pfeldman
2012/12/14 10:39:33
Why would you need this one? We typically rely upo
bulach
2012/12/14 16:03:52
the trouble is that the stop is asynchronous, so b
pfeldman
2012/12/14 18:35:05
So are you saying that you will poll for hasComple
| |
47 else if (method == "Trace.GetAndResetTrace") | |
pfeldman
2012/12/14 10:39:33
Tracing.getTraceAndReset ?
bulach
2012/12/14 16:03:52
Done.
| |
48 return GetAndResetTrace(params); | |
49 return NULL; | |
50 } | |
51 | |
52 | |
53 base::Value* DevToolsTraceDomainHandler::BeginTracing( | |
54 const base::DictionaryValue* params) { | |
55 std::string categories; | |
56 if (params && params->HasKey("categories")) | |
57 params->GetString("categories", &categories); | |
58 TraceController::GetInstance()->BeginTracing(this, categories); | |
59 | |
60 DictionaryValue* response = new DictionaryValue(); | |
61 response->Set("result", base::Value::CreateBooleanValue(true)); | |
62 return response; | |
pfeldman
2012/12/14 10:39:33
I think you want to return base::Value::CreateBool
bulach
2012/12/14 16:03:52
yeah, I was originally thinking this level could p
| |
63 } | |
64 | |
65 base::Value* DevToolsTraceDomainHandler::EndTracingAsync( | |
66 const base::DictionaryValue* /* params */) { | |
67 TraceController::GetInstance()->EndTracingAsync(this); | |
68 | |
69 DictionaryValue* response = new DictionaryValue(); | |
70 response->Set("result", base::Value::CreateBooleanValue(true)); | |
71 return response; | |
72 } | |
73 | |
74 | |
75 base::Value* DevToolsTraceDomainHandler::HasCompleted( | |
pfeldman
2012/12/14 10:39:33
I don't think you need this.
bulach
2012/12/14 16:03:52
as above, line 67 is async, so we need some mechan
| |
76 const base::DictionaryValue* /* params */) { | |
77 | |
78 DictionaryValue* response = new DictionaryValue(); | |
79 response->Set("result", base::Value::CreateBooleanValue(has_completed_)); | |
80 return response; | |
81 } | |
82 | |
83 base::Value* DevToolsTraceDomainHandler::GetAndResetTrace( | |
84 const base::DictionaryValue* /* params */) { | |
85 std::string ret(buffer_); | |
86 buffer_.clear(); | |
87 has_completed_ = false; | |
88 | |
89 DictionaryValue* response = new DictionaryValue(); | |
90 response->Set("result", base::Value::CreateStringValue(ret)); | |
91 return response; | |
92 } | |
93 | |
94 } // namespace content | |
OLD | NEW |