Commit 50caa012 authored by mtytel@chromium.org's avatar mtytel@chromium.org

CPM: API changes for API/UI integration.

BUG=130212
TEST=


Review URL: https://chromiumcodereview.appspot.com/10797056

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148407 0039d316-1c4b-4281-b951-d872f2087c98
parent 1aa497c7
......@@ -51,7 +51,7 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() {
}
void PerformanceMonitor::Start() {
BrowserThread::PostBlockingPoolTaskAndReply(
util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&PerformanceMonitor::InitOnBackgroundThread,
base::Unretained(this)),
......@@ -81,6 +81,7 @@ void PerformanceMonitor::FinishInit() {
// to the background thread, and do not rely upon a reply from the background
// thread; this is necessary for this notification to be valid.
util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&base::DoNothing),
base::Bind(&PerformanceMonitor::NotifyInitialized,
base::Unretained(this)));
......
......@@ -53,13 +53,15 @@ std::vector<MetricInfo> AggregateMetric(
return results;
}
bool PostTaskToDatabaseThreadAndReply(const base::Closure& request,
bool PostTaskToDatabaseThreadAndReply(
const tracked_objects::Location& from_here,
const base::Closure& request,
const base::Closure& reply) {
base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
base::SequencedWorkerPool::SequenceToken token =
pool->GetNamedSequenceToken(Database::kDatabaseSequenceToken);
return pool->GetSequencedTaskRunner(token)->PostTaskAndReply(
FROM_HERE, request, reply);
from_here, request, reply);
}
scoped_ptr<Event> CreateExtensionInstallEvent(const base::Time& time,
......
......@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "base/time.h"
#include "base/tracked_objects.h"
#include "chrome/browser/performance_monitor/event.h"
#include "chrome/browser/performance_monitor/metric_info.h"
#include "chrome/common/extensions/extension_constants.h"
......@@ -28,7 +29,9 @@ std::vector<MetricInfo> AggregateMetric(
// Posts |request| to the performance monitor database's sequenced thread. On
// completion |reply| is posted to the thread that called
// PostTaskToDatabaseThreadAndReply.
bool PostTaskToDatabaseThreadAndReply(const base::Closure& request,
bool PostTaskToDatabaseThreadAndReply(
const tracked_objects::Location& from_here,
const base::Closure& request,
const base::Closure& reply);
// These are a collection of methods designed to create an event to store the
......
......@@ -79,7 +79,13 @@ 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();
}
WebUIHandler::~WebUIHandler() {}
void WebUIHandler::RegisterMessages() {
......@@ -122,9 +128,10 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) {
ListValue* results = new ListValue();
util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&DoGetActiveIntervals, results, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getActiveIntervalsCallback",
"PerformanceMonitor.getActiveIntervalsCallback",
base::Owned(results)));
}
......@@ -140,8 +147,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) {
......@@ -160,11 +166,12 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) {
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(
FROM_HERE,
base::Bind(&DoGetEvents, points_results, event_type, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getEventsCallback",
"PerformanceMonitor.getEventsCallback",
base::Owned(results)));
}
......@@ -185,7 +192,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) {
......@@ -207,14 +214,15 @@ 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(
FROM_HERE,
base::Bind(&DoGetMetric, points_results, metric_type,
start, end, resolution),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getMetricCallback",
"PerformanceMonitor.getMetricCallback",
base::Owned(results)));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment