OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
6 | 6 |
7 #include "utility" | 7 #include "utility" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 109 } |
110 | 110 |
111 CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() { | 111 CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() { |
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
113 CannedBrowsingDataCookieHelper* clone = | 113 CannedBrowsingDataCookieHelper* clone = |
114 new CannedBrowsingDataCookieHelper(request_context_getter()); | 114 new CannedBrowsingDataCookieHelper(request_context_getter()); |
115 | 115 |
116 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin(); | 116 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin(); |
117 it != origin_cookie_list_map_.end(); | 117 it != origin_cookie_list_map_.end(); |
118 ++it) { | 118 ++it) { |
119 net::CookieList* cookies = clone->GetCookiesFor(it->first); | 119 net::CookieHashSet* cookies = clone->GetCookiesFor(it->first); |
120 cookies->insert(cookies->begin(), it->second->begin(), it->second->end()); | 120 cookies->insert(it->second->begin(), it->second->end()); |
121 } | 121 } |
122 return clone; | 122 return clone; |
123 } | 123 } |
124 | 124 |
125 void CannedBrowsingDataCookieHelper::AddReadCookies( | 125 void CannedBrowsingDataCookieHelper::AddReadCookies( |
126 const GURL& frame_url, | 126 const GURL& frame_url, |
127 const GURL& url, | 127 const GURL& url, |
128 const net::CookieList& cookie_list) { | 128 const net::CookieList& cookie_list) { |
129 typedef net::CookieList::const_iterator cookie_iterator; | 129 typedef net::CookieList::const_iterator cookie_iterator; |
130 for (cookie_iterator add_cookie = cookie_list.begin(); | 130 for (cookie_iterator add_cookie = cookie_list.begin(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin(); | 192 for (OriginCookieListMap::iterator it = origin_cookie_list_map_.begin(); |
193 it != origin_cookie_list_map_.end(); | 193 it != origin_cookie_list_map_.end(); |
194 ++it) { | 194 ++it) { |
195 DeleteMatchingCookie(cookie, it->second); | 195 DeleteMatchingCookie(cookie, it->second); |
196 } | 196 } |
197 BrowsingDataCookieHelper::DeleteCookie(cookie); | 197 BrowsingDataCookieHelper::DeleteCookie(cookie); |
198 } | 198 } |
199 | 199 |
200 bool CannedBrowsingDataCookieHelper::DeleteMatchingCookie( | 200 bool CannedBrowsingDataCookieHelper::DeleteMatchingCookie( |
201 const net::CanonicalCookie& add_cookie, | 201 const net::CanonicalCookie& add_cookie, |
202 net::CookieList* cookie_list) { | 202 net::CookieHashSet* cookie_list) { |
203 typedef net::CookieList::iterator cookie_iterator; | 203 return cookie_list->erase(add_cookie) > 0; |
204 for (cookie_iterator cookie = cookie_list->begin(); | |
205 cookie != cookie_list->end(); ++cookie) { | |
206 if (cookie->Name() == add_cookie.Name() && | |
207 cookie->Domain() == add_cookie.Domain()&& | |
208 cookie->Path() == add_cookie.Path()) { | |
209 cookie_list->erase(cookie); | |
210 return true; | |
211 } | |
212 } | |
213 return false; | |
214 } | 204 } |
215 | 205 |
216 net::CookieList* CannedBrowsingDataCookieHelper::GetCookiesFor( | 206 net::CookieHashSet* CannedBrowsingDataCookieHelper::GetCookiesFor( |
217 const GURL& first_party_origin) { | 207 const GURL& first_party_origin) { |
218 OriginCookieListMap::iterator it = | 208 OriginCookieListMap::iterator it = |
219 origin_cookie_list_map_.find(first_party_origin); | 209 origin_cookie_list_map_.find(first_party_origin); |
220 if (it == origin_cookie_list_map_.end()) { | 210 if (it == origin_cookie_list_map_.end()) { |
221 net::CookieList* cookies = new net::CookieList(); | 211 net::CookieHashSet* cookies = new net::CookieHashSet; |
222 origin_cookie_list_map_.insert( | 212 origin_cookie_list_map_.insert( |
223 std::pair<GURL, net::CookieList*>(first_party_origin, cookies)); | 213 std::pair<GURL, net::CookieHashSet*>(first_party_origin, cookies)); |
224 return cookies; | 214 return cookies; |
225 } | 215 } |
226 return it->second; | 216 return it->second; |
227 } | 217 } |
228 | 218 |
229 void CannedBrowsingDataCookieHelper::AddCookie( | 219 void CannedBrowsingDataCookieHelper::AddCookie( |
230 const GURL& frame_url, | 220 const GURL& frame_url, |
231 const net::CanonicalCookie& cookie) { | 221 const net::CanonicalCookie& cookie) { |
232 // Storing cookies in separate cookie lists per frame origin makes the | 222 // Storing cookies in separate cookie lists per frame origin makes the |
233 // GetCookieCount method count a cookie multiple times if it is stored in | 223 // GetCookieCount method count a cookie multiple times if it is stored in |
234 // multiple lists. | 224 // multiple lists. |
235 // E.g. let "example.com" be redirected to "www.example.com". A cookie set | 225 // E.g. let "example.com" be redirected to "www.example.com". A cookie set |
236 // with the cookie string "A=B; Domain=.example.com" would be sent to both | 226 // with the cookie string "A=B; Domain=.example.com" would be sent to both |
237 // hosts. This means it would be stored in the separate cookie lists for both | 227 // hosts. This means it would be stored in the separate cookie lists for both |
238 // hosts ("example.com", "www.example.com"). The method GetCookieCount would | 228 // hosts ("example.com", "www.example.com"). The method GetCookieCount would |
239 // count this cookie twice. To prevent this, we us a single global cookie | 229 // count this cookie twice. To prevent this, we us a single global cookie |
240 // list as a work-around to store all added cookies. Per frame URL cookie | 230 // list as a work-around to store all added cookies. Per frame URL cookie |
241 // lists are currently not used. In the future they will be used for | 231 // lists are currently not used. In the future they will be used for |
242 // collecting cookies per origin in redirect chains. | 232 // collecting cookies per origin in redirect chains. |
243 // TODO(markusheintz): A) Change the GetCookiesCount method to prevent | 233 // TODO(markusheintz): A) Change the GetCookiesCount method to prevent |
244 // counting cookies multiple times if they are stored in multiple cookie | 234 // counting cookies multiple times if they are stored in multiple cookie |
245 // lists. B) Replace the GetCookieFor method call below with: | 235 // lists. B) Replace the GetCookieFor method call below with: |
246 // "GetCookiesFor(frame_url.GetOrigin());" | 236 // "GetCookiesFor(frame_url.GetOrigin());" |
247 net::CookieList* cookie_list = | 237 if (origin_cookie_url_.is_empty()) |
248 GetCookiesFor(GURL(kGlobalCookieListURL)); | 238 origin_cookie_url_ = GURL(kGlobalCookieListURL); |
239 net::CookieHashSet* cookie_list = GetCookiesFor(origin_cookie_url_); | |
Avi (use Gerrit)
2014/08/07 23:50:37
Or...
static const GURL origin_cookie_url(kGlobal
erikchen
2014/08/08 00:35:27
Done.
| |
249 DeleteMatchingCookie(cookie, cookie_list); | 240 DeleteMatchingCookie(cookie, cookie_list); |
250 cookie_list->push_back(cookie); | 241 cookie_list->insert(cookie); |
251 } | 242 } |
OLD | NEW |