host_extension_session_manager.h 2.6 KB

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