OLD | NEW |
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/unittest_only_benchmark.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" |
5 #include "base/values.h" | 9 #include "base/values.h" |
6 #include "cc/debug/unittest_only_benchmark.h" | 10 #include "cc/debug/unittest_only_benchmark_impl.h" |
7 | 11 |
8 namespace cc { | 12 namespace cc { |
9 | 13 |
10 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value, | 14 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value, |
11 const DoneCallback& callback) | 15 const DoneCallback& callback) |
12 : MicroBenchmark(callback) {} | 16 : MicroBenchmark(callback), |
| 17 create_impl_benchmark_(false), |
| 18 weak_ptr_factory_(this) { |
| 19 if (!value) |
| 20 return; |
13 | 21 |
14 UnittestOnlyBenchmark::~UnittestOnlyBenchmark() {} | 22 base::DictionaryValue* settings = NULL; |
| 23 value->GetAsDictionary(&settings); |
| 24 if (!settings) |
| 25 return; |
| 26 |
| 27 if (settings->HasKey("run_benchmark_impl")) |
| 28 settings->GetBoolean("run_benchmark_impl", &create_impl_benchmark_); |
| 29 } |
| 30 |
| 31 UnittestOnlyBenchmark::~UnittestOnlyBenchmark() { |
| 32 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 33 } |
15 | 34 |
16 void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) { | 35 void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
17 NotifyDone(scoped_ptr<base::Value>()); | 36 NotifyDone(scoped_ptr<base::Value>()); |
18 } | 37 } |
19 | 38 |
| 39 void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) { |
| 40 NotifyDone(results.Pass()); |
| 41 } |
| 42 |
| 43 scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl( |
| 44 scoped_refptr<base::MessageLoopProxy> origin_loop) { |
| 45 if (!create_impl_benchmark_) |
| 46 return make_scoped_ptr<MicroBenchmarkImpl>(NULL); |
| 47 |
| 48 return scoped_ptr<MicroBenchmarkImpl>(new UnittestOnlyBenchmarkImpl( |
| 49 origin_loop, |
| 50 NULL, |
| 51 base::Bind(&UnittestOnlyBenchmark::RecordImplResults, |
| 52 weak_ptr_factory_.GetWeakPtr()))); |
| 53 } |
| 54 |
20 } // namespace cc | 55 } // namespace cc |
OLD | NEW |