Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / media / cast / sender / fake_video_encode_accelerator_factory.cc
blob24eba4b07eea986e068ab2c458c8a43e7eb556cc
1 // Copyright 2015 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 "media/cast/sender/fake_video_encode_accelerator_factory.h"
7 #include "base/callback_helpers.h"
9 namespace media {
10 namespace cast {
12 FakeVideoEncodeAcceleratorFactory::FakeVideoEncodeAcceleratorFactory(
13 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
14 : task_runner_(task_runner),
15 will_init_succeed_(true),
16 auto_respond_(false),
17 vea_response_count_(0),
18 shm_response_count_(0),
19 last_response_vea_(nullptr),
20 last_response_shm_(nullptr) {}
22 FakeVideoEncodeAcceleratorFactory::~FakeVideoEncodeAcceleratorFactory() {}
24 void FakeVideoEncodeAcceleratorFactory::SetInitializationWillSucceed(
25 bool will_init_succeed) {
26 will_init_succeed_ = will_init_succeed;
29 void FakeVideoEncodeAcceleratorFactory::SetAutoRespond(bool auto_respond) {
30 auto_respond_ = auto_respond;
31 if (auto_respond_) {
32 if (!vea_response_callback_.is_null())
33 RespondWithVideoEncodeAccelerator();
34 if (!shm_response_callback_.is_null())
35 RespondWithSharedMemory();
39 void FakeVideoEncodeAcceleratorFactory::CreateVideoEncodeAccelerator(
40 const ReceiveVideoEncodeAcceleratorCallback& callback) {
41 DCHECK(!callback.is_null());
42 DCHECK(!next_response_vea_);
44 FakeVideoEncodeAccelerator* const vea =
45 new FakeVideoEncodeAccelerator(task_runner_);
46 vea->SetWillInitializationSucceed(will_init_succeed_);
47 next_response_vea_.reset(vea);
48 vea_response_callback_ = callback;
49 if (auto_respond_)
50 RespondWithVideoEncodeAccelerator();
53 void FakeVideoEncodeAcceleratorFactory::CreateSharedMemory(
54 size_t size, const ReceiveVideoEncodeMemoryCallback& callback) {
55 DCHECK(!callback.is_null());
56 DCHECK(!next_response_shm_);
58 next_response_shm_.reset(new base::SharedMemory());
59 CHECK(next_response_shm_->CreateAndMapAnonymous(size));
60 shm_response_callback_ = callback;
61 if (auto_respond_)
62 RespondWithSharedMemory();
65 void FakeVideoEncodeAcceleratorFactory::RespondWithVideoEncodeAccelerator() {
66 DCHECK(next_response_vea_.get());
67 last_response_vea_ = next_response_vea_.get();
68 ++vea_response_count_;
69 base::ResetAndReturn(&vea_response_callback_).Run(
70 task_runner_, next_response_vea_.Pass());
73 void FakeVideoEncodeAcceleratorFactory::RespondWithSharedMemory() {
74 DCHECK(next_response_shm_.get());
75 last_response_shm_ = next_response_shm_.get();
76 ++shm_response_count_;
77 base::ResetAndReturn(&shm_response_callback_).Run(next_response_shm_.Pass());
80 } // namespace cast
81 } // namespace media