| Index: cc/debug/micro_benchmark_controller.cc
|
| diff --git a/cc/debug/micro_benchmark_controller.cc b/cc/debug/micro_benchmark_controller.cc
|
| index 7d9025c1c42103dc40f9499fc2b467ca8b827460..f6df0f6be19ac20aa997f0b9d2f7aece8086cec2 100644
|
| --- a/cc/debug/micro_benchmark_controller.cc
|
| +++ b/cc/debug/micro_benchmark_controller.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "cc/debug/micro_benchmark_controller.h"
|
|
|
| +#include <limits>
|
| #include <string>
|
|
|
| #include "base/callback.h"
|
| @@ -17,6 +18,8 @@
|
|
|
| namespace cc {
|
|
|
| +int MicroBenchmarkController::next_id_ = 1;
|
| +
|
| namespace {
|
|
|
| scoped_ptr<MicroBenchmark> CreateBenchmark(
|
| @@ -56,16 +59,37 @@ MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
|
|
|
| MicroBenchmarkController::~MicroBenchmarkController() {}
|
|
|
| -bool MicroBenchmarkController::ScheduleRun(
|
| +int MicroBenchmarkController::ScheduleRun(
|
| const std::string& micro_benchmark_name,
|
| scoped_ptr<base::Value> value,
|
| const MicroBenchmark::DoneCallback& callback) {
|
| scoped_ptr<MicroBenchmark> benchmark =
|
| CreateBenchmark(micro_benchmark_name, value.Pass(), callback);
|
| if (benchmark.get()) {
|
| + int id = GetNextIdAndIncrement();
|
| + benchmark->set_id(id);
|
| benchmarks_.push_back(benchmark.Pass());
|
| host_->SetNeedsCommit();
|
| - return true;
|
| + return id;
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int MicroBenchmarkController::GetNextIdAndIncrement() {
|
| + int id = next_id_++;
|
| + // Wrap around to 1 if we overflow (very unlikely).
|
| + if (next_id_ == std::numeric_limits<int>::max())
|
| + next_id_ = 1;
|
| + return id;
|
| +}
|
| +
|
| +bool MicroBenchmarkController::SendMessage(int id,
|
| + scoped_ptr<base::Value> value) {
|
| + for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
|
| + it != benchmarks_.end();
|
| + ++it) {
|
| + if ((*it)->id() == id)
|
| + return (*it)->ProcessMessage(value.Pass());
|
| }
|
| return false;
|
| }
|
|
|