MD Downloads: center "Open downloads folder" when there's no downloads
[chromium-blink-merge.git] / remoting / protocol / fake_authenticator.h
blob6c153df0bb1f71f8beff56c6686042b9b5a42a4e
1 // Copyright (c) 2012 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.
5 #ifndef REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "remoting/protocol/authenticator.h"
11 #include "remoting/protocol/channel_authenticator.h"
13 namespace remoting {
14 namespace protocol {
16 class FakeChannelAuthenticator : public ChannelAuthenticator {
17 public:
18 FakeChannelAuthenticator(bool accept, bool async);
19 ~FakeChannelAuthenticator() override;
21 // ChannelAuthenticator interface.
22 void SecureAndAuthenticate(scoped_ptr<P2PStreamSocket> socket,
23 const DoneCallback& done_callback) override;
25 private:
26 void OnAuthBytesWritten(int result);
27 void OnAuthBytesRead(int result);
29 void CallDoneCallback();
31 int result_;
32 bool async_;
34 scoped_ptr<P2PStreamSocket> socket_;
35 DoneCallback done_callback_;
37 bool did_read_bytes_;
38 bool did_write_bytes_;
40 base::WeakPtrFactory<FakeChannelAuthenticator> weak_factory_;
42 DISALLOW_COPY_AND_ASSIGN(FakeChannelAuthenticator);
45 class FakeAuthenticator : public Authenticator {
46 public:
47 enum Type {
48 HOST,
49 CLIENT,
52 enum Action {
53 ACCEPT,
54 REJECT,
55 REJECT_CHANNEL
58 FakeAuthenticator(Type type, int round_trips, Action action, bool async);
60 ~FakeAuthenticator() override;
62 // Set the number of messages that the authenticator needs to process before
63 // started() returns true. Default to 0.
64 void set_messages_till_started(int messages);
66 // Authenticator interface.
67 State state() const override;
68 bool started() const override;
69 RejectionReason rejection_reason() const override;
70 void ProcessMessage(const buzz::XmlElement* message,
71 const base::Closure& resume_callback) override;
72 scoped_ptr<buzz::XmlElement> GetNextMessage() override;
73 const std::string& GetAuthKey() const override;
74 scoped_ptr<ChannelAuthenticator> CreateChannelAuthenticator() const override;
76 protected:
77 Type type_;
78 int round_trips_;
79 Action action_;
80 bool async_;
82 // Total number of messages that have been processed.
83 int messages_;
84 // Number of messages that the authenticator needs to process before started()
85 // returns true. Default to 0.
86 int messages_till_started_;
88 std::string auth_key_;
90 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
93 class FakeHostAuthenticatorFactory : public AuthenticatorFactory {
94 public:
95 FakeHostAuthenticatorFactory(
96 int round_trips, int messages_till_start,
97 FakeAuthenticator::Action action, bool async);
98 ~FakeHostAuthenticatorFactory() override;
100 // AuthenticatorFactory interface.
101 scoped_ptr<Authenticator> CreateAuthenticator(
102 const std::string& local_jid,
103 const std::string& remote_jid,
104 const buzz::XmlElement* first_message) override;
106 private:
107 int round_trips_;
108 int messages_till_started_;
109 FakeAuthenticator::Action action_;
110 bool async_;
112 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory);
115 } // namespace protocol
116 } // namespace remoting
118 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_