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

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

Issue 1949004: Added authentication scheme as key to HttpAuthCache. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fixed nits from eroman. Created 10 years, 7 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 | « 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) 2008 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 {
11 11
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return IsEnclosingPath(path, x); 53 return IsEnclosingPath(path, x);
54 } 54 }
55 const std::string& path; 55 const std::string& path;
56 }; 56 };
57 57
58 } // namespace 58 } // namespace
59 59
60 namespace net { 60 namespace net {
61 61
62 // Performance: O(n), where n is the number of realm entries. 62 // Performance: O(n), where n is the number of realm entries.
63 HttpAuthCache::Entry* HttpAuthCache::LookupByRealm(const GURL& origin, 63 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin,
64 const std::string& realm) { 64 const std::string& realm,
65 const std::string& scheme) {
65 CheckOriginIsValid(origin); 66 CheckOriginIsValid(origin);
66 67
67 // Linear scan through the realm entries. 68 // Linear scan through the realm entries.
68 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 69 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
69 if (it->origin() == origin && it->realm() == realm) 70 if (it->origin() == origin && it->realm() == realm &&
71 it->scheme() == scheme)
70 return &(*it); 72 return &(*it);
71 } 73 }
72 return NULL; // No realm entry found. 74 return NULL; // No realm entry found.
73 } 75 }
74 76
75 // Performance: O(n*m), where n is the number of realm entries, m is the number 77 // Performance: O(n*m), where n is the number of realm entries, m is the number
76 // of path entries per realm. Both n amd m are expected to be small; m is 78 // of path entries per realm. Both n amd m are expected to be small; m is
77 // kept small because AddPath() only keeps the shallowest entry. 79 // kept small because AddPath() only keeps the shallowest entry.
78 HttpAuthCache::Entry* HttpAuthCache::LookupByPath(const GURL& origin, 80 HttpAuthCache::Entry* HttpAuthCache::LookupByPath(const GURL& origin,
79 const std::string& path) { 81 const std::string& path) {
(...skipping 16 matching lines...) Expand all
96 98
97 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, 99 HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin,
98 HttpAuthHandler* handler, 100 HttpAuthHandler* handler,
99 const std::wstring& username, 101 const std::wstring& username,
100 const std::wstring& password, 102 const std::wstring& password,
101 const std::string& path) { 103 const std::string& path) {
102 CheckOriginIsValid(origin); 104 CheckOriginIsValid(origin);
103 CheckPathIsValid(path); 105 CheckPathIsValid(path);
104 106
105 // Check for existing entry (we will re-use it if present). 107 // Check for existing entry (we will re-use it if present).
106 HttpAuthCache::Entry* entry = LookupByRealm(origin, handler->realm()); 108 HttpAuthCache::Entry* entry = Lookup(origin, handler->realm(),
109 handler->scheme());
107 110
108 if (!entry) { 111 if (!entry) {
109 // Failsafe to prevent unbounded memory growth of the cache. 112 // Failsafe to prevent unbounded memory growth of the cache.
110 if (entries_.size() >= kMaxNumRealmEntries) { 113 if (entries_.size() >= kMaxNumRealmEntries) {
111 LOG(WARNING) << "Num auth cache entries reached limit -- evicting"; 114 LOG(WARNING) << "Num auth cache entries reached limit -- evicting";
112 entries_.pop_back(); 115 entries_.pop_back();
113 } 116 }
114 117
115 entries_.push_front(Entry()); 118 entries_.push_front(Entry());
116 entry = &entries_.front(); 119 entry = &entries_.front();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (PathList::const_iterator it = paths_.begin(); it != paths_.end(); 151 for (PathList::const_iterator it = paths_.begin(); it != paths_.end();
149 ++it) { 152 ++it) {
150 if (IsEnclosingPath(*it, dir)) 153 if (IsEnclosingPath(*it, dir))
151 return true; 154 return true;
152 } 155 }
153 return false; 156 return false;
154 } 157 }
155 158
156 bool HttpAuthCache::Remove(const GURL& origin, 159 bool HttpAuthCache::Remove(const GURL& origin,
157 const std::string& realm, 160 const std::string& realm,
161 const std::string& scheme,
158 const std::wstring& username, 162 const std::wstring& username,
159 const std::wstring& password) { 163 const std::wstring& password) {
160 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { 164 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) {
161 if (it->origin() == origin && it->realm() == realm) { 165 if (it->origin() == origin && it->realm() == realm &&
166 it->scheme() == scheme) {
162 if (username == it->username() && password == it->password()) { 167 if (username == it->username() && password == it->password()) {
163 entries_.erase(it); 168 entries_.erase(it);
164 return true; 169 return true;
165 } 170 }
166 return false; 171 return false;
167 } 172 }
168 } 173 }
169 return false; 174 return false;
170 } 175 }
171 176
172 } // namespace net 177 } // 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