blob: be0a138f06f2adb9953035be94cb690b35e6aea7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CAST_COMMON_CHANNEL_CONNECTION_NAMESPACE_HANDLER_H_
#define CAST_COMMON_CHANNEL_CONNECTION_NAMESPACE_HANDLER_H_
#include "cast/common/channel/cast_message_handler.h"
#include "util/json/json_serialization.h"
namespace cast {
namespace channel {
struct VirtualConnection;
class VirtualConnectionManager;
class VirtualConnectionRouter;
// Handles CastMessages in the connection namespace by opening and closing
// VirtualConnections on the socket on which the messages were received.
class ConnectionNamespaceHandler final : public CastMessageHandler {
public:
class VirtualConnectionPolicy {
public:
virtual ~VirtualConnectionPolicy() = default;
virtual bool IsConnectionAllowed(
const VirtualConnection& virtual_conn) const = 0;
};
// Both |vc_manager| and |vc_policy| should outlive this object.
ConnectionNamespaceHandler(VirtualConnectionManager* vc_manager,
VirtualConnectionPolicy* vc_policy);
~ConnectionNamespaceHandler() override;
// CastMessageHandler overrides.
void OnMessage(VirtualConnectionRouter* router,
CastSocket* socket,
CastMessage&& message) override;
private:
void HandleConnect(VirtualConnectionRouter* router,
CastSocket* socket,
CastMessage&& message,
Json::Value&& parsed_message);
void HandleClose(VirtualConnectionRouter* router,
CastSocket* socket,
CastMessage&& message,
Json::Value&& parsed_message);
void SendClose(VirtualConnectionRouter* router,
VirtualConnection&& virtual_conn);
void SendConnectedResponse(VirtualConnectionRouter* router,
const VirtualConnection& virtual_conn,
int max_protocol_version);
VirtualConnectionManager* const vc_manager_;
VirtualConnectionPolicy* const vc_policy_;
};
} // namespace channel
} // namespace cast
#endif // CAST_COMMON_CHANNEL_CONNECTION_NAMESPACE_HANDLER_H_
|