summaryrefslogtreecommitdiffstats
path: root/net/base/cookie_monster.cc
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 19:58:57 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 19:58:57 +0000
commita0b0d63b60bbc0675115317a0b08ee4183436787 (patch)
treebe1e255eac2d1e176af658d492bfcf2b28d30ae3 /net/base/cookie_monster.cc
parentb24586704bd0ab21ea365bd75eb6ab0ffc1e00ec (diff)
downloadchromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.zip
chromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.tar.gz
chromium_src-a0b0d63b60bbc0675115317a0b08ee4183436787.tar.bz2
Back out trunk r37998.
Modify CookiePolicy to work asynchronously This change will enable us to prompt the user before setting a cookie. While we only need to prompt before setting, we actually need to make both CanSetCookie and CanGetCookies asynchronous. This is necessary in order to preserve FIFO ordering since the value returned by GetCookies depends on the changes made to the cookie DB by SetCookie. This change also includes some simplification of CookieStore. Instead of N virtual functions, I distilled it down to only 4. The remaining functions are instead expressed in terms of those. While studying all the places where we currently use CookiePolicy, I found that some of them were not appropriate. After discussing with Amit, I decided to remove the policy checks in URLRequestAutomationJob. See the comments in the code regarding this. I changed the signature of CookieMonster::GetRawCookies to GetAllCookiesForURL to better match GetAllCookies. I also filed a bug about making it even closer in functionality. Related to this change webkit/glue/webcookie.h grows a constructor that takes a CanonicalCookie to help clean up some code. On the Chrome side, ChromeURLRequestContext now has a ChromeCookiePolicy object. That object is threadsafe ref counted because it is passed between the UI and IO threads. It is responsible for implementing the queuing logic described above. It will also in the future trigger the Chrome UI code to actually show the setcookie prompt. Please review the state machinery changes in URLRequestHttpJob carefully. R=eroman BUG=34331 TEST=no tests yet for prompting. Review URL: http://codereview.chromium.org/567015 TBR=darin@chromium.org Review URL: http://codereview.chromium.org/562037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/cookie_monster.cc')
-rw-r--r--net/base/cookie_monster.cc77
1 files changed, 59 insertions, 18 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 805bfc1..992191c 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -404,11 +404,44 @@ void CookieMonster::SetCookieableSchemes(
schemes, schemes + num_schemes);
}
-bool CookieMonster::SetCookieWithCreationTimeAndOptions(
- const GURL& url,
- const std::string& cookie_line,
- const Time& creation_time_or_null,
- const CookieOptions& options) {
+bool CookieMonster::SetCookie(const GURL& url,
+ const std::string& cookie_line) {
+ CookieOptions options;
+ return SetCookieWithOptions(url, cookie_line, options);
+}
+
+bool CookieMonster::SetCookieWithOptions(const GURL& url,
+ const std::string& cookie_line,
+ const CookieOptions& options) {
+ Time creation_date;
+ {
+ AutoLock autolock(lock_);
+ creation_date = CurrentTime();
+ last_time_seen_ = creation_date;
+ }
+ return SetCookieWithCreationTimeWithOptions(url,
+ cookie_line,
+ creation_date,
+ options);
+}
+
+bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
+ const std::string& cookie_line,
+ const Time& creation_time) {
+ CookieOptions options;
+ return SetCookieWithCreationTimeWithOptions(url,
+ cookie_line,
+ creation_time,
+ options);
+}
+
+bool CookieMonster::SetCookieWithCreationTimeWithOptions(
+ const GURL& url,
+ const std::string& cookie_line,
+ const Time& creation_time,
+ const CookieOptions& options) {
+ DCHECK(!creation_time.is_null());
+
if (!HasCookieableScheme(url)) {
return false;
}
@@ -418,12 +451,6 @@ bool CookieMonster::SetCookieWithCreationTimeAndOptions(
COOKIE_DLOG(INFO) << "SetCookie() line: " << cookie_line;
- Time creation_time = creation_time_or_null;
- if (creation_time.is_null()) {
- creation_time = CurrentTime();
- last_time_seen_ = creation_time;
- }
-
// Parse the cookie.
ParsedCookie pc(cookie_line);
@@ -481,6 +508,21 @@ bool CookieMonster::SetCookieWithCreationTimeAndOptions(
return true;
}
+void CookieMonster::SetCookies(const GURL& url,
+ const std::vector<std::string>& cookies) {
+ CookieOptions options;
+ SetCookiesWithOptions(url, cookies, options);
+}
+
+void CookieMonster::SetCookiesWithOptions(
+ const GURL& url,
+ const std::vector<std::string>& cookies,
+ const CookieOptions& options) {
+ for (std::vector<std::string>::const_iterator iter = cookies.begin();
+ iter != cookies.end(); ++iter)
+ SetCookieWithOptions(url, *iter, options);
+}
+
void CookieMonster::InternalInsertCookie(const std::string& key,
CanonicalCookie* cc,
bool sync_to_store) {
@@ -694,12 +736,6 @@ static bool CookieSorter(CookieMonster::CanonicalCookie* cc1,
return cc1->Path().length() > cc2->Path().length();
}
-bool CookieMonster::SetCookieWithOptions(const GURL& url,
- const std::string& cookie_line,
- const CookieOptions& options) {
- return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options);
-}
-
// Currently our cookie datastructure is based on Mozilla's approach. We have a
// hash keyed on the cookie's domain, and for any query we walk down the domain
// components and probe for cookies until we reach the TLD, where we stop.
@@ -712,6 +748,11 @@ bool CookieMonster::SetCookieWithOptions(const GURL& url,
// search/prefix trie, where we reverse the hostname and query for all
// keys that are a prefix of our hostname. I think the hash probing
// should be fast and simple enough for now.
+std::string CookieMonster::GetCookies(const GURL& url) {
+ CookieOptions options;
+ return GetCookiesWithOptions(url, options);
+}
+
std::string CookieMonster::GetCookiesWithOptions(const GURL& url,
const CookieOptions& options) {
if (!HasCookieableScheme(url)) {
@@ -793,7 +834,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookies() {
return cookie_list;
}
-CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) {
+CookieMonster::CookieList CookieMonster::GetRawCookies(const GURL& url) {
AutoLock autolock(lock_);
InitIfNecessary();