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#ifndef REMOTING_HOST_HOST_EXTENSION_SESSION_MANAGER_H_ 6#define REMOTING_HOST_HOST_EXTENSION_SESSION_MANAGER_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/memory/scoped_ptr.h" 12#include "base/memory/scoped_vector.h" 13 14namespace webrtc { 15class DesktopCapturer; 16} 17 18namespace remoting { 19 20class ClientSessionControl; 21class HostExtension; 22class HostExtensionSession; 23class VideoEncoder; 24 25namespace protocol { 26class ClientStub; 27class ExtensionMessage; 28} 29 30// Helper class used to create and manage a set of HostExtensionSession 31// instances depending upon the set of registered HostExtensions, and the 32// set of capabilities negotiated between client and host. 33class HostExtensionSessionManager { 34 public: 35 typedef std::vector<HostExtension*> HostExtensions; 36 37 // Creates an extension manager for the specified |extensions|. 38 HostExtensionSessionManager(const HostExtensions& extensions, 39 ClientSessionControl* client_session_control); 40 virtual ~HostExtensionSessionManager(); 41 42 // Returns the union of all capabilities supported by registered extensions. 43 std::string GetCapabilities() const; 44 45 // Calls the corresponding hook functions for each extension, to allow them 46 // to wrap or replace video pipeline components. Only extensions which return 47 // true from ModifiesVideoPipeline() will be called. 48 // The order in which extensions are called is undefined. 49 void OnCreateVideoCapturer(scoped_ptr<webrtc::DesktopCapturer>* capturer); 50 void OnCreateVideoEncoder(scoped_ptr<VideoEncoder>* encoder); 51 52 // Handles completion of authentication and capabilities negotiation, creating 53 // the set of HostExtensionSessions to match the client's capabilities. 54 void OnNegotiatedCapabilities(protocol::ClientStub* client_stub, 55 const std::string& capabilities); 56 57 // Passes |message| to each HostExtensionSession in turn until the message 58 // is handled, or none remain. Returns true if the message was handled. 59 // It is not valid for more than one extension to handle the same message. 60 bool OnExtensionMessage(const protocol::ExtensionMessage& message); 61 62 private: 63 typedef ScopedVector<HostExtensionSession> HostExtensionSessions; 64 65 // Passed to HostExtensionSessions to allow them to send messages, 66 // disconnect the session, etc. 67 ClientSessionControl* client_session_control_; 68 protocol::ClientStub* client_stub_; 69 70 // The HostExtensions to instantiate for the session, if it reaches the 71 // authenticated state. 72 HostExtensions extensions_; 73 74 // The instantiated HostExtensionSessions, used to handle extension messages. 75 HostExtensionSessions extension_sessions_; 76 77 DISALLOW_COPY_AND_ASSIGN(HostExtensionSessionManager); 78}; 79 80} // namespace remoting 81 82#endif // REMOTING_HOST_HOST_EXTENSION_SESSION_MANAGER_H_ 83