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/tracing/tracing_ui.h" | 5 #include "content/browser/tracing/tracing_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "content/browser/tracing/tracing_controller_impl.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/tracing_controller.h" | |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
23 #include "content/public/browser/web_ui_data_source.h" | 23 #include "content/public/browser/web_ui_data_source.h" |
24 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
25 #include "grit/tracing_resources.h" | 25 #include "grit/tracing_resources.h" |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 namespace { | 28 namespace { |
29 | 29 |
30 void OnGotCategories(const WebUIDataSource::GotDataCallback& callback, | 30 void OnGotCategories(const WebUIDataSource::GotDataCallback& callback, |
(...skipping 13 matching lines...) Expand all Loading... |
44 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); | 44 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback); |
45 | 45 |
46 bool OnBeginRecording(const std::string& data64, | 46 bool OnBeginRecording(const std::string& data64, |
47 const WebUIDataSource::GotDataCallback& callback) { | 47 const WebUIDataSource::GotDataCallback& callback) { |
48 std::string data; | 48 std::string data; |
49 if (!base::Base64Decode(data64, &data)) { | 49 if (!base::Base64Decode(data64, &data)) { |
50 LOG(ERROR) << "Options were not base64 encoded."; | 50 LOG(ERROR) << "Options were not base64 encoded."; |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 scoped_ptr<base::Value> optionsRaw(base::JSONReader::Read(data)); | 54 scoped_ptr<base::Value> paramsRaw(base::JSONReader::Read(data)); |
55 if (!optionsRaw) { | 55 if (!paramsRaw) { |
56 LOG(ERROR) << "Options were not valid JSON"; | 56 LOG(ERROR) << "Params were not valid JSON"; |
57 return false; | 57 return false; |
58 } | 58 } |
59 base::DictionaryValue* options; | 59 base::DictionaryValue* params; |
60 if (!optionsRaw->GetAsDictionary(&options)) { | 60 if (!paramsRaw->GetAsDictionary(¶ms)) { |
61 LOG(ERROR) << "Options must be dict"; | 61 LOG(ERROR) << "Params must be dict"; |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
65 std::string category_filter_string; | 65 std::string category_filter; |
66 bool use_system_tracing; | 66 TracingController::Options tracing_options; |
67 bool use_continuous_tracing; | 67 if (!TracingControllerImpl::ParseTracingParams(params, &category_filter, |
68 bool use_sampling; | 68 &tracing_options)) { |
69 | |
70 bool options_ok = true; | |
71 options_ok &= options->GetString("categoryFilter", &category_filter_string); | |
72 options_ok &= options->GetBoolean("useSystemTracing", &use_system_tracing); | |
73 options_ok &= options->GetBoolean("useContinuousTracing", | |
74 &use_continuous_tracing); | |
75 options_ok &= options->GetBoolean("useSampling", &use_sampling); | |
76 if (!options_ok) { | |
77 LOG(ERROR) << "Malformed options"; | |
78 return false; | 69 return false; |
79 } | 70 } |
80 | 71 |
81 int tracing_options = 0; | |
82 if (use_system_tracing) | |
83 tracing_options |= TracingController::ENABLE_SYSTRACE; | |
84 if (use_sampling) | |
85 tracing_options |= TracingController::ENABLE_SAMPLING; | |
86 if (use_continuous_tracing) | |
87 tracing_options |= TracingController::RECORD_CONTINUOUSLY; | |
88 | |
89 base::debug::CategoryFilter category_filter(category_filter_string); | |
90 return TracingController::GetInstance()->EnableRecording( | 72 return TracingController::GetInstance()->EnableRecording( |
91 category_filter, | 73 category_filter, tracing_options, |
92 static_cast<TracingController::Options>(tracing_options), | |
93 base::Bind(OnRecordingEnabledAck, callback)); | 74 base::Bind(OnRecordingEnabledAck, callback)); |
94 } | 75 } |
95 | 76 |
96 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { | 77 void OnRecordingEnabledAck(const WebUIDataSource::GotDataCallback& callback) { |
97 base::RefCountedString* res = new base::RefCountedString(); | 78 base::RefCountedString* res = new base::RefCountedString(); |
98 callback.Run(res); | 79 callback.Run(res); |
99 } | 80 } |
100 | 81 |
101 void OnTraceBufferPercentFullResult( | 82 void OnTraceBufferPercentFullResult( |
102 const WebUIDataSource::GotDataCallback& callback, float result) { | 83 const WebUIDataSource::GotDataCallback& callback, float result) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 143 |
163 WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost); | 144 WebUIDataSource* source = WebUIDataSource::Create(kChromeUITracingHost); |
164 source->SetJsonPath("strings.js"); | 145 source->SetJsonPath("strings.js"); |
165 source->SetDefaultResource(IDR_TRACING_HTML); | 146 source->SetDefaultResource(IDR_TRACING_HTML); |
166 source->AddResourcePath("tracing.js", IDR_TRACING_JS); | 147 source->AddResourcePath("tracing.js", IDR_TRACING_JS); |
167 source->SetRequestFilter(base::Bind(OnBeginRequest)); | 148 source->SetRequestFilter(base::Bind(OnBeginRequest)); |
168 WebUIDataSource::Add(browser_context, source); | 149 WebUIDataSource::Add(browser_context, source); |
169 } | 150 } |
170 | 151 |
171 } // namespace content | 152 } // namespace content |
OLD | NEW |