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

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

Issue 6191001: Cleanup: Use AUTH_SCHEME enum instead of a string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merge with trunk Created 9 years, 11 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) 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 #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 const std::string& scheme) { 71 HttpAuth::Scheme 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 15 matching lines...) Expand all
97 // Linear scan through the realm entries. 97 // Linear scan through the realm entries.
98 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 98 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
99 if (it->origin() == origin && it->HasEnclosingPath(parent_dir)) 99 if (it->origin() == origin && it->HasEnclosingPath(parent_dir))
100 return &(*it); 100 return &(*it);
101 } 101 }
102 return NULL; // No entry found. 102 return NULL; // No entry found.
103 } 103 }
104 104
105 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, 105 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin,
106 const std::string& realm, 106 const std::string& realm,
107 const std::string& scheme, 107 HttpAuth::Scheme scheme,
108 const std::string& auth_challenge, 108 const std::string& auth_challenge,
109 const string16& username, 109 const string16& username,
110 const string16& password, 110 const string16& password,
111 const std::string& path) { 111 const std::string& path) {
112 CheckOriginIsValid(origin); 112 CheckOriginIsValid(origin);
113 CheckPathIsValid(path); 113 CheckPathIsValid(path);
114 114
115 // Check for existing entry (we will re-use it if present). 115 // Check for existing entry (we will re-use it if present).
116 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); 116 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme);
117 if (!entry) { 117 if (!entry) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 177
178 void HttpAuthCache::Entry::UpdateStaleChallenge( 178 void HttpAuthCache::Entry::UpdateStaleChallenge(
179 const std::string& auth_challenge) { 179 const std::string& auth_challenge) {
180 auth_challenge_ = auth_challenge; 180 auth_challenge_ = auth_challenge;
181 nonce_count_ = 1; 181 nonce_count_ = 1;
182 } 182 }
183 183
184 bool HttpAuthCache::Remove(const GURL& origin, 184 bool HttpAuthCache::Remove(const GURL& origin,
185 const std::string& realm, 185 const std::string& realm,
186 const std::string& scheme, 186 HttpAuth::Scheme scheme,
187 const string16& username, 187 const string16& username,
188 const string16& password) { 188 const string16& password) {
189 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 189 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
190 if (it->origin() == origin && it->realm() == realm && 190 if (it->origin() == origin && it->realm() == realm &&
191 it->scheme() == scheme) { 191 it->scheme() == scheme) {
192 if (username == it->username() && password == it->password()) { 192 if (username == it->username() && password == it->password()) {
193 entries_.erase(it); 193 entries_.erase(it);
194 return true; 194 return true;
195 } 195 }
196 return false; 196 return false;
197 } 197 }
198 } 198 }
199 return false; 199 return false;
200 } 200 }
201 201
202 bool HttpAuthCache::UpdateStaleChallenge(const GURL& origin, 202 bool HttpAuthCache::UpdateStaleChallenge(const GURL& origin,
203 const std::string& realm, 203 const std::string& realm,
204 const std::string& scheme, 204 HttpAuth::Scheme scheme,
205 const std::string& auth_challenge) { 205 const std::string& auth_challenge) {
206 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); 206 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme);
207 if (!entry) 207 if (!entry)
208 return false; 208 return false;
209 entry->UpdateStaleChallenge(auth_challenge); 209 entry->UpdateStaleChallenge(auth_challenge);
210 return true; 210 return true;
211 } 211 }
212 212
213 } // namespace net 213 } // 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