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/unittest_only_benchmark.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/values.h"
10 #include "cc/debug/unittest_only_benchmark_impl.h"
14 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr
<base::Value
> value
,
15 const DoneCallback
& callback
)
16 : MicroBenchmark(callback
),
17 create_impl_benchmark_(false),
18 weak_ptr_factory_(this) {
22 base::DictionaryValue
* settings
= nullptr;
23 value
->GetAsDictionary(&settings
);
27 if (settings
->HasKey("run_benchmark_impl"))
28 settings
->GetBoolean("run_benchmark_impl", &create_impl_benchmark_
);
31 UnittestOnlyBenchmark::~UnittestOnlyBenchmark() {
32 weak_ptr_factory_
.InvalidateWeakPtrs();
35 void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost
* host
) {
39 bool UnittestOnlyBenchmark::ProcessMessage(scoped_ptr
<base::Value
> value
) {
40 base::DictionaryValue
* message
= nullptr;
41 value
->GetAsDictionary(&message
);
43 if (message
->HasKey("can_handle")) {
44 message
->GetBoolean("can_handle", &can_handle
);
51 void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr
<base::Value
> results
) {
52 NotifyDone(results
.Pass());
55 scoped_ptr
<MicroBenchmarkImpl
> UnittestOnlyBenchmark::CreateBenchmarkImpl(
56 scoped_refptr
<base::SingleThreadTaskRunner
> origin_task_runner
) {
57 if (!create_impl_benchmark_
)
58 return make_scoped_ptr
<MicroBenchmarkImpl
>(nullptr);
60 return make_scoped_ptr(new UnittestOnlyBenchmarkImpl(
61 origin_task_runner
, nullptr,
62 base::Bind(&UnittestOnlyBenchmark::RecordImplResults
,
63 weak_ptr_factory_
.GetWeakPtr())));