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 "chrome/browser/ui/webui/performance_monitor/web_ui_handler.h" | 5 #include "chrome/browser/ui/webui/performance_monitor/web_ui_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 it != aggregated_metrics.end(); ++it) { | 72 it != aggregated_metrics.end(); ++it) { |
73 DictionaryValue* metric_value = new DictionaryValue(); | 73 DictionaryValue* metric_value = new DictionaryValue(); |
74 metric_value->SetDouble("time", it->time.ToJsTime()); | 74 metric_value->SetDouble("time", it->time.ToJsTime()); |
75 metric_value->SetDouble("value", it->value); | 75 metric_value->SetDouble("value", it->value); |
76 results->Append(metric_value); | 76 results->Append(metric_value); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 WebUIHandler::WebUIHandler() {} | 82 WebUIHandler::WebUIHandler() { |
| 83 // TODO(mtytel): Remove this check when the PerformanceMonitor starts up |
| 84 // before the WebUI. |
| 85 if (!PerformanceMonitor::GetInstance()->database()) |
| 86 PerformanceMonitor::GetInstance()->Start(); |
| 87 } |
| 88 |
83 WebUIHandler::~WebUIHandler() {} | 89 WebUIHandler::~WebUIHandler() {} |
84 | 90 |
85 void WebUIHandler::RegisterMessages() { | 91 void WebUIHandler::RegisterMessages() { |
86 web_ui()->RegisterMessageCallback( | 92 web_ui()->RegisterMessageCallback( |
87 "getActiveIntervals", | 93 "getActiveIntervals", |
88 base::Bind(&WebUIHandler::HandleGetActiveIntervals, | 94 base::Bind(&WebUIHandler::HandleGetActiveIntervals, |
89 base::Unretained(this))); | 95 base::Unretained(this))); |
90 web_ui()->RegisterMessageCallback( | 96 web_ui()->RegisterMessageCallback( |
91 "getAllEventTypes", | 97 "getAllEventTypes", |
92 base::Bind(&WebUIHandler::HandleGetAllEventTypes, | 98 base::Bind(&WebUIHandler::HandleGetAllEventTypes, |
(...skipping 22 matching lines...) Expand all Loading... |
115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
116 CHECK_EQ(2u, args->GetSize()); | 122 CHECK_EQ(2u, args->GetSize()); |
117 double double_time = 0.0; | 123 double double_time = 0.0; |
118 CHECK(args->GetDouble(0, &double_time)); | 124 CHECK(args->GetDouble(0, &double_time)); |
119 base::Time start = base::Time::FromJsTime(double_time); | 125 base::Time start = base::Time::FromJsTime(double_time); |
120 CHECK(args->GetDouble(1, &double_time)); | 126 CHECK(args->GetDouble(1, &double_time)); |
121 base::Time end = base::Time::FromJsTime(double_time); | 127 base::Time end = base::Time::FromJsTime(double_time); |
122 | 128 |
123 ListValue* results = new ListValue(); | 129 ListValue* results = new ListValue(); |
124 util::PostTaskToDatabaseThreadAndReply( | 130 util::PostTaskToDatabaseThreadAndReply( |
| 131 FROM_HERE, |
125 base::Bind(&DoGetActiveIntervals, results, start, end), | 132 base::Bind(&DoGetActiveIntervals, results, start, end), |
126 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), | 133 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), |
127 "performance_monitor.getActiveIntervalsCallback", | 134 "PerformanceMonitor.getActiveIntervalsCallback", |
128 base::Owned(results))); | 135 base::Owned(results))); |
129 } | 136 } |
130 | 137 |
131 void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) { | 138 void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) { |
132 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 139 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
133 CHECK_EQ(0u, args->GetSize()); | 140 CHECK_EQ(0u, args->GetSize()); |
134 ListValue results; | 141 ListValue results; |
135 for (int i = 0; i < EVENT_NUMBER_OF_EVENTS; ++i) { | 142 for (int i = 0; i < EVENT_NUMBER_OF_EVENTS; ++i) { |
136 EventType event_type = static_cast<EventType>(i); | 143 EventType event_type = static_cast<EventType>(i); |
137 DictionaryValue* event_type_info = new DictionaryValue(); | 144 DictionaryValue* event_type_info = new DictionaryValue(); |
138 event_type_info->SetInteger("eventType", event_type); | 145 event_type_info->SetInteger("eventType", event_type); |
139 event_type_info->SetString("shortDescription", | 146 event_type_info->SetString("shortDescription", |
140 EventTypeToString(event_type)); | 147 EventTypeToString(event_type)); |
141 results.Append(event_type_info); | 148 results.Append(event_type_info); |
142 } | 149 } |
143 | 150 ReturnResults("PerformanceMonitor.getAllEventTypesCallback", &results); |
144 ReturnResults("performance_monitor.getAllEventTypesCallback", &results); | |
145 } | 151 } |
146 | 152 |
147 void WebUIHandler::HandleGetEvents(const ListValue* args) { | 153 void WebUIHandler::HandleGetEvents(const ListValue* args) { |
148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
149 CHECK_EQ(3u, args->GetSize()); | 155 CHECK_EQ(3u, args->GetSize()); |
150 double event = 0; | 156 double event = 0; |
151 CHECK(args->GetDouble(0, &event)); | 157 CHECK(args->GetDouble(0, &event)); |
152 EventType event_type = static_cast<EventType>(static_cast<int>(event)); | 158 EventType event_type = static_cast<EventType>(static_cast<int>(event)); |
153 | 159 |
154 double double_time = 0.0; | 160 double double_time = 0.0; |
155 CHECK(args->GetDouble(1, &double_time)); | 161 CHECK(args->GetDouble(1, &double_time)); |
156 base::Time start = base::Time::FromJsTime(double_time); | 162 base::Time start = base::Time::FromJsTime(double_time); |
157 CHECK(args->GetDouble(2, &double_time)); | 163 CHECK(args->GetDouble(2, &double_time)); |
158 base::Time end = base::Time::FromJsTime(double_time); | 164 base::Time end = base::Time::FromJsTime(double_time); |
159 | 165 |
160 DictionaryValue* results = new DictionaryValue(); | 166 DictionaryValue* results = new DictionaryValue(); |
161 ListValue* points_results = new ListValue(); | 167 ListValue* points_results = new ListValue(); |
162 results->Set("points", points_results); | 168 results->Set("points", points_results); |
163 results->SetInteger("type", event_type); | 169 results->SetInteger("eventType", event_type); |
164 util::PostTaskToDatabaseThreadAndReply( | 170 util::PostTaskToDatabaseThreadAndReply( |
| 171 FROM_HERE, |
165 base::Bind(&DoGetEvents, points_results, event_type, start, end), | 172 base::Bind(&DoGetEvents, points_results, event_type, start, end), |
166 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), | 173 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), |
167 "performance_monitor.getEventsCallback", | 174 "PerformanceMonitor.getEventsCallback", |
168 base::Owned(results))); | 175 base::Owned(results))); |
169 } | 176 } |
170 | 177 |
171 void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { | 178 void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { |
172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
173 CHECK_EQ(0u, args->GetSize()); | 180 CHECK_EQ(0u, args->GetSize()); |
174 ListValue results; | 181 ListValue results; |
175 for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) { | 182 for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) { |
176 MetricType metric_type = static_cast<MetricType>(i); | 183 MetricType metric_type = static_cast<MetricType>(i); |
177 const MetricDetails* metric_details = GetMetricDetails(metric_type); | 184 const MetricDetails* metric_details = GetMetricDetails(metric_type); |
178 | 185 |
179 DictionaryValue* metric_type_info = new DictionaryValue(); | 186 DictionaryValue* metric_type_info = new DictionaryValue(); |
180 metric_type_info->SetInteger("metricType", metric_type); | 187 metric_type_info->SetInteger("metricType", metric_type); |
181 metric_type_info->SetString("shortDescription", | 188 metric_type_info->SetString("shortDescription", |
182 metric_details->description); | 189 metric_details->description); |
183 metric_type_info->SetDouble("tickSize", metric_details->tick_size); | 190 metric_type_info->SetDouble("tickSize", metric_details->tick_size); |
184 metric_type_info->SetString("units", metric_details->units); | 191 metric_type_info->SetString("units", metric_details->units); |
185 results.Append(metric_type_info); | 192 results.Append(metric_type_info); |
186 } | 193 } |
187 | 194 |
188 ReturnResults("performance_monitor.getAllMetricTypesCallback", &results); | 195 ReturnResults("PerformanceMonitor.getAllMetricTypesCallback", &results); |
189 } | 196 } |
190 | 197 |
191 void WebUIHandler::HandleGetMetric(const ListValue* args) { | 198 void WebUIHandler::HandleGetMetric(const ListValue* args) { |
192 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 199 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
193 CHECK_EQ(4u, args->GetSize()); | 200 CHECK_EQ(4u, args->GetSize()); |
194 double metric = 0; | 201 double metric = 0; |
195 CHECK(args->GetDouble(0, &metric)); | 202 CHECK(args->GetDouble(0, &metric)); |
196 MetricType metric_type = static_cast<MetricType>(static_cast<int>(metric)); | 203 MetricType metric_type = static_cast<MetricType>(static_cast<int>(metric)); |
197 | 204 |
198 double double_time = 0.0; | 205 double double_time = 0.0; |
199 CHECK(args->GetDouble(1, &double_time)); | 206 CHECK(args->GetDouble(1, &double_time)); |
200 base::Time start = base::Time::FromJsTime(double_time); | 207 base::Time start = base::Time::FromJsTime(double_time); |
201 CHECK(args->GetDouble(2, &double_time)); | 208 CHECK(args->GetDouble(2, &double_time)); |
202 base::Time end = base::Time::FromJsTime(double_time); | 209 base::Time end = base::Time::FromJsTime(double_time); |
203 | 210 |
204 double resolution_in_milliseconds = 0; | 211 double resolution_in_milliseconds = 0; |
205 CHECK(args->GetDouble(3, &resolution_in_milliseconds)); | 212 CHECK(args->GetDouble(3, &resolution_in_milliseconds)); |
206 base::TimeDelta resolution = | 213 base::TimeDelta resolution = |
207 base::TimeDelta::FromMilliseconds(resolution_in_milliseconds); | 214 base::TimeDelta::FromMilliseconds(resolution_in_milliseconds); |
208 | 215 |
209 DictionaryValue* results = new DictionaryValue(); | 216 DictionaryValue* results = new DictionaryValue(); |
210 results->SetInteger("type", metric_type); | 217 results->SetInteger("metricType", metric_type); |
211 ListValue* points_results = new ListValue(); | 218 ListValue* points_results = new ListValue(); |
212 results->Set("points", points_results); | 219 results->Set("points", points_results); |
213 util::PostTaskToDatabaseThreadAndReply( | 220 util::PostTaskToDatabaseThreadAndReply( |
| 221 FROM_HERE, |
214 base::Bind(&DoGetMetric, points_results, metric_type, | 222 base::Bind(&DoGetMetric, points_results, metric_type, |
215 start, end, resolution), | 223 start, end, resolution), |
216 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), | 224 base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), |
217 "performance_monitor.getMetricCallback", | 225 "PerformanceMonitor.getMetricCallback", |
218 base::Owned(results))); | 226 base::Owned(results))); |
219 } | 227 } |
220 | 228 |
221 } // namespace performance_monitor | 229 } // namespace performance_monitor |
OLD | NEW |