Setup a experiment to enable background tracing.
[chromium-blink-merge.git] / cc / test / fake_external_begin_frame_source.cc
blob3c35536cba4f35ddbe5186882662d67bcba3717c
1 // Copyright 2014 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/test/fake_external_begin_frame_source.h"
7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "base/time/time.h"
11 #include "cc/test/begin_frame_args_test.h"
13 namespace cc {
15 FakeExternalBeginFrameSource::FakeExternalBeginFrameSource(double refresh_rate)
16 : milliseconds_per_frame_(1000.0 / refresh_rate),
17 is_ready_(false),
18 weak_ptr_factory_(this) {
19 DetachFromThread();
22 FakeExternalBeginFrameSource::~FakeExternalBeginFrameSource() {
23 DCHECK(CalledOnValidThread());
26 void FakeExternalBeginFrameSource::SetClientReady() {
27 DCHECK(CalledOnValidThread());
28 is_ready_ = true;
31 void FakeExternalBeginFrameSource::OnNeedsBeginFramesChange(
32 bool needs_begin_frames) {
33 DCHECK(CalledOnValidThread());
34 if (needs_begin_frames) {
35 PostTestOnBeginFrame();
39 void FakeExternalBeginFrameSource::TestOnBeginFrame() {
40 DCHECK(CalledOnValidThread());
41 CallOnBeginFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
43 if (NeedsBeginFrames()) {
44 PostTestOnBeginFrame();
48 void FakeExternalBeginFrameSource::PostTestOnBeginFrame() {
49 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
50 FROM_HERE, base::Bind(&FakeExternalBeginFrameSource::TestOnBeginFrame,
51 weak_ptr_factory_.GetWeakPtr()),
52 base::TimeDelta::FromMilliseconds(milliseconds_per_frame_));
55 } // namespace cc