Class for allocating a chunk of memory for RenderPass
[chromium-blink-merge.git] / remoting / protocol / fake_authenticator.h
bloba6ddc74528ab07b2965dfc815e9d76a67b5fe63a
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 virtual ~FakeChannelAuthenticator();
21 // ChannelAuthenticator interface.
22 virtual void SecureAndAuthenticate(
23 scoped_ptr<net::StreamSocket> socket,
24 const DoneCallback& done_callback) OVERRIDE;
26 private:
27 void OnAuthBytesWritten(int result);
28 void OnAuthBytesRead(int result);
30 void CallDoneCallback();
32 int result_;
33 bool async_;
35 scoped_ptr<net::StreamSocket> socket_;
36 DoneCallback done_callback_;
38 bool did_read_bytes_;
39 bool did_write_bytes_;
41 base::WeakPtrFactory<FakeChannelAuthenticator> weak_factory_;
43 DISALLOW_COPY_AND_ASSIGN(FakeChannelAuthenticator);
46 class FakeAuthenticator : public Authenticator {
47 public:
48 enum Type {
49 HOST,
50 CLIENT,
53 enum Action {
54 ACCEPT,
55 REJECT,
56 REJECT_CHANNEL
59 FakeAuthenticator(Type type, int round_trips, Action action, bool async);
61 virtual ~FakeAuthenticator();
63 // Set the number of messages that the authenticator needs to process before
64 // started() returns true. Default to 0.
65 void set_messages_till_started(int messages);
67 // Authenticator interface.
68 virtual State state() const OVERRIDE;
69 virtual bool started() const OVERRIDE;
70 virtual RejectionReason rejection_reason() const OVERRIDE;
71 virtual void ProcessMessage(const buzz::XmlElement* message,
72 const base::Closure& resume_callback) OVERRIDE;
73 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
74 virtual scoped_ptr<ChannelAuthenticator>
75 CreateChannelAuthenticator() const OVERRIDE;
77 protected:
78 Type type_;
79 int round_trips_;
80 Action action_;
81 bool async_;
83 // Total number of messages that have been processed.
84 int messages_;
85 // Number of messages that the authenticator needs to process before started()
86 // returns true. Default to 0.
87 int messages_till_started_;
89 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
92 class FakeHostAuthenticatorFactory : public AuthenticatorFactory {
93 public:
94 FakeHostAuthenticatorFactory(
95 int round_trips, int messages_till_start,
96 FakeAuthenticator::Action action, bool async);
97 virtual ~FakeHostAuthenticatorFactory();
99 // AuthenticatorFactory interface.
100 virtual scoped_ptr<Authenticator> CreateAuthenticator(
101 const std::string& local_jid,
102 const std::string& remote_jid,
103 const buzz::XmlElement* first_message) OVERRIDE;
105 private:
106 int round_trips_;
107 int messages_till_started_;
108 FakeAuthenticator::Action action_;
109 bool async_;
111 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory);
114 } // namespace protocol
115 } // namespace remoting
117 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_