Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / remoting / host / fake_host_extension.cc
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.
4
5 #include "remoting/host/fake_host_extension.h"
6
7 #include <string>
8
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"
14
15 namespace remoting {
16
17 class FakeExtension::Session : public HostExtensionSession {
18  public:
19   Session(FakeExtension* extension, const std::string& message_type);
20   ~Session() override {}
21
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;
30
31  private:
32   FakeExtension* extension_;
33   std::string message_type_;
34
35   DISALLOW_COPY_AND_ASSIGN(Session);
36 };
37
38 FakeExtension::Session::Session(
39     FakeExtension* extension, const std::string& message_type)
40   : extension_(extension),
41     message_type_(message_type) {
42 }
43
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();
49   }
50 }
51
52 void FakeExtension::Session::OnCreateVideoEncoder(
53     scoped_ptr<VideoEncoder>* encoder) {
54   extension_->has_wrapped_video_encoder_ = true;
55 }
56
57 bool FakeExtension::Session::ModifiesVideoPipeline() const {
58   return extension_->steal_video_capturer_;
59 }
60
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;
68   }
69   return false;
70 }
71
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) {
81 }
82
83 FakeExtension::~FakeExtension() {
84 }
85
86 std::string FakeExtension::capability() const {
87   return capability_;
88 }
89
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();
97 }
98
99 } // namespace remoting