Remove dependency on content from remoting_host.
[chromium-blink-merge.git] / remoting / host / fake_host_extension.cc
blob34c31f928d83759c29e534101a91c104d8a96d0d
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 "remoting/host/fake_host_extension.h"
7 #include <string>
9 #include "base/logging.h"
10 #include "remoting/codec/video_encoder.h"
11 #include "remoting/host/host_extension_session.h"
12 #include "remoting/proto/control.pb.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
15 namespace remoting {
17 class FakeExtension::Session : public HostExtensionSession {
18 public:
19 Session(FakeExtension* extension, const std::string& message_type);
20 ~Session() override {}
22 // HostExtensionSession interface.
23 void OnCreateVideoCapturer(
24 scoped_ptr<webrtc::DesktopCapturer>* encoder) override;
25 void OnCreateVideoEncoder(scoped_ptr<VideoEncoder>* encoder) override;
26 bool ModifiesVideoPipeline() const override;
27 bool OnExtensionMessage(ClientSessionControl* client_session_control,
28 protocol::ClientStub* client_stub,
29 const protocol::ExtensionMessage& message) override;
31 private:
32 FakeExtension* extension_;
33 std::string message_type_;
35 DISALLOW_COPY_AND_ASSIGN(Session);
38 FakeExtension::Session::Session(
39 FakeExtension* extension, const std::string& message_type)
40 : extension_(extension),
41 message_type_(message_type) {
44 void FakeExtension::Session::OnCreateVideoCapturer(
45 scoped_ptr<webrtc::DesktopCapturer>* capturer) {
46 extension_->has_wrapped_video_capturer_ = true;
47 if (extension_->steal_video_capturer_) {
48 capturer->reset();
52 void FakeExtension::Session::OnCreateVideoEncoder(
53 scoped_ptr<VideoEncoder>* encoder) {
54 extension_->has_wrapped_video_encoder_ = true;
57 bool FakeExtension::Session::ModifiesVideoPipeline() const {
58 return extension_->steal_video_capturer_;
61 bool FakeExtension::Session::OnExtensionMessage(
62 ClientSessionControl* client_session_control,
63 protocol::ClientStub* client_stub,
64 const protocol::ExtensionMessage& message) {
65 if (message.type() == message_type_) {
66 extension_->has_handled_message_ = true;
67 return true;
69 return false;
72 FakeExtension::FakeExtension(const std::string& message_type,
73 const std::string& capability)
74 : message_type_(message_type),
75 capability_(capability),
76 steal_video_capturer_(false),
77 has_handled_message_(false),
78 has_wrapped_video_encoder_(false),
79 has_wrapped_video_capturer_(false),
80 was_instantiated_(false) {
83 FakeExtension::~FakeExtension() {
86 std::string FakeExtension::capability() const {
87 return capability_;
90 scoped_ptr<HostExtensionSession> FakeExtension::CreateExtensionSession(
91 ClientSessionControl* client_session_control,
92 protocol::ClientStub* client_stub) {
93 DCHECK(!was_instantiated());
94 was_instantiated_ = true;
95 scoped_ptr<HostExtensionSession> session(new Session(this, message_type_));
96 return session.Pass();
99 } // namespace remoting