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

Side by Side Diff: net/http/http_auth_controller.h

Issue 3039028: Make HttpAuthController not reference counted. (Closed)
Patch Set: Created 10 years, 5 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
« no previous file with comments | « no previous file | net/http/http_auth_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 NET_HTTP_HTTP_AUTH_CONTROLLER_H_ 5 #ifndef NET_HTTP_HTTP_AUTH_CONTROLLER_H_
6 #define NET_HTTP_HTTP_AUTH_CONTROLLER_H_ 6 #define NET_HTTP_HTTP_AUTH_CONTROLLER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/net_log.h" 16 #include "net/base/net_log.h"
17 #include "net/http/http_auth.h" 17 #include "net/http/http_auth.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 class AuthChallengeInfo; 21 class AuthChallengeInfo;
22 class HostResolver; 22 class HostResolver;
23 class HttpAuthHandler; 23 class HttpAuthHandler;
24 class HttpNetworkSession; 24 class HttpNetworkSession;
25 class HttpRequestHeaders; 25 class HttpRequestHeaders;
26 struct HttpRequestInfo; 26 struct HttpRequestInfo;
27 27
28 class HttpAuthController : public base::RefCounted<HttpAuthController> { 28 class HttpAuthController {
29 public: 29 public:
30 // The arguments are self explanatory except possibly for |auth_url|, which 30 // The arguments are self explanatory except possibly for |auth_url|, which
31 // should be both the auth target and auth path in a single url argument. 31 // should be both the auth target and auth path in a single url argument.
32 HttpAuthController(HttpAuth::Target target, const GURL& auth_url, 32 HttpAuthController(HttpAuth::Target target, const GURL& auth_url,
33 scoped_refptr<HttpNetworkSession> session); 33 scoped_refptr<HttpNetworkSession> session);
34 34
35 ~HttpAuthController();
36
35 // Generate an authentication token for |target| if necessary. The return 37 // Generate an authentication token for |target| if necessary. The return
36 // value is a net error code. |OK| will be returned both in the case that 38 // value is a net error code. |OK| will be returned both in the case that
37 // a token is correctly generated synchronously, as well as when no tokens 39 // a token is correctly generated synchronously, as well as when no tokens
38 // were necessary. 40 // were necessary.
39 virtual int MaybeGenerateAuthToken(const HttpRequestInfo* request, 41 virtual int MaybeGenerateAuthToken(const HttpRequestInfo* request,
40 CompletionCallback* callback, 42 CompletionCallback* callback,
41 const BoundNetLog& net_log); 43 const BoundNetLog& net_log);
42 44
43 // Adds either the proxy auth header, or the origin server auth header, 45 // Adds either the proxy auth header, or the origin server auth header,
44 // as specified by |target_|. 46 // as specified by |target_|.
45 virtual void AddAuthorizationHeader( 47 virtual void AddAuthorizationHeader(
46 HttpRequestHeaders* authorization_headers); 48 HttpRequestHeaders* authorization_headers);
47 49
48 // Checks for and handles HTTP status code 401 or 407. 50 // Checks for and handles HTTP status code 401 or 407.
49 // |HandleAuthChallenge()| returns OK on success, or a network error code 51 // |HandleAuthChallenge()| returns OK on success, or a network error code
50 // otherwise. It may also populate |auth_info_|. 52 // otherwise. It may also populate |auth_info_|.
51 virtual int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers, 53 virtual int HandleAuthChallenge(scoped_refptr<HttpResponseHeaders> headers,
52 bool do_not_send_server_auth, 54 bool do_not_send_server_auth,
53 bool establishing_tunnel, 55 bool establishing_tunnel,
54 const BoundNetLog& net_log); 56 const BoundNetLog& net_log);
55 57
56 // Store the supplied credentials and prepare to restart the auth. 58 // Store the supplied credentials.
57 virtual void ResetAuth(const std::wstring& username, 59 virtual void SetCredentials(const std::wstring& username,
58 const std::wstring& password); 60 const std::wstring& password);
61
62 // Prepare to restart the auth.
63 virtual void PrepareForAuthRestart();
59 64
60 virtual bool HaveAuthHandler() const { 65 virtual bool HaveAuthHandler() const {
61 return handler_.get() != NULL; 66 return handler_.get() != NULL;
62 } 67 }
63 68
64 virtual bool HaveAuth() const { 69 virtual bool HaveAuth() const {
65 return handler_.get() && !identity_.invalid; 70 return handler_.get() && !identity_.invalid;
66 } 71 }
67 72
73 virtual HttpAuth::Identity AuthIdentity() {
74 return identity_;
75 }
76
68 virtual scoped_refptr<AuthChallengeInfo> auth_info() { 77 virtual scoped_refptr<AuthChallengeInfo> auth_info() {
69 return auth_info_; 78 return auth_info_;
70 } 79 }
71 80
72 virtual bool IsAuthSchemeDisabled(const std::string& scheme) const; 81 virtual bool IsAuthSchemeDisabled(const std::string& scheme) const;
73 virtual void DisableAuthScheme(const std::string& scheme); 82 virtual void DisableAuthScheme(const std::string& scheme);
74 83
75 protected: // So that we can mock this object.
76 friend class base::RefCounted<HttpAuthController>;
77 virtual ~HttpAuthController();
78
79 private: 84 private:
80 // Searches the auth cache for an entry that encompasses the request's path. 85 // Searches the auth cache for an entry that encompasses the request's path.
81 // If such an entry is found, updates |identity_| and |handler_| with the 86 // If such an entry is found, updates |identity_| and |handler_| with the
82 // cache entry's data and returns true. 87 // cache entry's data and returns true.
83 bool SelectPreemptiveAuth(const BoundNetLog& net_log); 88 bool SelectPreemptiveAuth(const BoundNetLog& net_log);
84 89
85 // Invalidates any auth cache entries after authentication has failed. 90 // Invalidates any auth cache entries after authentication has failed.
86 // The identity that was rejected is |identity_|. 91 // The identity that was rejected is |identity_|.
87 void InvalidateRejectedAuthFromCache(); 92 void InvalidateRejectedAuthFromCache();
88 93
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // True if default credentials have already been tried for this transaction 140 // True if default credentials have already been tried for this transaction
136 // in response to an HTTP authentication challenge. 141 // in response to an HTTP authentication challenge.
137 bool default_credentials_used_; 142 bool default_credentials_used_;
138 143
139 scoped_refptr<HttpNetworkSession> session_; 144 scoped_refptr<HttpNetworkSession> session_;
140 145
141 std::set<std::string> disabled_schemes_; 146 std::set<std::string> disabled_schemes_;
142 147
143 CompletionCallbackImpl<HttpAuthController> io_callback_; 148 CompletionCallbackImpl<HttpAuthController> io_callback_;
144 CompletionCallback* user_callback_; 149 CompletionCallback* user_callback_;
150
151 DISALLOW_COPY_AND_ASSIGN(HttpAuthController);
145 }; 152 };
146 153
147 } // namespace net 154 } // namespace net
148 155
149 #endif // NET_HTTP_HTTP_AUTH_CONTROLLER_H_ 156 #endif // NET_HTTP_HTTP_AUTH_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/http_auth_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698