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() { ...@@ -51,7 +51,7 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() {
} }
void PerformanceMonitor::Start() { void PerformanceMonitor::Start() {
BrowserThread::PostBlockingPoolTaskAndReply( util::PostTaskToDatabaseThreadAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&PerformanceMonitor::InitOnBackgroundThread, base::Bind(&PerformanceMonitor::InitOnBackgroundThread,
base::Unretained(this)), base::Unretained(this)),
...@@ -81,6 +81,7 @@ void PerformanceMonitor::FinishInit() { ...@@ -81,6 +81,7 @@ void PerformanceMonitor::FinishInit() {
// to the background thread, and do not rely upon a reply from the background // to the background thread, and do not rely upon a reply from the background
// thread; this is necessary for this notification to be valid. // thread; this is necessary for this notification to be valid.
util::PostTaskToDatabaseThreadAndReply( util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&base::DoNothing), base::Bind(&base::DoNothing),
base::Bind(&PerformanceMonitor::NotifyInitialized, base::Bind(&PerformanceMonitor::NotifyInitialized,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -53,13 +53,15 @@ std::vector<MetricInfo> AggregateMetric( ...@@ -53,13 +53,15 @@ std::vector<MetricInfo> AggregateMetric(
return results; return results;
} }
bool PostTaskToDatabaseThreadAndReply(const base::Closure& request, bool PostTaskToDatabaseThreadAndReply(
const base::Closure& reply) { const tracked_objects::Location& from_here,
const base::Closure& request,
const base::Closure& reply) {
base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
base::SequencedWorkerPool::SequenceToken token = base::SequencedWorkerPool::SequenceToken token =
pool->GetNamedSequenceToken(Database::kDatabaseSequenceToken); pool->GetNamedSequenceToken(Database::kDatabaseSequenceToken);
return pool->GetSequencedTaskRunner(token)->PostTaskAndReply( return pool->GetSequencedTaskRunner(token)->PostTaskAndReply(
FROM_HERE, request, reply); from_here, request, reply);
} }
scoped_ptr<Event> CreateExtensionInstallEvent(const base::Time& time, scoped_ptr<Event> CreateExtensionInstallEvent(const base::Time& time,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/time.h" #include "base/time.h"
#include "base/tracked_objects.h"
#include "chrome/browser/performance_monitor/event.h" #include "chrome/browser/performance_monitor/event.h"
#include "chrome/browser/performance_monitor/metric_info.h" #include "chrome/browser/performance_monitor/metric_info.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
...@@ -28,8 +29,10 @@ std::vector<MetricInfo> AggregateMetric( ...@@ -28,8 +29,10 @@ std::vector<MetricInfo> AggregateMetric(
// Posts |request| to the performance monitor database's sequenced thread. On // Posts |request| to the performance monitor database's sequenced thread. On
// completion |reply| is posted to the thread that called // completion |reply| is posted to the thread that called
// PostTaskToDatabaseThreadAndReply. // PostTaskToDatabaseThreadAndReply.
bool PostTaskToDatabaseThreadAndReply(const base::Closure& request, bool PostTaskToDatabaseThreadAndReply(
const base::Closure& reply); 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 // These are a collection of methods designed to create an event to store the
// pertinent information, given all the fields. Please use these methods to // pertinent information, given all the fields. Please use these methods to
......
...@@ -79,7 +79,13 @@ void DoGetMetric(ListValue* results, ...@@ -79,7 +79,13 @@ void DoGetMetric(ListValue* results,
} // namespace } // 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() {} WebUIHandler::~WebUIHandler() {}
void WebUIHandler::RegisterMessages() { void WebUIHandler::RegisterMessages() {
...@@ -122,9 +128,10 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) { ...@@ -122,9 +128,10 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) {
ListValue* results = new ListValue(); ListValue* results = new ListValue();
util::PostTaskToDatabaseThreadAndReply( util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&DoGetActiveIntervals, results, start, end), base::Bind(&DoGetActiveIntervals, results, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getActiveIntervalsCallback", "PerformanceMonitor.getActiveIntervalsCallback",
base::Owned(results))); base::Owned(results)));
} }
...@@ -140,8 +147,7 @@ void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) { ...@@ -140,8 +147,7 @@ void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) {
EventTypeToString(event_type)); EventTypeToString(event_type));
results.Append(event_type_info); results.Append(event_type_info);
} }
ReturnResults("PerformanceMonitor.getAllEventTypesCallback", &results);
ReturnResults("performance_monitor.getAllEventTypesCallback", &results);
} }
void WebUIHandler::HandleGetEvents(const ListValue* args) { void WebUIHandler::HandleGetEvents(const ListValue* args) {
...@@ -160,11 +166,12 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) { ...@@ -160,11 +166,12 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) {
DictionaryValue* results = new DictionaryValue(); DictionaryValue* results = new DictionaryValue();
ListValue* points_results = new ListValue(); ListValue* points_results = new ListValue();
results->Set("points", points_results); results->Set("points", points_results);
results->SetInteger("type", event_type); results->SetInteger("eventType", event_type);
util::PostTaskToDatabaseThreadAndReply( util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&DoGetEvents, points_results, event_type, start, end), base::Bind(&DoGetEvents, points_results, event_type, start, end),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getEventsCallback", "PerformanceMonitor.getEventsCallback",
base::Owned(results))); base::Owned(results)));
} }
...@@ -185,7 +192,7 @@ void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { ...@@ -185,7 +192,7 @@ void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) {
results.Append(metric_type_info); results.Append(metric_type_info);
} }
ReturnResults("performance_monitor.getAllMetricTypesCallback", &results); ReturnResults("PerformanceMonitor.getAllMetricTypesCallback", &results);
} }
void WebUIHandler::HandleGetMetric(const ListValue* args) { void WebUIHandler::HandleGetMetric(const ListValue* args) {
...@@ -207,14 +214,15 @@ void WebUIHandler::HandleGetMetric(const ListValue* args) { ...@@ -207,14 +214,15 @@ void WebUIHandler::HandleGetMetric(const ListValue* args) {
base::TimeDelta::FromMilliseconds(resolution_in_milliseconds); base::TimeDelta::FromMilliseconds(resolution_in_milliseconds);
DictionaryValue* results = new DictionaryValue(); DictionaryValue* results = new DictionaryValue();
results->SetInteger("type", metric_type); results->SetInteger("metricType", metric_type);
ListValue* points_results = new ListValue(); ListValue* points_results = new ListValue();
results->Set("points", points_results); results->Set("points", points_results);
util::PostTaskToDatabaseThreadAndReply( util::PostTaskToDatabaseThreadAndReply(
FROM_HERE,
base::Bind(&DoGetMetric, points_results, metric_type, base::Bind(&DoGetMetric, points_results, metric_type,
start, end, resolution), start, end, resolution),
base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(),
"performance_monitor.getMetricCallback", "PerformanceMonitor.getMetricCallback",
base::Owned(results))); 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