Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: cc/debug/unittest_only_benchmark.cc

Issue 300963004: cc: Add message passing mechanism to micro benchmarking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "cc/debug/unittest_only_benchmark_impl.h" 10 #include "cc/debug/unittest_only_benchmark_impl.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value, 14 UnittestOnlyBenchmark::UnittestOnlyBenchmark(scoped_ptr<base::Value> value,
15 const DoneCallback& callback) 15 const DoneCallback& callback,
16 : MicroBenchmark(callback), 16 int id)
17 : MicroBenchmark(callback, id),
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 = NULL; 23 base::DictionaryValue* settings = NULL;
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(scoped_ptr<base::Value>()); 37 NotifyDone(scoped_ptr<base::Value>());
37 } 38 }
38 39
40 bool UnittestOnlyBenchmark::SendMessage(scoped_ptr<base::Value> value) {
41 base::DictionaryValue* message = NULL;
42 value->GetAsDictionary(&message);
43 bool can_handle;
44 if (message->HasKey("can_handle")) {
45 message->GetBoolean("can_handle", &can_handle);
46 if (can_handle)
47 return true;
48 }
49 return false;
50 }
51
39 void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) { 52 void UnittestOnlyBenchmark::RecordImplResults(scoped_ptr<base::Value> results) {
40 NotifyDone(results.Pass()); 53 NotifyDone(results.Pass());
41 } 54 }
42 55
43 scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl( 56 scoped_ptr<MicroBenchmarkImpl> UnittestOnlyBenchmark::CreateBenchmarkImpl(
44 scoped_refptr<base::MessageLoopProxy> origin_loop) { 57 scoped_refptr<base::MessageLoopProxy> origin_loop) {
45 if (!create_impl_benchmark_) 58 if (!create_impl_benchmark_)
46 return make_scoped_ptr<MicroBenchmarkImpl>(NULL); 59 return make_scoped_ptr<MicroBenchmarkImpl>(NULL);
47 60
48 return scoped_ptr<MicroBenchmarkImpl>(new UnittestOnlyBenchmarkImpl( 61 return scoped_ptr<MicroBenchmarkImpl>(new UnittestOnlyBenchmarkImpl(
49 origin_loop, 62 origin_loop,
50 NULL, 63 NULL,
51 base::Bind(&UnittestOnlyBenchmark::RecordImplResults, 64 base::Bind(&UnittestOnlyBenchmark::RecordImplResults,
52 weak_ptr_factory_.GetWeakPtr()))); 65 weak_ptr_factory_.GetWeakPtr())));
53 } 66 }
54 67
55 } // namespace cc 68 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698