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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 cookie_info.mac_key = cookie->MACKey(); | 352 cookie_info.mac_key = cookie->MACKey(); |
353 cookie_info.mac_algorithm = cookie->MACAlgorithm(); | 353 cookie_info.mac_algorithm = cookie->MACAlgorithm(); |
354 | 354 |
355 cookie_infos->push_back(cookie_info); | 355 cookie_infos->push_back(cookie_info); |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 } // namespace | 359 } // namespace |
360 | 360 |
361 // static | 361 // static |
362 bool CookieMonster::enable_file_scheme_ = false; | 362 bool CookieMonster::default_enable_file_scheme_ = false; |
363 | 363 |
364 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) | 364 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) |
365 : initialized_(false), | 365 : initialized_(false), |
366 loaded_(false), | 366 loaded_(false), |
367 store_(store), | 367 store_(store), |
368 last_access_threshold_( | 368 last_access_threshold_( |
369 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), | 369 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), |
370 delegate_(delegate), | 370 delegate_(delegate), |
371 last_statistic_record_time_(Time::Now()), | 371 last_statistic_record_time_(Time::Now()), |
372 keep_expired_cookies_(false), | 372 keep_expired_cookies_(false), |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1362 base::AutoLock autolock(lock_); | 1362 base::AutoLock autolock(lock_); |
1363 | 1363 |
1364 // Cookieable Schemes must be set before first use of function. | 1364 // Cookieable Schemes must be set before first use of function. |
1365 DCHECK(!initialized_); | 1365 DCHECK(!initialized_); |
1366 | 1366 |
1367 cookieable_schemes_.clear(); | 1367 cookieable_schemes_.clear(); |
1368 cookieable_schemes_.insert(cookieable_schemes_.end(), | 1368 cookieable_schemes_.insert(cookieable_schemes_.end(), |
1369 schemes, schemes + num_schemes); | 1369 schemes, schemes + num_schemes); |
1370 } | 1370 } |
1371 | 1371 |
1372 #if defined(OS_ANDROID) | |
1373 void CookieMonster::SetEnableFileScheme(bool accept) { | |
1374 // This assumes "file" is always at the end of the array. See the comment | |
1375 // above kDefaultCookieableSchemes. | |
1376 int num_schemes = accept ? kDefaultCookieableSchemesCount : | |
1377 kDefaultCookieableSchemesCount - 1; | |
1378 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | |
1379 } | |
1380 #endif // defined(OS_ANDROID) | |
1381 | |
1372 void CookieMonster::SetKeepExpiredCookies() { | 1382 void CookieMonster::SetKeepExpiredCookies() { |
1373 keep_expired_cookies_ = true; | 1383 keep_expired_cookies_ = true; |
1374 } | 1384 } |
1375 | 1385 |
1376 // static | 1386 // static |
1377 void CookieMonster::EnableFileScheme() { | 1387 void CookieMonster::EnableFileScheme() { |
1378 enable_file_scheme_ = true; | 1388 default_enable_file_scheme_ = true; |
1379 } | 1389 } |
1380 | 1390 |
1381 void CookieMonster::FlushStore(const base::Closure& callback) { | 1391 void CookieMonster::FlushStore(const base::Closure& callback) { |
1382 base::AutoLock autolock(lock_); | 1392 base::AutoLock autolock(lock_); |
1383 if (initialized_ && store_) | 1393 if (initialized_ && store_) |
1384 store_->Flush(callback); | 1394 store_->Flush(callback); |
1385 else if (!callback.is_null()) | 1395 else if (!callback.is_null()) |
1386 MessageLoop::current()->PostTask(FROM_HERE, callback); | 1396 MessageLoop::current()->PostTask(FROM_HERE, callback); |
1387 } | 1397 } |
1388 | 1398 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1734 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); | 1744 DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE); |
1735 } | 1745 } |
1736 } | 1746 } |
1737 DCHECK_EQ(num_duplicates, num_duplicates_found); | 1747 DCHECK_EQ(num_duplicates, num_duplicates_found); |
1738 | 1748 |
1739 return num_duplicates; | 1749 return num_duplicates; |
1740 } | 1750 } |
1741 | 1751 |
1742 // Note: file must be the last scheme. | 1752 // Note: file must be the last scheme. |
1743 const char* CookieMonster::kDefaultCookieableSchemes[] = | 1753 const char* CookieMonster::kDefaultCookieableSchemes[] = |
1744 { "http", "https", "file" }; | 1754 { "http", "https", "file" }; |
felipeg_google
2012/06/11 09:45:52
FYI: this is just a comment, address if you wish.
| |
1745 const int CookieMonster::kDefaultCookieableSchemesCount = | 1755 const int CookieMonster::kDefaultCookieableSchemesCount = |
1746 arraysize(CookieMonster::kDefaultCookieableSchemes); | 1756 arraysize(CookieMonster::kDefaultCookieableSchemes); |
1747 | 1757 |
1748 void CookieMonster::SetDefaultCookieableSchemes() { | 1758 void CookieMonster::SetDefaultCookieableSchemes() { |
1749 int num_schemes = enable_file_scheme_ ? | 1759 int num_schemes = default_enable_file_scheme_ ? |
1750 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; | 1760 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; |
1751 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); | 1761 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); |
1752 } | 1762 } |
1753 | 1763 |
1754 | 1764 |
1755 void CookieMonster::FindCookiesForHostAndDomain( | 1765 void CookieMonster::FindCookiesForHostAndDomain( |
1756 const GURL& url, | 1766 const GURL& url, |
1757 const CookieOptions& options, | 1767 const CookieOptions& options, |
1758 bool update_access_time, | 1768 bool update_access_time, |
1759 std::vector<CanonicalCookie*>* cookies) { | 1769 std::vector<CanonicalCookie*>* cookies) { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2160 std::string effective_domain( | 2170 std::string effective_domain( |
2161 RegistryControlledDomainService::GetDomainAndRegistry(domain)); | 2171 RegistryControlledDomainService::GetDomainAndRegistry(domain)); |
2162 if (effective_domain.empty()) | 2172 if (effective_domain.empty()) |
2163 effective_domain = domain; | 2173 effective_domain = domain; |
2164 | 2174 |
2165 if (!effective_domain.empty() && effective_domain[0] == '.') | 2175 if (!effective_domain.empty() && effective_domain[0] == '.') |
2166 return effective_domain.substr(1); | 2176 return effective_domain.substr(1); |
2167 return effective_domain; | 2177 return effective_domain; |
2168 } | 2178 } |
2169 | 2179 |
2180 #if defined(OS_ANDROID) | |
2181 bool CookieMonster::IsCookieableScheme(const std::string& scheme) { | |
2182 base::AutoLock autolock(lock_); | |
2183 | |
2184 return std::find(cookieable_schemes_.begin(), cookieable_schemes_.end(), | |
2185 scheme) != cookieable_schemes_.end(); | |
2186 } | |
2187 #endif // defined(OS_ANDROID) | |
2188 | |
2170 bool CookieMonster::HasCookieableScheme(const GURL& url) { | 2189 bool CookieMonster::HasCookieableScheme(const GURL& url) { |
2171 lock_.AssertAcquired(); | 2190 lock_.AssertAcquired(); |
2172 | 2191 |
2173 // Make sure the request is on a cookie-able url scheme. | 2192 // Make sure the request is on a cookie-able url scheme. |
2174 for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { | 2193 for (size_t i = 0; i < cookieable_schemes_.size(); ++i) { |
2175 // We matched a scheme. | 2194 // We matched a scheme. |
2176 if (url.SchemeIs(cookieable_schemes_[i].c_str())) { | 2195 if (url.SchemeIs(cookieable_schemes_[i].c_str())) { |
2177 // We've matched a supported scheme. | 2196 // We've matched a supported scheme. |
2178 return true; | 2197 return true; |
2179 } | 2198 } |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2840 std::string CookieMonster::CanonicalCookie::DebugString() const { | 2859 std::string CookieMonster::CanonicalCookie::DebugString() const { |
2841 return base::StringPrintf( | 2860 return base::StringPrintf( |
2842 "name: %s value: %s domain: %s path: %s creation: %" | 2861 "name: %s value: %s domain: %s path: %s creation: %" |
2843 PRId64, | 2862 PRId64, |
2844 name_.c_str(), value_.c_str(), | 2863 name_.c_str(), value_.c_str(), |
2845 domain_.c_str(), path_.c_str(), | 2864 domain_.c_str(), path_.c_str(), |
2846 static_cast<int64>(creation_date_.ToTimeT())); | 2865 static_cast<int64>(creation_date_.ToTimeT())); |
2847 } | 2866 } |
2848 | 2867 |
2849 } // namespace | 2868 } // namespace |
OLD | NEW |