summaryrefslogtreecommitdiffstats
path: root/chromium/cc/debug/unittest_only_benchmark.cc
blob: 0f0694ad9df3e25f01b4bb7e880eebc69b1968d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/debug/unittest_only_benchmark.h"

#include "base/bind.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/values.h"
#include "cc/debug/unittest_only_benchmark_impl.h"

namespace cc {

UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value,
                                             const DoneCallback& callback)
    : MicroBenchmark(callback),
      create_impl_benchmark_(false),
      weak_ptr_factory_(this) {
  if (!value)
    return;

  base::DictionaryValue* settings = NULL;
  value->GetAsDictionary(&settings);
  if (!settings)
    return;

  if (settings->HasKey("run_benchmark_impl"))
    settings->GetBoolean("run_benchmark_impl", &create_impl_benchmark_);
}

UnittestOnlyBenchmark::~UnittestOnlyBenchmark() {
  weak_ptr_factory_.InvalidateWeakPtrs();
}

void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* host) {
  NotifyDone(scoped_ptr<base::Value>());
}

bool UnittestOnlyBenchmark::ProcessMessage(scoped_ptr<base::Value> value) {
  base::DictionaryValue* message = NULL;
  value->GetAsDictionary(&message);
  bool can_handle;
  if (message->HasKey("can_handle")) {
    message->GetBoolean("can_handle", &can_handle);
    if (can_handle)
      return true;
  }
  return false;
}

void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) {
  NotifyDone(results.Pass());
}

scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl(
    scoped_refptr<base::MessageLoopProxy> origin_loop) {
  if (!create_impl_benchmark_)
    return make_scoped_ptr<MicroBenchmarkImpl>(NULL);

  return scoped_ptr<MicroBenchmarkImpl>(new UnittestOnlyBenchmarkImpl(
      origin_loop,
      NULL,
      base::Bind(&UnittestOnlyBenchmark::RecordImplResults,
                 weak_ptr_factory_.GetWeakPtr())));
}

}  // namespace cc