Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3262)

Unified Diff: chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc

Issue 10797056: CPM: API changes for API/UI integration. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Commented and renamed UTCToLocalJsTime and LocalJsTimeToUTC. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
diff --git a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
index 5029f87bd6a5bc5bee64f7b774828f3b148501e1..0f9f6ac04d1b168185d9e543972821a842a9efa7 100644
--- a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
+++ b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc
@@ -20,6 +20,22 @@
namespace performance_monitor {
namespace {
+// Converts a base::Time object in UTC to a double representing local time from
+// javascript epoch.
+double UTCToLocalJsTime(const base::Time& utc_time) {
+ base::Time::Exploded exploded;
+ utc_time.LocalExplode(&exploded);
+ return base::Time::FromUTCExploded(exploded).ToJsTime();
Evan Stade 2012/07/23 23:09:50 piping LocalExplode to FromUTCExploded strikes me
Matt Tytel 2012/07/24 20:44:16 Yea, I talked to Brettw about this. We decided jus
+}
+
+// Converts a double representing local time from javascript epoch to a
+// base::Time object in UTC.
+base::Time LocalJsTimeToUTC(double local_time) {
+ base::Time::Exploded exploded;
+ base::Time::FromJsTime(local_time).UTCExplode(&exploded);
+ return base::Time::FromLocalExploded(exploded);
+}
+
// Queries the performance monitor database for active intervals between
// |start| and |end| times and appends the results to |results|.
void DoGetActiveIntervals(ListValue* results,
@@ -30,8 +46,8 @@ void DoGetActiveIntervals(ListValue* results,
for (std::vector<TimeRange>::iterator it = intervals.begin();
it != intervals.end(); ++it) {
DictionaryValue* interval_value = new DictionaryValue();
- interval_value->SetDouble("start", it->start.ToJsTime());
- interval_value->SetDouble("end", it->end.ToJsTime());
+ interval_value->SetDouble("start", UTCToLocalJsTime(it->start));
+ interval_value->SetDouble("end", UTCToLocalJsTime(it->end));
results->Append(interval_value);
}
}
@@ -71,7 +87,7 @@ void DoGetMetric(ListValue* results,
for (Database::MetricInfoVector::iterator it = aggregated_metrics.begin();
it != aggregated_metrics.end(); ++it) {
DictionaryValue* metric_value = new DictionaryValue();
- metric_value->SetDouble("time", it->time.ToJsTime());
+ metric_value->SetDouble("time", UTCToLocalJsTime(it->time));
metric_value->SetDouble("value", it->value);
results->Append(metric_value);
}
@@ -79,7 +95,12 @@ void DoGetMetric(ListValue* results,
} // namespace
-WebUIHandler::WebUIHandler() {}
+WebUIHandler::WebUIHandler() {
+ // TODO(mtytel): Remove this check when the PerformanceMonitor starts up
+ // before the WebUI.
+ if (!PerformanceMonitor::GetInstance()->database())
+ PerformanceMonitor::GetInstance()->Start();
+}
Evan Stade 2012/07/23 23:09:50 \n
Matt Tytel 2012/07/24 20:44:16 Done.
WebUIHandler::~WebUIHandler() {}
void WebUIHandler::RegisterMessages() {
@@ -116,15 +137,15 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) {
CHECK_EQ(2u, args->GetSize());
double double_time = 0.0;
CHECK(args->GetDouble(0, &double_time));
- base::Time start = base::Time::FromJsTime(double_time);
+ base::Time start = LocalJsTimeToUTC(double_time);
CHECK(args->GetDouble(1, &double_time));
- base::Time end = base::Time::FromJsTime(double_time);
+ base::Time end = LocalJsTimeToUTC(double_time);
ListValue* results = new ListValue();
util::PostTaskToDatabaseThreadAndReply(
base::Bind(&DoGetActiveIntervals, results, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
- "performance_monitor.getActiveIntervalsCallback",
+ "PerformanceMonitor.getActiveIntervalsCallback",
base::Owned(results)));
}
@@ -140,8 +161,7 @@ void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) {
EventTypeToString(event_type));
results.Append(event_type_info);
}
-
- ReturnResults("performance_monitor.getAllEventTypesCallback", &results);
+ ReturnResults("PerformanceMonitor.getAllEventTypesCallback", &results);
}
void WebUIHandler::HandleGetEvents(const ListValue* args) {
@@ -153,18 +173,18 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) {
double double_time = 0.0;
CHECK(args->GetDouble(1, &double_time));
- base::Time start = base::Time::FromJsTime(double_time);
+ base::Time start = LocalJsTimeToUTC(double_time);
CHECK(args->GetDouble(2, &double_time));
- base::Time end = base::Time::FromJsTime(double_time);
+ base::Time end = LocalJsTimeToUTC(double_time);
DictionaryValue* results = new DictionaryValue();
ListValue* points_results = new ListValue();
results->Set("points", points_results);
- results->SetInteger("type", event_type);
+ results->SetInteger("eventType", event_type);
util::PostTaskToDatabaseThreadAndReply(
base::Bind(&DoGetEvents, points_results, event_type, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
- "performance_monitor.getEventsCallback",
+ "PerformanceMonitor.getEventsCallback",
base::Owned(results)));
}
@@ -181,7 +201,7 @@ void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) {
results.Append(metric_type_info);
}
- ReturnResults("performance_monitor.getAllMetricTypesCallback", &results);
+ ReturnResults("PerformanceMonitor.getAllMetricTypesCallback", &results);
}
void WebUIHandler::HandleGetMetric(const ListValue* args) {
@@ -193,9 +213,9 @@ void WebUIHandler::HandleGetMetric(const ListValue* args) {
double double_time = 0.0;
CHECK(args->GetDouble(1, &double_time));
- base::Time start = base::Time::FromJsTime(double_time);
+ base::Time start = LocalJsTimeToUTC(double_time);
CHECK(args->GetDouble(2, &double_time));
- base::Time end = base::Time::FromJsTime(double_time);
+ base::Time end = LocalJsTimeToUTC(double_time);
double resolution_in_milliseconds = 0;
CHECK(args->GetDouble(3, &resolution_in_milliseconds));
@@ -203,14 +223,14 @@ void WebUIHandler::HandleGetMetric(const ListValue* args) {
base::TimeDelta::FromMilliseconds(resolution_in_milliseconds);
DictionaryValue* results = new DictionaryValue();
- results->SetInteger("type", metric_type);
+ results->SetInteger("metricType", metric_type);
ListValue* points_results = new ListValue();
results->Set("points", points_results);
util::PostTaskToDatabaseThreadAndReply(
base::Bind(&DoGetMetric, points_results, metric_type,
start, end, resolution),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
- "performance_monitor.getMetricCallback",
+ "PerformanceMonitor.getMetricCallback",
base::Owned(results)));
}

Powered by Google App Engine
This is Rietveld 408576698