| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ | 5 #ifndef REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ |
| 6 #define REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ | 6 #define REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "remoting/protocol/authenticator.h" | 10 #include "remoting/protocol/authenticator.h" |
| 11 #include "remoting/protocol/channel_authenticator.h" | 11 #include "remoting/protocol/channel_authenticator.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 class FakeChannelAuthenticator : public ChannelAuthenticator { | 16 class FakeChannelAuthenticator : public ChannelAuthenticator { |
| 17 public: | 17 public: |
| 18 FakeChannelAuthenticator(bool accept, bool async); | 18 FakeChannelAuthenticator(bool accept, bool async); |
| 19 virtual ~FakeChannelAuthenticator(); | 19 ~FakeChannelAuthenticator() override; |
| 20 | 20 |
| 21 // ChannelAuthenticator interface. | 21 // ChannelAuthenticator interface. |
| 22 virtual void SecureAndAuthenticate( | 22 void SecureAndAuthenticate(scoped_ptr<net::StreamSocket> socket, |
| 23 scoped_ptr<net::StreamSocket> socket, | 23 const DoneCallback& done_callback) override; |
| 24 const DoneCallback& done_callback) override; | |
| 25 | 24 |
| 26 private: | 25 private: |
| 27 void OnAuthBytesWritten(int result); | 26 void OnAuthBytesWritten(int result); |
| 28 void OnAuthBytesRead(int result); | 27 void OnAuthBytesRead(int result); |
| 29 | 28 |
| 30 void CallDoneCallback(); | 29 void CallDoneCallback(); |
| 31 | 30 |
| 32 int result_; | 31 int result_; |
| 33 bool async_; | 32 bool async_; |
| 34 | 33 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 }; | 50 }; |
| 52 | 51 |
| 53 enum Action { | 52 enum Action { |
| 54 ACCEPT, | 53 ACCEPT, |
| 55 REJECT, | 54 REJECT, |
| 56 REJECT_CHANNEL | 55 REJECT_CHANNEL |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 FakeAuthenticator(Type type, int round_trips, Action action, bool async); | 58 FakeAuthenticator(Type type, int round_trips, Action action, bool async); |
| 60 | 59 |
| 61 virtual ~FakeAuthenticator(); | 60 ~FakeAuthenticator() override; |
| 62 | 61 |
| 63 // Set the number of messages that the authenticator needs to process before | 62 // Set the number of messages that the authenticator needs to process before |
| 64 // started() returns true. Default to 0. | 63 // started() returns true. Default to 0. |
| 65 void set_messages_till_started(int messages); | 64 void set_messages_till_started(int messages); |
| 66 | 65 |
| 67 // Authenticator interface. | 66 // Authenticator interface. |
| 68 virtual State state() const override; | 67 State state() const override; |
| 69 virtual bool started() const override; | 68 bool started() const override; |
| 70 virtual RejectionReason rejection_reason() const override; | 69 RejectionReason rejection_reason() const override; |
| 71 virtual void ProcessMessage(const buzz::XmlElement* message, | 70 void ProcessMessage(const buzz::XmlElement* message, |
| 72 const base::Closure& resume_callback) override; | 71 const base::Closure& resume_callback) override; |
| 73 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() override; | 72 scoped_ptr<buzz::XmlElement> GetNextMessage() override; |
| 74 virtual scoped_ptr<ChannelAuthenticator> | 73 scoped_ptr<ChannelAuthenticator> CreateChannelAuthenticator() const override; |
| 75 CreateChannelAuthenticator() const override; | |
| 76 | 74 |
| 77 protected: | 75 protected: |
| 78 Type type_; | 76 Type type_; |
| 79 int round_trips_; | 77 int round_trips_; |
| 80 Action action_; | 78 Action action_; |
| 81 bool async_; | 79 bool async_; |
| 82 | 80 |
| 83 // Total number of messages that have been processed. | 81 // Total number of messages that have been processed. |
| 84 int messages_; | 82 int messages_; |
| 85 // Number of messages that the authenticator needs to process before started() | 83 // Number of messages that the authenticator needs to process before started() |
| 86 // returns true. Default to 0. | 84 // returns true. Default to 0. |
| 87 int messages_till_started_; | 85 int messages_till_started_; |
| 88 | 86 |
| 89 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); | 87 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); |
| 90 }; | 88 }; |
| 91 | 89 |
| 92 class FakeHostAuthenticatorFactory : public AuthenticatorFactory { | 90 class FakeHostAuthenticatorFactory : public AuthenticatorFactory { |
| 93 public: | 91 public: |
| 94 FakeHostAuthenticatorFactory( | 92 FakeHostAuthenticatorFactory( |
| 95 int round_trips, int messages_till_start, | 93 int round_trips, int messages_till_start, |
| 96 FakeAuthenticator::Action action, bool async); | 94 FakeAuthenticator::Action action, bool async); |
| 97 virtual ~FakeHostAuthenticatorFactory(); | 95 ~FakeHostAuthenticatorFactory() override; |
| 98 | 96 |
| 99 // AuthenticatorFactory interface. | 97 // AuthenticatorFactory interface. |
| 100 virtual scoped_ptr<Authenticator> CreateAuthenticator( | 98 scoped_ptr<Authenticator> CreateAuthenticator( |
| 101 const std::string& local_jid, | 99 const std::string& local_jid, |
| 102 const std::string& remote_jid, | 100 const std::string& remote_jid, |
| 103 const buzz::XmlElement* first_message) override; | 101 const buzz::XmlElement* first_message) override; |
| 104 | 102 |
| 105 private: | 103 private: |
| 106 int round_trips_; | 104 int round_trips_; |
| 107 int messages_till_started_; | 105 int messages_till_started_; |
| 108 FakeAuthenticator::Action action_; | 106 FakeAuthenticator::Action action_; |
| 109 bool async_; | 107 bool async_; |
| 110 | 108 |
| 111 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory); | 109 DISALLOW_COPY_AND_ASSIGN(FakeHostAuthenticatorFactory); |
| 112 }; | 110 }; |
| 113 | 111 |
| 114 } // namespace protocol | 112 } // namespace protocol |
| 115 } // namespace remoting | 113 } // namespace remoting |
| 116 | 114 |
| 117 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ | 115 #endif // REMOTING_PROTOCOL_FAKE_AUTHENTICATOR_H_ |
| OLD | NEW |