telemetry: Support custom 'out' directory
[chromium-blink-merge.git] / remoting / protocol / fake_authenticator.h
bloba5a2de833441e87897c44a1de06fc7c510d74635
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 CallCallback(
28 net::Error error,
29 scoped_ptr<net::StreamSocket> socket);
31 void OnAuthBytesWritten(int result);
32 void OnAuthBytesRead(int result);
34 net::Error result_;
35 bool async_;
37 scoped_ptr<net::StreamSocket> socket_;
38 DoneCallback done_callback_;
40 bool did_read_bytes_;
41 bool did_write_bytes_;
43 base::WeakPtrFactory<FakeChannelAuthenticator> weak_factory_;
45 DISALLOW_COPY_AND_ASSIGN(FakeChannelAuthenticator);
48 class FakeAuthenticator : public Authenticator {
49 public:
50 enum Type {
51 HOST,
52 CLIENT,
55 enum Action {
56 ACCEPT,
57 REJECT,
58 REJECT_CHANNEL
61 FakeAuthenticator(Type type, int round_trips, Action action, bool async);
62 virtual ~FakeAuthenticator();
64 // Authenticator interface.
65 virtual State state() const OVERRIDE;
66 virtual RejectionReason rejection_reason() const OVERRIDE;
67 virtual void ProcessMessage(const buzz::XmlElement* message,
68 const base::Closure& resume_callback) OVERRIDE;
69 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE;
70 virtual scoped_ptr<ChannelAuthenticator>
71 CreateChannelAuthenticator() const OVERRIDE;
73 protected:
74 Type type_;
75 int round_trips_;
76 Action action_;
77 bool async_;
79 // Total number of messages that have been processed.
80 int messages_;
82 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
85 class FakeHostAuthenticatorFactory : public AuthenticatorFactory {
86 public:
87 FakeHostAuthenticatorFactory(
88 int round_trips, FakeAuthenticator::Action action, bool async);
89 virtual ~FakeHostAuthenticatorFactory();
91 // AuthenticatorFactory interface.
92 virtual scoped_ptr<Authenticator> CreateAuthenticator(
93 const std::string& local_jid,
94 const std::string& remote_jid,
95 const buzz::XmlElement* first_message) OVERRIDE;
97 private:
98 int round_trips_;
99 FakeAuthenticator::Action action_;
100 bool async_;
102 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory);
105 } // namespace protocol
106 } // namespace remoting
108 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_