| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool operator() (const std::string& x) { | 52 bool operator() (const std::string& x) { |
| 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 HttpAuthCache::HttpAuthCache() { |
| 63 } |
| 64 |
| 65 HttpAuthCache::~HttpAuthCache() { |
| 66 } |
| 67 |
| 62 // Performance: O(n), where n is the number of realm entries. | 68 // Performance: O(n), where n is the number of realm entries. |
| 63 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, | 69 HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, |
| 64 const std::string& realm, | 70 const std::string& realm, |
| 65 const std::string& scheme) { | 71 const std::string& scheme) { |
| 66 CheckOriginIsValid(origin); | 72 CheckOriginIsValid(origin); |
| 67 | 73 |
| 68 // Linear scan through the realm entries. | 74 // Linear scan through the realm entries. |
| 69 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { | 75 for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { |
| 70 if (it->origin() == origin && it->realm() == realm && | 76 if (it->origin() == origin && it->realm() == realm && |
| 71 it->scheme() == scheme) | 77 it->scheme() == scheme) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 133 |
| 128 entry->auth_challenge_ = auth_challenge; | 134 entry->auth_challenge_ = auth_challenge; |
| 129 entry->username_ = username; | 135 entry->username_ = username; |
| 130 entry->password_ = password; | 136 entry->password_ = password; |
| 131 entry->nonce_count_ = 1; | 137 entry->nonce_count_ = 1; |
| 132 entry->AddPath(path); | 138 entry->AddPath(path); |
| 133 | 139 |
| 134 return entry; | 140 return entry; |
| 135 } | 141 } |
| 136 | 142 |
| 143 HttpAuthCache::Entry::~Entry() { |
| 144 } |
| 145 |
| 137 HttpAuthCache::Entry::Entry() | 146 HttpAuthCache::Entry::Entry() |
| 138 : nonce_count_(0) { | 147 : nonce_count_(0) { |
| 139 } | 148 } |
| 140 | 149 |
| 141 void HttpAuthCache::Entry::AddPath(const std::string& path) { | 150 void HttpAuthCache::Entry::AddPath(const std::string& path) { |
| 142 std::string parent_dir = GetParentDirectory(path); | 151 std::string parent_dir = GetParentDirectory(path); |
| 143 if (!HasEnclosingPath(parent_dir)) { | 152 if (!HasEnclosingPath(parent_dir)) { |
| 144 // Remove any entries that have been subsumed by the new entry. | 153 // Remove any entries that have been subsumed by the new entry. |
| 145 paths_.remove_if(IsEnclosedBy(parent_dir)); | 154 paths_.remove_if(IsEnclosedBy(parent_dir)); |
| 146 | 155 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const std::string& scheme, | 204 const std::string& scheme, |
| 196 const std::string& auth_challenge) { | 205 const std::string& auth_challenge) { |
| 197 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); | 206 HttpAuthCache::Entry* entry = Lookup(origin, realm, scheme); |
| 198 if (!entry) | 207 if (!entry) |
| 199 return false; | 208 return false; |
| 200 entry->UpdateStaleChallenge(auth_challenge); | 209 entry->UpdateStaleChallenge(auth_challenge); |
| 201 return true; | 210 return true; |
| 202 } | 211 } |
| 203 | 212 |
| 204 } // namespace net | 213 } // namespace net |
| OLD | NEW |