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

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

Issue 3040016: Net: Convert username and password to string16. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address comments Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_auth.h ('k') | net/http/http_auth_cache.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) 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 #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 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
11 11
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/string16.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 // This is needed for the FRIEND_TEST() macro. 15 // This is needed for the FRIEND_TEST() macro.
15 #include "testing/gtest/include/gtest/gtest_prod.h" 16 #include "testing/gtest/include/gtest/gtest_prod.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // HttpAuthCache stores HTTP authentication identities and challenge info. 20 // HttpAuthCache stores HTTP authentication identities and challenge info.
20 // For each (origin, realm, scheme) triple the cache stores a 21 // For each (origin, realm, scheme) triple the cache stores a
21 // HttpAuthCache::Entry, which holds: 22 // HttpAuthCache::Entry, which holds:
22 // - the origin server {protocol scheme, host, port} 23 // - the origin server {protocol scheme, host, port}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // |scheme| - the authentication scheme for the challenge. 56 // |scheme| - the authentication scheme for the challenge.
56 // |username| - login information for the realm. 57 // |username| - login information for the realm.
57 // |password| - login information for the realm. 58 // |password| - login information for the realm.
58 // |path| - absolute path for a resource contained in the protection 59 // |path| - absolute path for a resource contained in the protection
59 // space; this will be added to the list of known paths. 60 // space; this will be added to the list of known paths.
60 // returns - the entry that was just added/updated. 61 // returns - the entry that was just added/updated.
61 Entry* Add(const GURL& origin, 62 Entry* Add(const GURL& origin,
62 const std::string& realm, 63 const std::string& realm,
63 const std::string& scheme, 64 const std::string& scheme,
64 const std::string& auth_challenge, 65 const std::string& auth_challenge,
65 const std::wstring& username, 66 const string16& username,
66 const std::wstring& password, 67 const string16& password,
67 const std::string& path); 68 const std::string& path);
68 69
69 // Remove entry on server |origin| for realm |realm| and scheme |scheme| 70 // Remove entry on server |origin| for realm |realm| and scheme |scheme|
70 // if one exists AND if the cached identity matches (|username|, |password|). 71 // if one exists AND if the cached identity matches (|username|, |password|).
71 // |origin| - the {scheme, host, port} of the server. 72 // |origin| - the {scheme, host, port} of the server.
72 // |realm| - case sensitive realm string. 73 // |realm| - case sensitive realm string.
73 // |scheme| - authentication scheme 74 // |scheme| - authentication scheme
74 // |username| - condition to match. 75 // |username| - condition to match.
75 // |password| - condition to match. 76 // |password| - condition to match.
76 // returns - true if an entry was removed. 77 // returns - true if an entry was removed.
77 bool Remove(const GURL& origin, 78 bool Remove(const GURL& origin,
78 const std::string& realm, 79 const std::string& realm,
79 const std::string& scheme, 80 const std::string& scheme,
80 const std::wstring& username, 81 const string16& username,
81 const std::wstring& password); 82 const string16& password);
82 83
83 // Prevent unbounded memory growth. These are safeguards for abuse; it is 84 // Prevent unbounded memory growth. These are safeguards for abuse; it is
84 // not expected that the limits will be reached in ordinary usage. 85 // not expected that the limits will be reached in ordinary usage.
85 // This also defines the worst-case lookup times (which grow linearly 86 // This also defines the worst-case lookup times (which grow linearly
86 // with number of elements in the cache). 87 // with number of elements in the cache).
87 enum { kMaxNumPathsPerRealmEntry = 10 }; 88 enum { kMaxNumPathsPerRealmEntry = 10 };
88 enum { kMaxNumRealmEntries = 10 }; 89 enum { kMaxNumRealmEntries = 10 };
89 90
90 private: 91 private:
91 typedef std::list<Entry> EntryList; 92 typedef std::list<Entry> EntryList;
(...skipping 16 matching lines...) Expand all
108 const std::string scheme() const { 109 const std::string scheme() const {
109 return scheme_; 110 return scheme_;
110 } 111 }
111 112
112 // The authentication challenge. 113 // The authentication challenge.
113 const std::string auth_challenge() const { 114 const std::string auth_challenge() const {
114 return auth_challenge_; 115 return auth_challenge_;
115 } 116 }
116 117
117 // The login username. 118 // The login username.
118 const std::wstring username() const { 119 const string16 username() const {
119 return username_; 120 return username_;
120 } 121 }
121 122
122 // The login password. 123 // The login password.
123 const std::wstring password() const { 124 const string16 password() const {
124 return password_; 125 return password_;
125 } 126 }
126 127
127 int IncrementNonceCount() { 128 int IncrementNonceCount() {
128 return ++nonce_count_; 129 return ++nonce_count_;
129 } 130 }
130 131
131 private: 132 private:
132 friend class HttpAuthCache; 133 friend class HttpAuthCache;
133 FRIEND_TEST(HttpAuthCacheTest, AddPath); 134 FRIEND_TEST(HttpAuthCacheTest, AddPath);
134 FRIEND_TEST(HttpAuthCacheTest, AddToExistingEntry); 135 FRIEND_TEST(HttpAuthCacheTest, AddToExistingEntry);
135 136
136 Entry() {} 137 Entry() {}
137 138
138 // Adds a path defining the realm's protection space. If the path is 139 // Adds a path defining the realm's protection space. If the path is
139 // already contained in the protection space, is a no-op. 140 // already contained in the protection space, is a no-op.
140 void AddPath(const std::string& path); 141 void AddPath(const std::string& path);
141 142
142 // Returns true if |dir| is contained within the realm's protection space. 143 // Returns true if |dir| is contained within the realm's protection space.
143 bool HasEnclosingPath(const std::string& dir); 144 bool HasEnclosingPath(const std::string& dir);
144 145
145 // |origin_| contains the {scheme, host, port} of the server. 146 // |origin_| contains the {scheme, host, port} of the server.
146 GURL origin_; 147 GURL origin_;
147 std::string realm_; 148 std::string realm_;
148 std::string scheme_; 149 std::string scheme_;
149 150
150 // Identity. 151 // Identity.
151 std::string auth_challenge_; 152 std::string auth_challenge_;
152 std::wstring username_; 153 string16 username_;
153 std::wstring password_; 154 string16 password_;
154 155
155 int nonce_count_; 156 int nonce_count_;
156 157
157 // List of paths that define the realm's protection space. 158 // List of paths that define the realm's protection space.
158 typedef std::list<std::string> PathList; 159 typedef std::list<std::string> PathList;
159 PathList paths_; 160 PathList paths_;
160 }; 161 };
161 162
162 } // namespace net 163 } // namespace net
163 164
164 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ 165 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_
OLDNEW
« no previous file with comments | « net/http/http_auth.h ('k') | net/http/http_auth_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698