Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(986)

Side by Side Diff: remoting/protocol/authenticator.h

Issue 12389010: Refactor of Authenticator to allow it to ProcessMessage asynchronously and then call a callback (Closed) Base URL: http://git.chromium.org/chromium/src.git@host_key_pair
Patch Set: Remove useless include Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_AUTHENTICATOR_H_ 5 #ifndef REMOTING_PROTOCOL_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_ 6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 12
12 namespace buzz { 13 namespace buzz {
13 class XmlElement; 14 class XmlElement;
14 } // namespace buzz 15 } // namespace buzz
15 16
16 namespace remoting { 17 namespace remoting {
17 namespace protocol { 18 namespace protocol {
18 19
19 class ChannelAuthenticator; 20 class ChannelAuthenticator;
(...skipping 11 matching lines...) Expand all
31 // and session-accept messages or in a session-info 32 // and session-accept messages or in a session-info
32 // message. Session-info messages are used only if authenticators need 33 // message. Session-info messages are used only if authenticators need
33 // to exchange more than one message. 34 // to exchange more than one message.
34 class Authenticator { 35 class Authenticator {
35 public: 36 public:
36 // Allowed state transitions: 37 // Allowed state transitions:
37 // When ProcessMessage() is called: 38 // When ProcessMessage() is called:
38 // WAITING_MESSAGE -> MESSAGE_READY 39 // WAITING_MESSAGE -> MESSAGE_READY
39 // WAITING_MESSAGE -> ACCEPTED 40 // WAITING_MESSAGE -> ACCEPTED
40 // WAITING_MESSAGE -> REJECTED 41 // WAITING_MESSAGE -> REJECTED
42 // WAITING_MESSAGE -> PROCESSING_MESSAGE -> MESSAGE_READY
Sergey Ulanov 2013/03/01 01:28:30 Move the second transition to a separate line and
rmsousa 2013/03/01 02:22:11 Done.
41 // When GetNextMessage() is called: 43 // When GetNextMessage() is called:
42 // MESSAGE_READY -> WAITING_MESSAGE 44 // MESSAGE_READY -> WAITING_MESSAGE
43 // MESSAGE_READY -> ACCEPTED 45 // MESSAGE_READY -> ACCEPTED
44 enum State { 46 enum State {
45 // Waiting for the next message from the peer. 47 // Waiting for the next message from the peer.
46 WAITING_MESSAGE, 48 WAITING_MESSAGE,
47 49
48 // Next message is ready to be sent to the peer. 50 // Next message is ready to be sent to the peer.
49 MESSAGE_READY, 51 MESSAGE_READY,
50 52
51 // Session is authenticated successufully. 53 // Session is authenticated successufully.
52 ACCEPTED, 54 ACCEPTED,
53 55
54 // Session is rejected. 56 // Session is rejected.
55 REJECTED, 57 REJECTED,
58
59 // Asynchronously processing the last message from the peer.
60 PROCESSING_MESSAGE,
56 }; 61 };
57 62
58 enum RejectionReason { 63 enum RejectionReason {
59 INVALID_CREDENTIALS, 64 INVALID_CREDENTIALS,
60 PROTOCOL_ERROR, 65 PROTOCOL_ERROR,
61 }; 66 };
62 67
63 // Returns true if |message| is an Authenticator message. 68 // Returns true if |message| is an Authenticator message.
64 static bool IsAuthenticatorMessage(const buzz::XmlElement* message); 69 static bool IsAuthenticatorMessage(const buzz::XmlElement* message);
65 70
66 // Creates an empty Authenticator message, owned by the caller. 71 // Creates an empty Authenticator message, owned by the caller.
67 static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); 72 static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage();
68 73
69 // Finds Authenticator message among child elements of |message|, or 74 // Finds Authenticator message among child elements of |message|, or
70 // returns NULL otherwise. 75 // returns NULL otherwise.
71 static const buzz::XmlElement* FindAuthenticatorMessage( 76 static const buzz::XmlElement* FindAuthenticatorMessage(
72 const buzz::XmlElement* message); 77 const buzz::XmlElement* message);
73 78
74 Authenticator() {} 79 Authenticator() {}
75 virtual ~Authenticator() {} 80 virtual ~Authenticator() {}
76 81
77 // Returns current state of the authenticator. 82 // Returns current state of the authenticator.
78 virtual State state() const = 0; 83 virtual State state() const = 0;
79 84
80 // Returns rejection reason. Can be called only when in REJECTED state. 85 // Returns rejection reason. Can be called only when in REJECTED state.
81 virtual RejectionReason rejection_reason() const = 0; 86 virtual RejectionReason rejection_reason() const = 0;
82 87
83 // Called in response to incoming message received from the peer. 88 // Called in response to incoming message received from the peer.
84 // Should only be called when in WAITING_MESSAGE state. Caller 89 // Should only be called when in WAITING_MESSAGE state. Caller retains
85 // retains ownership of |message|. 90 // ownership of |message|. |resume_callback| will be called when processing is
86 virtual void ProcessMessage(const buzz::XmlElement* message) = 0; 91 // finished. The implementation must guarantee that |resume_callback| is not
92 // called after the Authenticator is destroyed.
93 virtual void ProcessMessage(const base::Closure& resume_callback,
Sergey Ulanov 2013/03/01 01:28:30 It would be more natural to have message argument
rmsousa 2013/03/01 02:22:11 Done.
94 const buzz::XmlElement* message) = 0;
87 95
88 // Must be called when in MESSAGE_READY state. Returns next 96 // Must be called when in MESSAGE_READY state. Returns next
89 // authentication message that needs to be sent to the peer. 97 // authentication message that needs to be sent to the peer.
90 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0; 98 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0;
91 99
92 // Creates new authenticator for a channel. Can be called only in 100 // Creates new authenticator for a channel. Can be called only in
93 // the ACCEPTED state. 101 // the ACCEPTED state.
94 virtual scoped_ptr<ChannelAuthenticator> 102 virtual scoped_ptr<ChannelAuthenticator>
95 CreateChannelAuthenticator() const = 0; 103 CreateChannelAuthenticator() const = 0;
96 }; 104 };
(...skipping 15 matching lines...) Expand all
112 virtual scoped_ptr<Authenticator> CreateAuthenticator( 120 virtual scoped_ptr<Authenticator> CreateAuthenticator(
113 const std::string& local_jid, 121 const std::string& local_jid,
114 const std::string& remote_jid, 122 const std::string& remote_jid,
115 const buzz::XmlElement* first_message) = 0; 123 const buzz::XmlElement* first_message) = 0;
116 }; 124 };
117 125
118 } // namespace protocol 126 } // namespace protocol
119 } // namespace remoting 127 } // namespace remoting
120 128
121 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ 129 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698