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

Side by Side Diff: net/http/http_auth_handler.cc

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "net/http/http_auth_handler.h" 5 #include "net/http/http_auth_handler.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
9 11
10 namespace net { 12 namespace net {
11 13
12 HttpAuthHandler::HttpAuthHandler() 14 HttpAuthHandler::HttpAuthHandler()
13 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX), 15 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX),
14 score_(-1), 16 score_(-1),
15 target_(HttpAuth::AUTH_NONE), 17 target_(HttpAuth::AUTH_NONE),
16 properties_(-1), 18 properties_(-1) {
17 original_callback_(NULL),
18 ALLOW_THIS_IN_INITIALIZER_LIST(
19 wrapper_callback_(
20 this, &HttpAuthHandler::OnGenerateAuthTokenComplete)) {
21 } 19 }
22 20
23 HttpAuthHandler::~HttpAuthHandler() { 21 HttpAuthHandler::~HttpAuthHandler() {
24 } 22 }
25 23
26 bool HttpAuthHandler::InitFromChallenge( 24 bool HttpAuthHandler::InitFromChallenge(
27 HttpAuth::ChallengeTokenizer* challenge, 25 HttpAuth::ChallengeTokenizer* challenge,
28 HttpAuth::Target target, 26 HttpAuth::Target target,
29 const GURL& origin, 27 const GURL& origin,
30 const BoundNetLog& net_log) { 28 const BoundNetLog& net_log) {
(...skipping 24 matching lines...) Expand all
55 case HttpAuth::AUTH_SERVER: 53 case HttpAuth::AUTH_SERVER:
56 return NetLog::TYPE_AUTH_SERVER; 54 return NetLog::TYPE_AUTH_SERVER;
57 default: 55 default:
58 NOTREACHED(); 56 NOTREACHED();
59 return NetLog::TYPE_CANCELLED; 57 return NetLog::TYPE_CANCELLED;
60 } 58 }
61 } 59 }
62 60
63 } // namespace 61 } // namespace
64 62
65 int HttpAuthHandler::GenerateAuthToken(const AuthCredentials* credentials, 63 int HttpAuthHandler::GenerateAuthToken(
66 const HttpRequestInfo* request, 64 const AuthCredentials* credentials, const HttpRequestInfo* request,
67 OldCompletionCallback* callback, 65 const CompletionCallback& callback, std::string* auth_token) {
68 std::string* auth_token) {
69 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream. 66 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream.
70 DCHECK(request); 67 DCHECK(request);
71 DCHECK(credentials != NULL || AllowsDefaultCredentials()); 68 DCHECK(credentials != NULL || AllowsDefaultCredentials());
72 DCHECK(auth_token != NULL); 69 DCHECK(auth_token != NULL);
73 DCHECK(original_callback_ == NULL); 70 DCHECK(callback_.is_null());
74 original_callback_ = callback; 71 callback_ = callback;
75 net_log_.BeginEvent(EventTypeFromAuthTarget(target_), NULL); 72 net_log_.BeginEvent(EventTypeFromAuthTarget(target_), NULL);
76 int rv = GenerateAuthTokenImpl(credentials, request, 73 int rv = GenerateAuthTokenImpl(
77 &wrapper_callback_, auth_token); 74 credentials, request,
75 base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete,
76 base::Unretained(this)),
77 auth_token);
78 if (rv != ERR_IO_PENDING) 78 if (rv != ERR_IO_PENDING)
79 FinishGenerateAuthToken(); 79 FinishGenerateAuthToken();
80 return rv; 80 return rv;
81 } 81 }
82 82
83 bool HttpAuthHandler::NeedsIdentity() { 83 bool HttpAuthHandler::NeedsIdentity() {
84 return true; 84 return true;
85 } 85 }
86 86
87 bool HttpAuthHandler::AllowsDefaultCredentials() { 87 bool HttpAuthHandler::AllowsDefaultCredentials() {
88 return false; 88 return false;
89 } 89 }
90 90
91 bool HttpAuthHandler::AllowsExplicitCredentials() { 91 bool HttpAuthHandler::AllowsExplicitCredentials() {
92 return true; 92 return true;
93 } 93 }
94 94
95 void HttpAuthHandler::OnGenerateAuthTokenComplete(int rv) { 95 void HttpAuthHandler::OnGenerateAuthTokenComplete(int rv) {
96 OldCompletionCallback* callback = original_callback_; 96 CompletionCallback callback = callback_;
97 FinishGenerateAuthToken(); 97 FinishGenerateAuthToken();
98 if (callback) 98 if (!callback.is_null())
99 callback->Run(rv); 99 callback.Run(rv);
100 } 100 }
101 101
102 void HttpAuthHandler::FinishGenerateAuthToken() { 102 void HttpAuthHandler::FinishGenerateAuthToken() {
103 // TOOD(cbentzel): Should this be done in OK case only? 103 // TOOD(cbentzel): Should this be done in OK case only?
104 net_log_.EndEvent(EventTypeFromAuthTarget(target_), NULL); 104 net_log_.EndEvent(EventTypeFromAuthTarget(target_), NULL);
105 original_callback_ = NULL; 105 callback_.Reset();
106 } 106 }
107 107
108 } // namespace net 108 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698