unittest_only_benchmark.cc revision f2477e01787aa58f445919b809d89e252beef54f
14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file.
44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "cc/debug/unittest_only_benchmark.h"
64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/bind.h"
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/message_loop/message_loop_proxy.h"
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/values.h"
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "cc/debug/unittest_only_benchmark_impl.h"
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace cc {
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value,
158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                                             const DoneCallback& callback)
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : MicroBenchmark(callback),
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      create_impl_benchmark_(false),
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      weak_ptr_factory_(this) {
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!value)
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  base::DictionaryValue* settings = NULL;
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  value->GetAsDictionary(&settings);
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!settings)
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (settings->HasKey("run_benchmark_impl"))
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    settings->GetBoolean("run_benchmark_impl", &create_impl_benchmark_);
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)UnittestOnlyBenchmark::~UnittestOnlyBenchmark() {
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  weak_ptr_factory_.InvalidateWeakPtrs();
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) {
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  NotifyDone(scoped_ptr<base::Value>());
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) {
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  NotifyDone(results.Pass());
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl(
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    scoped_refptr<base::MessageLoopProxy> origin_loop) {
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!create_impl_benchmark_)
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return make_scoped_ptr<MicroBenchmarkImpl>(NULL);
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return scoped_ptr<MicroBenchmarkImpl>(new UnittestOnlyBenchmarkImpl(
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      origin_loop,
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      NULL,
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      base::Bind(&UnittestOnlyBenchmark::RecordImplResults,
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr())));
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace cc
56