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

Side by Side Diff: blimp/net/engine_auth_handler.h

Issue 1492643003: [Blimp Net] Add EngineAuthHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Kevin's comments. Created 5 years 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
(Empty)
1 // Copyright 2015 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.
4
5 #ifndef BLIMP_NET_ENGINE_AUTH_HANDLER_H_
6 #define BLIMP_NET_ENGINE_AUTH_HANDLER_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/timer/timer.h"
13 #include "blimp/net/blimp_message_processor.h"
14 #include "blimp/net/blimp_net_export.h"
15 #include "blimp/net/connection_error_observer.h"
16 #include "blimp/net/connection_handler.h"
17 #include "net/base/completion_callback.h"
18
19 namespace blimp {
20
21 class BlimpConnection;
22 class BlimpMessage;
23
24 // Authenticates connections and hand them over to |connection_handler|
25 // if it is authenticated.
26 class BLIMP_NET_EXPORT EngineAuthHandler : public ConnectionHandler {
27 public:
28 // Caller is responsible for ensuring that |connection_handler| outlives
29 // |this|.
30 explicit EngineAuthHandler(ConnectionHandler* connection_handler);
31
32 ~EngineAuthHandler() override;
33
34 // ConnectionHandler implementation.
35 void HandleConnection(scoped_ptr<BlimpConnection> connection) override;
36
37 private:
38 using AuthCallback =
39 base::Callback<void(scoped_ptr<BlimpConnection> connection,
40 bool authenticated)>;
41
42 // Authenticates one connection. |auth_callback| is invoked when
43 // * the connection is authenticated.
44 // * the connection gets into error state.
45 // * timeout on waiting for auth message.
46 class Authenticator : public ConnectionErrorObserver,
47 public BlimpMessageProcessor {
48 public:
49 explicit Authenticator(scoped_ptr<BlimpConnection> connection);
50 ~Authenticator() override;
51
52 void Start(const AuthCallback& auth_callback);
53
54 private:
55 void InvokeAuthCallback(bool authenticated);
56
57 // Invoked on timeout while waiting for auth message.
58 void FailAuthetication();
59
60 // ConnectionErrorObserver implementation.
61 // Used to implement reconnection logic on unexpected disconnections.
62 void OnConnectionError(int error) override;
63
64 // BlimpMessageProcessor implementation.
65 void ProcessMessage(scoped_ptr<BlimpMessage> message,
66 const net::CompletionCallback& callback) override;
67
68 // The connection to be authenticated.
69 scoped_ptr<BlimpConnection> connection_;
Kevin M 2015/12/03 23:12:05 Can you make this a const?
haibinlu 2015/12/03 23:42:21 can not. autheticator will give the ownership of t
70
71 // Callback for authentication result;
72 AuthCallback auth_callback_;
73
74 // A timer to fail authentication on timeout.
75 base::OneShotTimer timer_;
76
77 DISALLOW_COPY_AND_ASSIGN(Authenticator);
78 };
79
80 // Callback when |authenticator| has the authentication result.
81 void OnAuthResult(Authenticator* authenticator,
82 scoped_ptr<BlimpConnection> connection,
83 bool authenticated);
84
85 void RemovePendingAuthenticator(Authenticator* authenticator);
86
87 // Handler for authenticated connections.
88 ConnectionHandler* connection_handler_;
89
90 // Pending authentications. An authenticator is removed from this list once
91 // it has the authentication result.
92 std::vector<scoped_ptr<Authenticator>> pending_auths_;
93
94 DISALLOW_COPY_AND_ASSIGN(EngineAuthHandler);
95 };
96
97 } // namespace blimp
98
99 #endif // BLIMP_NET_ENGINE_AUTH_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698