chrome.windows.create should return new window id in Guest mode
[chromium-blink-merge.git] / cc / debug / micro_benchmark_controller.cc
blob6e34e481698a0b0e7055848f7032153e5a2a932f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/debug/micro_benchmark_controller.h"
7 #include <string>
9 #include "base/callback.h"
10 #include "base/values.h"
11 #include "cc/debug/picture_record_benchmark.h"
12 #include "cc/debug/unittest_only_benchmark.h"
13 #include "cc/trees/layer_tree_host.h"
15 namespace cc {
17 namespace {
19 scoped_ptr<MicroBenchmark> CreateBenchmark(
20 const std::string& name,
21 scoped_ptr<base::Value> value,
22 const MicroBenchmark::DoneCallback& callback) {
23 if (name == "picture_record_benchmark") {
24 return scoped_ptr<MicroBenchmark>(
25 new PictureRecordBenchmark(value.Pass(), callback));
26 } else if (name == "unittest_only_benchmark") {
27 return scoped_ptr<MicroBenchmark>(
28 new UnittestOnlyBenchmark(value.Pass(), callback));
30 return scoped_ptr<MicroBenchmark>();
33 class IsDonePredicate {
34 public:
35 typedef const MicroBenchmark* argument_type;
36 typedef bool result_type;
38 result_type operator()(argument_type benchmark) const {
39 return benchmark->IsDone();
43 } // namespace
45 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
46 : host_(host) {
47 DCHECK(host_);
50 MicroBenchmarkController::~MicroBenchmarkController() {}
52 bool MicroBenchmarkController::ScheduleRun(
53 const std::string& micro_benchmark_name,
54 scoped_ptr<base::Value> value,
55 const MicroBenchmark::DoneCallback& callback) {
56 scoped_ptr<MicroBenchmark> benchmark =
57 CreateBenchmark(micro_benchmark_name, value.Pass(), callback);
58 if (benchmark.get()) {
59 benchmarks_.push_back(benchmark.Pass());
60 host_->SetNeedsCommit();
61 return true;
63 return false;
66 void MicroBenchmarkController::DidUpdateLayers() {
67 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin();
68 it != benchmarks_.end();
69 ++it) {
70 DCHECK(!(*it)->IsDone());
71 (*it)->DidUpdateLayers(host_);
74 CleanUpFinishedBenchmarks();
77 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
78 benchmarks_.erase(
79 benchmarks_.partition(std::not1(IsDonePredicate())),
80 benchmarks_.end());
83 } // namespace cc