summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browsing_data/browsing_data_cookie_helper.cc21
-rw-r--r--chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc20
2 files changed, 40 insertions, 1 deletions
diff --git a/chrome/browser/browsing_data/browsing_data_cookie_helper.cc b/chrome/browser/browsing_data/browsing_data_cookie_helper.cc
index b9efa43..88563a9 100644
--- a/chrome/browser/browsing_data/browsing_data_cookie_helper.cc
+++ b/chrome/browser/browsing_data/browsing_data_cookie_helper.cc
@@ -21,6 +21,10 @@
using content::BrowserThread;
+namespace {
+const char kGlobalCookieListURL[] = "chrome://cookielist";
+}
+
BrowsingDataCookieHelper::BrowsingDataCookieHelper(
net::URLRequestContextGetter* request_context_getter)
: is_fetching_(false),
@@ -223,8 +227,23 @@ net::CookieList* CannedBrowsingDataCookieHelper::GetCookiesFor(
void CannedBrowsingDataCookieHelper::AddCookie(
const GURL& frame_url,
const net::CanonicalCookie& cookie) {
+ // Storing cookies in separate cookie lists per frame origin makes the
+ // GetCookieCount method count a cookie multiple times if it is stored in
+ // multiple lists.
+ // E.g. let "example.com" be redirected to "www.example.com". A cookie set
+ // with the cookie string "A=B; Domain=.example.com" would be sent to both
+ // hosts. This means it would be stored in the separate cookie lists for both
+ // hosts ("example.com", "www.example.com"). The method GetCookieCount would
+ // count this cookie twice. To prevent this, we us a single global cookie
+ // list as a work-around to store all added cookies. Per frame URL cookie
+ // lists are currently not used. In the future they will be used for
+ // collecting cookies per origin in redirect chains.
+ // TODO(markusheintz): A) Change the GetCookiesCount method to prevent
+ // counting cookies multiple times if they are stored in multiple cookie
+ // lists. B) Replace the GetCookieFor method call below with:
+ // "GetCookiesFor(frame_url.GetOrigin());"
net::CookieList* cookie_list =
- GetCookiesFor(frame_url.GetOrigin());
+ GetCookiesFor(GURL(kGlobalCookieListURL));
DeleteMatchingCookie(cookie, cookie_list);
cookie_list->push_back(cookie);
}
diff --git a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
index 2b6d63a..0aaab16 100644
--- a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
+++ b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc
@@ -319,4 +319,24 @@ TEST_F(BrowsingDataCookieHelperTest, CannedDifferentFrames) {
base::Unretained(this)));
}
+TEST_F(BrowsingDataCookieHelperTest, CannedGetCookieCount) {
+ GURL frame1_url("http://www.google.com");
+ GURL frame2_url("http://www.google.de");
+ GURL request_url("http://res.google.com");
+ scoped_refptr<CannedBrowsingDataCookieHelper> helper(
+ new CannedBrowsingDataCookieHelper(
+ testing_profile_->GetRequestContext()));
+
+ EXPECT_EQ(0U, helper->GetCookieCount());
+ helper->AddChangedCookie(frame1_url, request_url, "a=1",
+ net::CookieOptions());
+ EXPECT_EQ(1U, helper->GetCookieCount());
+ helper->AddChangedCookie(frame1_url, request_url, "b=1",
+ net::CookieOptions());
+ EXPECT_EQ(2U, helper->GetCookieCount());
+ helper->AddChangedCookie(frame2_url, request_url, "a=2",
+ net::CookieOptions());
+ EXPECT_EQ(2U, helper->GetCookieCount());
+}
+
} // namespace