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

Side by Side Diff: cc/debug/micro_benchmark_controller.cc

Issue 1437413002: cc: Remove ScopedPtrVector and cc::remove_if. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « cc/debug/micro_benchmark_controller.h ('k') | cc/debug/micro_benchmark_controller_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/debug/micro_benchmark_controller.h" 5 #include "cc/debug/micro_benchmark_controller.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 19 matching lines...) Expand all
30 return make_scoped_ptr(new InvalidationBenchmark(value.Pass(), callback)); 30 return make_scoped_ptr(new InvalidationBenchmark(value.Pass(), callback));
31 } else if (name == "rasterize_and_record_benchmark") { 31 } else if (name == "rasterize_and_record_benchmark") {
32 return make_scoped_ptr( 32 return make_scoped_ptr(
33 new RasterizeAndRecordBenchmark(value.Pass(), callback)); 33 new RasterizeAndRecordBenchmark(value.Pass(), callback));
34 } else if (name == "unittest_only_benchmark") { 34 } else if (name == "unittest_only_benchmark") {
35 return make_scoped_ptr(new UnittestOnlyBenchmark(value.Pass(), callback)); 35 return make_scoped_ptr(new UnittestOnlyBenchmark(value.Pass(), callback));
36 } 36 }
37 return nullptr; 37 return nullptr;
38 } 38 }
39 39
40 class IsDonePredicate {
41 public:
42 typedef const MicroBenchmark* argument_type;
43 typedef bool result_type;
44
45 result_type operator()(argument_type benchmark) const {
46 return benchmark->IsDone();
47 }
48 };
49
50 } // namespace 40 } // namespace
51 41
52 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host) 42 MicroBenchmarkController::MicroBenchmarkController(LayerTreeHost* host)
53 : host_(host), 43 : host_(host),
54 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet() 44 main_controller_task_runner_(base::ThreadTaskRunnerHandle::IsSet()
55 ? base::ThreadTaskRunnerHandle::Get() 45 ? base::ThreadTaskRunnerHandle::Get()
56 : nullptr) { 46 : nullptr) {
57 DCHECK(host_); 47 DCHECK(host_);
58 } 48 }
59 49
(...skipping 18 matching lines...) Expand all
78 int MicroBenchmarkController::GetNextIdAndIncrement() { 68 int MicroBenchmarkController::GetNextIdAndIncrement() {
79 int id = next_id_++; 69 int id = next_id_++;
80 // Wrap around to 1 if we overflow (very unlikely). 70 // Wrap around to 1 if we overflow (very unlikely).
81 if (next_id_ == std::numeric_limits<int>::max()) 71 if (next_id_ == std::numeric_limits<int>::max())
82 next_id_ = 1; 72 next_id_ = 1;
83 return id; 73 return id;
84 } 74 }
85 75
86 bool MicroBenchmarkController::SendMessage(int id, 76 bool MicroBenchmarkController::SendMessage(int id,
87 scoped_ptr<base::Value> value) { 77 scoped_ptr<base::Value> value) {
88 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 78 auto it = std::find_if(benchmarks_.begin(), benchmarks_.end(),
89 it != benchmarks_.end(); 79 [id](const scoped_ptr<MicroBenchmark>& benchmark) {
90 ++it) { 80 return benchmark->id() == id;
91 if ((*it)->id() == id) 81 });
92 return (*it)->ProcessMessage(value.Pass()); 82 if (it == benchmarks_.end())
93 } 83 return false;
94 return false; 84 return (*it)->ProcessMessage(std::move(value));
95 } 85 }
96 86
97 void MicroBenchmarkController::ScheduleImplBenchmarks( 87 void MicroBenchmarkController::ScheduleImplBenchmarks(
98 LayerTreeHostImpl* host_impl) { 88 LayerTreeHostImpl* host_impl) {
99 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 89 for (const auto& benchmark : benchmarks_) {
100 it != benchmarks_.end();
101 ++it) {
102 scoped_ptr<MicroBenchmarkImpl> benchmark_impl; 90 scoped_ptr<MicroBenchmarkImpl> benchmark_impl;
103 if (!(*it)->ProcessedForBenchmarkImpl()) { 91 if (!benchmark->ProcessedForBenchmarkImpl()) {
104 benchmark_impl = (*it)->GetBenchmarkImpl(main_controller_task_runner_); 92 benchmark_impl =
93 benchmark->GetBenchmarkImpl(main_controller_task_runner_);
105 } 94 }
106 95
107 if (benchmark_impl.get()) 96 if (benchmark_impl.get())
108 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass()); 97 host_impl->ScheduleMicroBenchmark(benchmark_impl.Pass());
109 } 98 }
110 } 99 }
111 100
112 void MicroBenchmarkController::DidUpdateLayers() { 101 void MicroBenchmarkController::DidUpdateLayers() {
113 for (ScopedPtrVector<MicroBenchmark>::iterator it = benchmarks_.begin(); 102 for (const auto& benchmark : benchmarks_) {
114 it != benchmarks_.end(); 103 if (!benchmark->IsDone())
115 ++it) { 104 benchmark->DidUpdateLayers(host_);
116 if (!(*it)->IsDone())
117 (*it)->DidUpdateLayers(host_);
118 } 105 }
119 106
120 CleanUpFinishedBenchmarks(); 107 CleanUpFinishedBenchmarks();
121 } 108 }
122 109
123 void MicroBenchmarkController::CleanUpFinishedBenchmarks() { 110 void MicroBenchmarkController::CleanUpFinishedBenchmarks() {
124 benchmarks_.erase( 111 benchmarks_.erase(
125 benchmarks_.partition(std::not1(IsDonePredicate())), 112 std::remove_if(benchmarks_.begin(), benchmarks_.end(),
113 [](const scoped_ptr<MicroBenchmark>& benchmark) {
114 return benchmark->IsDone();
115 }),
126 benchmarks_.end()); 116 benchmarks_.end());
127 } 117 }
128 118
129 } // namespace cc 119 } // namespace cc
OLDNEW
« no previous file with comments | « cc/debug/micro_benchmark_controller.h ('k') | cc/debug/micro_benchmark_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698