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

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

Issue 2097043002: Clear HTTP auth data on clearing browsing data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace FRIEND_TEST_ALL_PREFIXES with set_creation_time_for_testing Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef NET_HTTP_HTTP_AUTH_CACHE_H_ 5 #ifndef NET_HTTP_HTTP_AUTH_CACHE_H_
6 #define NET_HTTP_HTTP_AUTH_CACHE_H_ 6 #define NET_HTTP_HTTP_AUTH_CACHE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <string> 11 #include <string>
12 12
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 #include "net/http/http_auth.h" 17 #include "net/http/http_auth.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 // HttpAuthCache stores HTTP authentication identities and challenge info. 22 // HttpAuthCache stores HTTP authentication identities and challenge info.
23 // For each (origin, realm, scheme) triple the cache stores a 23 // For each (origin, realm, scheme) triple the cache stores a
24 // HttpAuthCache::Entry, which holds: 24 // HttpAuthCache::Entry, which holds:
25 // - the origin server {protocol scheme, host, port} 25 // - the origin server {protocol scheme, host, port}
26 // - the last identity used (username/password) 26 // - the last identity used (username/password)
27 // - the last auth handler used (contains realm and authentication scheme) 27 // - the last auth handler used (contains realm and authentication scheme)
28 // - the list of paths which used this realm 28 // - the list of paths which used this realm
29 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). 29 // Entries can be looked up by either (origin, realm, scheme) or (origin, path).
30 class NET_EXPORT_PRIVATE HttpAuthCache { 30 class NET_EXPORT HttpAuthCache {
31 public: 31 public:
32 class NET_EXPORT_PRIVATE Entry { 32 class NET_EXPORT Entry {
33 public: 33 public:
34 Entry(const Entry& other); 34 Entry(const Entry& other);
35 ~Entry(); 35 ~Entry();
36 36
37 const GURL& origin() const { 37 const GURL& origin() const {
38 return origin_; 38 return origin_;
39 } 39 }
40 40
41 // The case-sensitive realm string of the challenge. 41 // The case-sensitive realm string of the challenge.
42 const std::string& realm() const { return realm_; } 42 const std::string& realm() const { return realm_; }
(...skipping 10 matching lines...) Expand all
53 const AuthCredentials& credentials() const { 53 const AuthCredentials& credentials() const {
54 return credentials_; 54 return credentials_;
55 } 55 }
56 56
57 int IncrementNonceCount() { 57 int IncrementNonceCount() {
58 return ++nonce_count_; 58 return ++nonce_count_;
59 } 59 }
60 60
61 void UpdateStaleChallenge(const std::string& auth_challenge); 61 void UpdateStaleChallenge(const std::string& auth_challenge);
62 62
63 void set_creation_time_for_testing(base::TimeTicks creation_time) {
64 creation_time_ = creation_time;
65 }
66
63 private: 67 private:
64 friend class HttpAuthCache; 68 friend class HttpAuthCache;
65 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath); 69 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath);
66 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry); 70 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry);
67 71
68 typedef std::list<std::string> PathList; 72 typedef std::list<std::string> PathList;
69 73
70 Entry(); 74 Entry();
71 75
72 // Adds a path defining the realm's protection space. If the path is 76 // Adds a path defining the realm's protection space. If the path is
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // |origin| - the {scheme, host, port} of the server. 159 // |origin| - the {scheme, host, port} of the server.
156 // |realm| - case sensitive realm string. 160 // |realm| - case sensitive realm string.
157 // |scheme| - the authentication scheme (i.e. basic, negotiate). 161 // |scheme| - the authentication scheme (i.e. basic, negotiate).
158 // |credentials| - the credentials to match. 162 // |credentials| - the credentials to match.
159 // returns - true if an entry was removed. 163 // returns - true if an entry was removed.
160 bool Remove(const GURL& origin, 164 bool Remove(const GURL& origin,
161 const std::string& realm, 165 const std::string& realm,
162 HttpAuth::Scheme scheme, 166 HttpAuth::Scheme scheme,
163 const AuthCredentials& credentials); 167 const AuthCredentials& credentials);
164 168
165 // Clears the cache. 169 // Clears cache entries created within |duration| of base::TimeTicks::Now().
166 void Clear(); 170 void ClearEntriesAddedWithin(base::TimeDelta duration);
167 171
168 // Updates a stale digest entry on server |origin| for realm |realm| and 172 // Updates a stale digest entry on server |origin| for realm |realm| and
169 // scheme |scheme|. The cached auth challenge is replaced with 173 // scheme |scheme|. The cached auth challenge is replaced with
170 // |auth_challenge| and the nonce count is reset. 174 // |auth_challenge| and the nonce count is reset.
171 // |UpdateStaleChallenge()| returns true if a matching entry exists in the 175 // |UpdateStaleChallenge()| returns true if a matching entry exists in the
172 // cache, false otherwise. 176 // cache, false otherwise.
173 bool UpdateStaleChallenge(const GURL& origin, 177 bool UpdateStaleChallenge(const GURL& origin,
174 const std::string& realm, 178 const std::string& realm,
175 HttpAuth::Scheme scheme, 179 HttpAuth::Scheme scheme,
176 const std::string& auth_challenge); 180 const std::string& auth_challenge);
177 181
178 // Copies all entries from |other| cache. 182 // Copies all entries from |other| cache.
179 void UpdateAllFrom(const HttpAuthCache& other); 183 void UpdateAllFrom(const HttpAuthCache& other);
180 184
181 private: 185 private:
182 typedef std::list<Entry> EntryList; 186 typedef std::list<Entry> EntryList;
183 EntryList entries_; 187 EntryList entries_;
184 }; 188 };
185 189
186 // An authentication realm entry. 190 // An authentication realm entry.
187 } // namespace net 191 } // namespace net
188 192
189 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ 193 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | net/http/http_auth_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698