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

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

Issue 10916272: Remove HttpAuth::Scheme enum in favor of a string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_auth_cache.h ('k') | net/http/http_auth_cache_unittest.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) 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_cache.h" 5 #include "net/http/http_auth_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 9
10 namespace { 10 namespace {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 HttpAuthCache::HttpAuthCache() { 62 HttpAuthCache::HttpAuthCache() {
63 } 63 }
64 64
65 HttpAuthCache::~HttpAuthCache() { 65 HttpAuthCache::~HttpAuthCache() {
66 } 66 }
67 67
68 // Performance: O(n), where n is the number of realm entries. 68 // Performance: O(n), where n is the number of realm entries.
69 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, 69 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin,
70 const std::string& realm, 70 const std::string& realm,
71 HttpAuth::Scheme scheme) { 71 const std::string& scheme) {
72 CheckOriginIsValid(origin); 72 CheckOriginIsValid(origin);
73 73
74 // Linear scan through the realm entries. 74 // Linear scan through the realm entries.
75 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 75 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
76 if (it->origin() == origin && it->realm() == realm && 76 if (it->origin() == origin && it->realm() == realm &&
77 it->scheme() == scheme) 77 it->scheme() == scheme)
78 return &(*it); 78 return &(*it);
79 } 79 }
80 return NULL; // No realm entry found. 80 return NULL; // No realm entry found.
81 } 81 }
(...skipping 21 matching lines...) Expand all
103 (!best_match || len > best_match_length)) { 103 (!best_match || len > best_match_length)) {
104 best_match_length = len; 104 best_match_length = len;
105 best_match = &(*it); 105 best_match = &(*it);
106 } 106 }
107 } 107 }
108 return best_match; 108 return best_match;
109 } 109 }
110 110
111 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, 111 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin,
112 const std::string& realm, 112 const std::string& realm,
113 HttpAuth::Scheme scheme, 113 const std::string& scheme,
114 const std::string& auth_challenge, 114 const std::string& auth_challenge,
115 const AuthCredentials& credentials, 115 const AuthCredentials& credentials,
116 const std::string& path) { 116 const std::string& path) {
117 CheckOriginIsValid(origin); 117 CheckOriginIsValid(origin);
118 CheckPathIsValid(path); 118 CheckPathIsValid(path);
119 119
120 // Check for existing entry (we will re-use it if present). 120 // Check for existing entry (we will re-use it if present).
121 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); 121 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme);
122 if (!entry) { 122 if (!entry) {
123 // Failsafe to prevent unbounded memory growth of the cache. 123 // Failsafe to prevent unbounded memory growth of the cache.
(...skipping 23 matching lines...) Expand all
147 HttpAuthCache::Entry::~Entry() { 147 HttpAuthCache::Entry::~Entry() {
148 } 148 }
149 149
150 void HttpAuthCache::Entry::UpdateStaleChallenge( 150 void HttpAuthCache::Entry::UpdateStaleChallenge(
151 const std::string& auth_challenge) { 151 const std::string& auth_challenge) {
152 auth_challenge_ = auth_challenge; 152 auth_challenge_ = auth_challenge;
153 nonce_count_ = 1; 153 nonce_count_ = 1;
154 } 154 }
155 155
156 HttpAuthCache::Entry::Entry() 156 HttpAuthCache::Entry::Entry()
157 : scheme_(HttpAuth::AUTH_SCHEME_MAX), 157 : nonce_count_(0) {
158 nonce_count_(0) {
159 } 158 }
160 159
161 void HttpAuthCache::Entry::AddPath(const std::string& path) { 160 void HttpAuthCache::Entry::AddPath(const std::string& path) {
162 std::string parent_dir = GetParentDirectory(path); 161 std::string parent_dir = GetParentDirectory(path);
163 if (!HasEnclosingPath(parent_dir, NULL)) { 162 if (!HasEnclosingPath(parent_dir, NULL)) {
164 // Remove any entries that have been subsumed by the new entry. 163 // Remove any entries that have been subsumed by the new entry.
165 paths_.remove_if(IsEnclosedBy(parent_dir)); 164 paths_.remove_if(IsEnclosedBy(parent_dir));
166 165
167 // Failsafe to prevent unbounded memory growth of the cache. 166 // Failsafe to prevent unbounded memory growth of the cache.
168 if (paths_.size() >= kMaxNumPathsPerRealmEntry) { 167 if (paths_.size() >= kMaxNumPathsPerRealmEntry) {
(...skipping 20 matching lines...) Expand all
189 if (path_len) 188 if (path_len)
190 *path_len = it->length(); 189 *path_len = it->length();
191 return true; 190 return true;
192 } 191 }
193 } 192 }
194 return false; 193 return false;
195 } 194 }
196 195
197 bool HttpAuthCache::Remove(const GURL& origin, 196 bool HttpAuthCache::Remove(const GURL& origin,
198 const std::string& realm, 197 const std::string& realm,
199 HttpAuth::Scheme scheme, 198 const std::string& scheme,
200 const AuthCredentials& credentials) { 199 const AuthCredentials& credentials) {
201 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 200 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
202 if (it->origin() == origin && it->realm() == realm && 201 if (it->origin() == origin && it->realm() == realm &&
203 it->scheme() == scheme) { 202 it->scheme() == scheme) {
204 if (credentials.Equals(it->credentials())) { 203 if (credentials.Equals(it->credentials())) {
205 entries_.erase(it); 204 entries_.erase(it);
206 return true; 205 return true;
207 } 206 }
208 return false; 207 return false;
209 } 208 }
210 } 209 }
211 return false; 210 return false;
212 } 211 }
213 212
214 bool HttpAuthCache::UpdateStaleChallenge(const GURL& origin, 213 bool HttpAuthCache::UpdateStaleChallenge(const GURL& origin,
215 const std::string& realm, 214 const std::string& realm,
216 HttpAuth::Scheme scheme, 215 const std::string& scheme,
217 const std::string& auth_challenge) { 216 const std::string& auth_challenge) {
218 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); 217 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme);
219 if (!entry) 218 if (!entry)
220 return false; 219 return false;
221 entry->UpdateStaleChallenge(auth_challenge); 220 entry->UpdateStaleChallenge(auth_challenge);
222 return true; 221 return true;
223 } 222 }
224 223
225 void HttpAuthCache::UpdateAllFrom(const HttpAuthCache& other) { 224 void HttpAuthCache::UpdateAllFrom(const HttpAuthCache& other) {
226 for (EntryList::const_iterator it = other.entries_.begin(); 225 for (EntryList::const_iterator it = other.entries_.begin();
227 it != other.entries_.end(); ++it) { 226 it != other.entries_.end(); ++it) {
228 // Add an Entry with one of the original entry's paths. 227 // Add an Entry with one of the original entry's paths.
229 DCHECK(it->paths_.size() > 0); 228 DCHECK(it->paths_.size() > 0);
230 Entry* entry = Add(it->origin(), it->realm(), it->scheme(), 229 Entry* entry = Add(it->origin(), it->realm(), it->scheme(),
231 it->auth_challenge(), it->credentials(), 230 it->auth_challenge(), it->credentials(),
232 it->paths_.back()); 231 it->paths_.back());
233 // Copy all other paths. 232 // Copy all other paths.
234 for (Entry::PathList::const_reverse_iterator it2 = ++it->paths_.rbegin(); 233 for (Entry::PathList::const_reverse_iterator it2 = ++it->paths_.rbegin();
235 it2 != it->paths_.rend(); ++it2) 234 it2 != it->paths_.rend(); ++it2)
236 entry->AddPath(*it2); 235 entry->AddPath(*it2);
237 // Copy nonce count (for digest authentication). 236 // Copy nonce count (for digest authentication).
238 entry->nonce_count_ = it->nonce_count_; 237 entry->nonce_count_ = it->nonce_count_;
239 } 238 }
240 } 239 }
241 240
242 } // namespace net 241 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_cache.h ('k') | net/http/http_auth_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698