| 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" | 5 #include "cc/debug/unittest_only_benchmark.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" |
| 8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "cc/debug/unittest_only_benchmark_impl.h" | 11 #include "cc/debug/unittest_only_benchmark_impl.h" |
| 11 | 12 |
| 12 namespace cc { | 13 namespace cc { |
| 13 | 14 |
| 14 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value, | 15 UnittestOnlyBenchmark::UnittestOnlyBenchmark(std::unique_ptr<base::Value> value, |
| 15 const DoneCallback& callback) | 16 const DoneCallback& callback) |
| 16 : MicroBenchmark(callback), | 17 : MicroBenchmark(callback), |
| 17 create_impl_benchmark_(false), | 18 create_impl_benchmark_(false), |
| 18 weak_ptr_factory_(this) { | 19 weak_ptr_factory_(this) { |
| 19 if (!value) | 20 if (!value) |
| 20 return; | 21 return; |
| 21 | 22 |
| 22 base::DictionaryValue* settings = nullptr; | 23 base::DictionaryValue* settings = nullptr; |
| 23 value->GetAsDictionary(&settings); | 24 value->GetAsDictionary(&settings); |
| 24 if (!settings) | 25 if (!settings) |
| 25 return; | 26 return; |
| 26 | 27 |
| 27 if (settings->HasKey("run_benchmark_impl")) | 28 if (settings->HasKey("run_benchmark_impl")) |
| 28 settings->GetBoolean("run_benchmark_impl", &create_impl_benchmark_); | 29 settings->GetBoolean("run_benchmark_impl", &create_impl_benchmark_); |
| 29 } | 30 } |
| 30 | 31 |
| 31 UnittestOnlyBenchmark::~UnittestOnlyBenchmark() { | 32 UnittestOnlyBenchmark::~UnittestOnlyBenchmark() { |
| 32 weak_ptr_factory_.InvalidateWeakPtrs(); | 33 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) { | 36 void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) { |
| 36 NotifyDone(nullptr); | 37 NotifyDone(nullptr); |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool UnittestOnlyBenchmark::ProcessMessage(scoped_ptr<base::Value> value) { | 40 bool UnittestOnlyBenchmark::ProcessMessage(std::unique_ptr<base::Value> value) { |
| 40 base::DictionaryValue* message = nullptr; | 41 base::DictionaryValue* message = nullptr; |
| 41 value->GetAsDictionary(&message); | 42 value->GetAsDictionary(&message); |
| 42 bool can_handle; | 43 bool can_handle; |
| 43 if (message->HasKey("can_handle")) { | 44 if (message->HasKey("can_handle")) { |
| 44 message->GetBoolean("can_handle", &can_handle); | 45 message->GetBoolean("can_handle", &can_handle); |
| 45 if (can_handle) | 46 if (can_handle) |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 return false; | 49 return false; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) { | 52 void UnittestOnlyBenchmark::RecordImplResults( |
| 53 std::unique_ptr<base::Value> results) { |
| 52 NotifyDone(std::move(results)); | 54 NotifyDone(std::move(results)); |
| 53 } | 55 } |
| 54 | 56 |
| 55 scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl( | 57 std::unique_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl( |
| 56 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { | 58 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) { |
| 57 if (!create_impl_benchmark_) | 59 if (!create_impl_benchmark_) |
| 58 return make_scoped_ptr<MicroBenchmarkImpl>(nullptr); | 60 return base::WrapUnique<MicroBenchmarkImpl>(nullptr); |
| 59 | 61 |
| 60 return make_scoped_ptr(new UnittestOnlyBenchmarkImpl( | 62 return base::WrapUnique(new UnittestOnlyBenchmarkImpl( |
| 61 origin_task_runner, nullptr, | 63 origin_task_runner, nullptr, |
| 62 base::Bind(&UnittestOnlyBenchmark::RecordImplResults, | 64 base::Bind(&UnittestOnlyBenchmark::RecordImplResults, |
| 63 weak_ptr_factory_.GetWeakPtr()))); | 65 weak_ptr_factory_.GetWeakPtr()))); |
| 64 } | 66 } |
| 65 | 67 |
| 66 } // namespace cc | 68 } // namespace cc |
| OLD | NEW |