| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |