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 18 matching lines...) Expand all Loading... | |
136 entry->password_ = password; | 136 entry->password_ = password; |
137 entry->nonce_count_ = 1; | 137 entry->nonce_count_ = 1; |
138 entry->AddPath(path); | 138 entry->AddPath(path); |
139 | 139 |
140 return entry; | 140 return entry; |
141 } | 141 } |
142 | 142 |
143 HttpAuthCache::Entry::~Entry() { | 143 HttpAuthCache::Entry::~Entry() { |
144 } | 144 } |
145 | 145 |
146 HttpAuthCache::Entry::Entry() | 146 HttpAuthCache::Entry::Entry() |
eroman
2011/01/10 19:32:39
Please update this to default-initialize scheme_ t
| |
147 : nonce_count_(0) { | 147 : nonce_count_(0) { |
148 } | 148 } |
149 | 149 |
150 void HttpAuthCache::Entry::AddPath(const std::string& path) { | 150 void HttpAuthCache::Entry::AddPath(const std::string& path) { |
151 std::string parent_dir = GetParentDirectory(path); | 151 std::string parent_dir = GetParentDirectory(path); |
152 if (!HasEnclosingPath(parent_dir)) { | 152 if (!HasEnclosingPath(parent_dir)) { |
153 // Remove any entries that have been subsumed by the new entry. | 153 // Remove any entries that have been subsumed by the new entry. |
154 paths_.remove_if(IsEnclosedBy(parent_dir)); | 154 paths_.remove_if(IsEnclosedBy(parent_dir)); |
155 | 155 |
156 // Failsafe to prevent unbounded memory growth of the cache. | 156 // Failsafe to prevent unbounded memory growth of the cache. |
(...skipping 19 matching lines...) Expand all 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 |