blob: b348ffe77b74d2fecdc429f9d18ad7e3666e2b58 [file] [log] [blame]
// Copyright 2014 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.
#include <map>
#include "base/macros.h"
#include "net/base/net_errors.h"
#include "remoting/protocol/stream_channel_factory.h"
namespace remoting {
namespace protocol {
class Authenticator;
class ChannelAuthenticator;
// StreamChannelFactory wrapper that authenticates every channel it creates.
// When CreateChannel() is called it first calls the wrapped
// StreamChannelFactory to create a channel and then uses the specified
// Authenticator to secure and authenticate the new channel before returning it
// to the caller.
class SecureChannelFactory : public StreamChannelFactory {
// Both parameters must outlive the object.
SecureChannelFactory(StreamChannelFactory* channel_factory,
Authenticator* authenticator);
~SecureChannelFactory() override;
// StreamChannelFactory interface.
void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) override;
void CancelChannelCreation(const std::string& name) override;
typedef std::map<std::string, ChannelAuthenticator*> AuthenticatorMap;
void OnBaseChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback,
std::unique_ptr<P2PStreamSocket> socket);
void OnSecureChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback,
int error,
std::unique_ptr<P2PStreamSocket> socket);
StreamChannelFactory* channel_factory_;
Authenticator* authenticator_;
AuthenticatorMap channel_authenticators_;
} // namespace protocol
} // namespace remoting