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

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: rebase 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 isAuthenticated)>;
Kevin M 2015/12/03 19:11:36 No camelCase for variable names.
haibinlu 2015/12/03 22:28:35 Done.
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 // ConnectionErrorObserver implementation.
Kevin M 2015/12/03 19:11:36 Move overrides to the bottom of the methods
haibinlu 2015/12/03 22:28:35 Done.
56 // Used to implement reconnection logic on unexpected disconnections.
57 void OnConnectionError(int error) override;
58
59 // BlimpMessageProcessor implementation.
60 void ProcessMessage(scoped_ptr<BlimpMessage> message,
61 const net::CompletionCallback& callback) override;
62
63 void InvokeAuthCallback(bool isAuthenticated);
64
65 // Invoked when timeout on waiting for auth message.
Kevin M 2015/12/03 19:11:36 nit: on timeout while
haibinlu 2015/12/03 22:28:35 Done.
66 void FailAuthetication();
67
68 // The connection to be authenticated.
69 scoped_ptr<BlimpConnection> connection_;
70
71 // Callback for authentication result;
72 AuthCallback auth_callback_;
73
74 // A timer to fail authentication on timeout.
75 scoped_ptr<base::OneShotTimer> timer_;
Kevin M 2015/12/03 19:11:36 Move this out of a scoped_ptr? It's never going to
haibinlu 2015/12/03 22:28:35 Done.
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 isAuthenticated);
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_;
Kevin M 2015/12/03 19:11:36 What's the purpose of tracking the pending authent
haibinlu 2015/12/03 22:28:35 Wez@, what do you think? Since we are not doing a
93
Kevin M 2015/12/03 19:11:36 Add WeakPtrFactory<> for callbacks to Authenticato
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