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 <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/macros.h"
13 
14 namespace remoting {
15 
16 class ClientSessionDetails;
17 class HostExtension;
18 class HostExtensionSession;
19 
20 namespace protocol {
21 class ClientStub;
22 class ExtensionMessage;
23 }
24 
25 // Helper class used to create and manage a set of HostExtensionSession
26 // instances depending upon the set of registered HostExtensions, and the
27 // set of capabilities negotiated between client and host.
28 class HostExtensionSessionManager {
29  public:
30   using HostExtensions = std::vector<HostExtension*>;
31 
32   // Creates an extension manager for the specified |extensions|.
33   HostExtensionSessionManager(const HostExtensions& extensions,
34                               ClientSessionDetails* client_session_details);
35   virtual ~HostExtensionSessionManager();
36 
37   // Returns the union of all capabilities supported by registered extensions.
38   std::string GetCapabilities() const;
39 
40   // Handles completion of authentication and capabilities negotiation, creating
41   // the set of HostExtensionSessions to match the client's capabilities.
42   void OnNegotiatedCapabilities(protocol::ClientStub* client_stub,
43                                 const std::string& capabilities);
44 
45   // Passes |message| to each HostExtensionSession in turn until the message
46   // is handled, or none remain. Returns true if the message was handled.
47   // It is not valid for more than one extension to handle the same message.
48   bool OnExtensionMessage(const protocol::ExtensionMessage& message);
49 
50  private:
51   using HostExtensionSessions =
52       std::vector<std::unique_ptr<HostExtensionSession>>;
53 
54   // Passed to HostExtensionSessions to allow them to send messages,
55   // disconnect the session, etc.
56   ClientSessionDetails* client_session_details_;
57   protocol::ClientStub* client_stub_;
58 
59   // The HostExtensions to instantiate for the session, if it reaches the
60   // authenticated state.
61   HostExtensions extensions_;
62 
63   // The instantiated HostExtensionSessions, used to handle extension messages.
64   HostExtensionSessions extension_sessions_;
65 
66   DISALLOW_COPY_AND_ASSIGN(HostExtensionSessionManager);
67 };
68 
69 }  // namespace remoting
70 
71 #endif  // REMOTING_HOST_HOST_EXTENSION_SESSION_MANAGER_H_
72