diff options
author | rdsmith@google.com <rdsmith@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 15:29:57 +0000 |
---|---|---|
committer | rdsmith@google.com <rdsmith@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 15:29:57 +0000 |
commit | 65781e9b7461c629639f5b9bff4f886b8b033a2b (patch) | |
tree | c355e78666be88f0799791f5b30dafedf028da43 | |
parent | 7008ab600398f8dd3be89fe9fa65074525d19666 (diff) | |
download | chromium_src-65781e9b7461c629639f5b9bff4f886b8b033a2b.zip chromium_src-65781e9b7461c629639f5b9bff4f886b8b033a2b.tar.gz chromium_src-65781e9b7461c629639f5b9bff4f886b8b033a2b.tar.bz2 |
Changed type CookieList to being a vector CanonicalCookies.
Originally, it was a vector of pair<domain_string, CanonicalCookie>.
TEST=Refactor; all relevant unit tests should still pass.
BUG=8850
Review URL: http://codereview.chromium.org/2799057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53184 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 139 insertions, 157 deletions
diff --git a/chrome/browser/cocoa/cookie_details.mm b/chrome/browser/cocoa/cookie_details.mm index 49f4157..7d625b2 100644 --- a/chrome/browser/cocoa/cookie_details.mm +++ b/chrome/browser/cocoa/cookie_details.mm @@ -239,7 +239,7 @@ CookieTreeNode::DetailedInfo::NodeType nodeType = info.node_type; if (nodeType == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { NSString* origin = base::SysWideToNSString(info.origin.c_str()); - return [[[CocoaCookieDetails alloc] initWithCookie:&(info.cookie->second) + return [[[CocoaCookieDetails alloc] initWithCookie:info.cookie origin:origin canEditExpiration:NO] autorelease]; } else if (nodeType == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 4f24adf..d4d577b 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -48,8 +48,8 @@ CookiesTreeModel* CookieTreeNode::GetModel() const { // CookieTreeCookieNode, public: CookieTreeCookieNode::CookieTreeCookieNode( - net::CookieMonster::CookieListPair* cookie) - : CookieTreeNode(UTF8ToWide(cookie->second.Name())), + net::CookieMonster::CanonicalCookie* cookie) + : CookieTreeNode(UTF8ToWide(cookie->Name())), cookie_(cookie) { } @@ -62,7 +62,7 @@ void CookieTreeCookieNode::DeleteStoredObjects() { // invalidate our pointers), and the fact that it contains semi out-of-date // data is not problematic as we don't re-build the model based on that. GetModel()->cookie_monster_-> - DeleteCookie(cookie_->first, cookie_->second, true); + DeleteCookie(cookie_->Domain(), *cookie_, true); } namespace { @@ -401,9 +401,9 @@ void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); for (CookieList::iterator it = all_cookies_.begin(); it != all_cookies_.end(); ++it) { - std::string origin_host = it->first; + std::string origin_host = it->Domain(); if (origin_host.length() > 1 && origin_host[0] == '.') - origin_host = it->first.substr(1); + origin_host = it->Domain().substr(1); // We treat secure cookies just the same as normal ones. GURL origin(std::string(chrome::kHttpScheme) + chrome::kStandardSchemeSeparator + origin_host + "/"); diff --git a/chrome/browser/cookies_tree_model.h b/chrome/browser/cookies_tree_model.h index 7e6675a..435b532 100644 --- a/chrome/browser/cookies_tree_model.h +++ b/chrome/browser/cookies_tree_model.h @@ -52,7 +52,7 @@ class CookieTreeNode : public TreeNode<CookieTreeNode> { }; DetailedInfo(const std::wstring& origin, NodeType node_type, - const net::CookieMonster::CookieListPair* cookie, + const net::CookieMonster::CanonicalCookie* cookie, const BrowsingDataDatabaseHelper::DatabaseInfo* database_info, const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info, @@ -70,7 +70,7 @@ class CookieTreeNode : public TreeNode<CookieTreeNode> { std::wstring origin; NodeType node_type; - const net::CookieMonster::CookieListPair* cookie; + const net::CookieMonster::CanonicalCookie* cookie; const BrowsingDataDatabaseHelper::DatabaseInfo* database_info; const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info; const appcache::AppCacheInfo* appcache_info; @@ -180,7 +180,7 @@ class CookieTreeCookieNode : public CookieTreeNode { // Does not take ownership of cookie, and cookie should remain valid at least // as long as the CookieTreeCookieNode is valid. - explicit CookieTreeCookieNode(net::CookieMonster::CookieListPair* cookie); + explicit CookieTreeCookieNode(net::CookieMonster::CanonicalCookie* cookie); virtual ~CookieTreeCookieNode() {} // CookieTreeNode methods: @@ -193,7 +193,7 @@ class CookieTreeCookieNode : public CookieTreeNode { private: // Cookie_ is not owned by the node, and is expected to remain valid as long // as the CookieTreeCookieNode is valid. - net::CookieMonster::CookieListPair* cookie_; + net::CookieMonster::CanonicalCookie* cookie_; DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode); }; @@ -404,7 +404,6 @@ class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { DATABASE = 2 }; typedef net::CookieMonster::CookieList CookieList; - typedef std::vector<net::CookieMonster::CookieListPair*> CookiePtrList; typedef std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> DatabaseInfoList; typedef std::vector<BrowsingDataLocalStorageHelper::LocalStorageInfo> diff --git a/chrome/browser/cookies_tree_model_unittest.cc b/chrome/browser/cookies_tree_model_unittest.cc index ff0f777..793a9ac 100644 --- a/chrome/browser/cookies_tree_model_unittest.cc +++ b/chrome/browser/cookies_tree_model_unittest.cc @@ -100,7 +100,7 @@ class CookiesTreeModelTest : public testing::Test { std::vector<std::string> parts; net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); for (size_t i = 0; i < cookie_list.size(); ++i) - parts.push_back(cookie_list[i].second.Name()); + parts.push_back(cookie_list[i].Name()); return JoinString(parts, ','); } @@ -121,7 +121,7 @@ class CookiesTreeModelTest : public testing::Test { case CookieTreeNode::DetailedInfo::TYPE_DATABASE: return node->GetDetailedInfo().database_info->database_name + ","; case CookieTreeNode::DetailedInfo::TYPE_COOKIE: - return node->GetDetailedInfo().cookie->second.Name() + ","; + return node->GetDetailedInfo().cookie->Name() + ","; case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: return node->GetDetailedInfo().appcache_info->manifest_url.spec() + ","; diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc index c20d1eb..096059d 100644 --- a/chrome/browser/extensions/extension_cookies_api.cc +++ b/chrome/browser/extensions/extension_cookies_api.cc @@ -58,14 +58,14 @@ void ExtensionCookiesEventRouter::CookieChanged( dict->SetBoolean(keys::kRemovedKey, details->removed); dict->Set( keys::kCookieKey, - extension_cookies_helpers::CreateCookieValue(*details->cookie_pair, + extension_cookies_helpers::CreateCookieValue(*details->cookie, extension_cookies_helpers::GetStoreIdFromProfile(profile))); args.Append(dict); std::string json_args; base::JSONWriter::Write(&args, false, &json_args); GURL cookie_domain = - extension_cookies_helpers::GetURLFromCookiePair(*details->cookie_pair); + extension_cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); DispatchEvent(profile, keys::kOnChanged, json_args, cookie_domain); } @@ -191,8 +191,7 @@ void GetCookieFunction::RespondOnUIThread() { for (it = cookie_list_.begin(); it != cookie_list_.end(); ++it) { // Return the first matching cookie. Relies on the fact that the // CookieMonster retrieves them in reverse domain-length order. - const net::CookieMonster::CanonicalCookie& cookie = it->second; - if (cookie.Name() == name_) { + if (it->Name() == name_) { result_.reset( extension_cookies_helpers::CreateCookieValue(*it, store_id_)); break; @@ -251,7 +250,8 @@ void GetAllCookiesFunction::RespondOnUIThread() { if (extension) { ListValue* matching_list = new ListValue(); extension_cookies_helpers::AppendMatchingCookiesToList( - cookie_list_, store_id_, url_, details_, GetExtension(), matching_list); + cookie_list_, store_id_, url_, details_, + GetExtension(), matching_list); result_.reset(matching_list); } SendResponse(true); diff --git a/chrome/browser/extensions/extension_cookies_helpers.cc b/chrome/browser/extensions/extension_cookies_helpers.cc index 903e89e..2322c1d 100644 --- a/chrome/browser/extensions/extension_cookies_helpers.cc +++ b/chrome/browser/extensions/extension_cookies_helpers.cc @@ -40,16 +40,15 @@ const char* GetStoreIdFromProfile(Profile* profile) { } DictionaryValue* CreateCookieValue( - const net::CookieMonster::CookieListPair& cookie_pair, + const net::CookieMonster::CanonicalCookie& cookie, const std::string& store_id) { DictionaryValue* result = new DictionaryValue(); - const net::CookieMonster::CanonicalCookie& cookie = cookie_pair.second; result->SetString(keys::kNameKey, cookie.Name()); result->SetString(keys::kValueKey, cookie.Value()); - result->SetString(keys::kDomainKey, cookie_pair.first); + result->SetString(keys::kDomainKey, cookie.Domain()); result->SetBoolean(keys::kHostOnlyKey, - net::CookieMonster::DomainIsHostOnly(cookie_pair.first)); + net::CookieMonster::DomainIsHostOnly(cookie.Domain())); result->SetString(keys::kPathKey, cookie.Path()); result->SetBoolean(keys::kSecureKey, cookie.IsSecure()); result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly()); @@ -82,10 +81,9 @@ net::CookieMonster::CookieList GetCookieListFromStore( return monster->GetAllCookies(); } -GURL GetURLFromCookiePair( - const net::CookieMonster::CookieListPair& cookie_pair) { - const std::string& domain_key = cookie_pair.first; - const net::CookieMonster::CanonicalCookie& cookie = cookie_pair.second; +GURL GetURLFromCanonicalCookie( + const net::CookieMonster::CanonicalCookie& cookie) { + const std::string& domain_key = cookie.Domain(); const std::string scheme = cookie.IsSecure() ? chrome::kHttpsScheme : chrome::kHttpScheme; const std::string host = @@ -103,7 +101,7 @@ void AppendMatchingCookiesToList( for (it = all_cookies.begin(); it != all_cookies.end(); ++it) { // Ignore any cookie whose domain doesn't match the extension's // host permissions. - GURL cookie_domain_url = GetURLFromCookiePair(*it); + GURL cookie_domain_url = GetURLFromCanonicalCookie(*it); if (!extension->HasHostPermission(cookie_domain_url)) continue; // Filter the cookie using the match filter. @@ -129,11 +127,10 @@ MatchFilter::MatchFilter(const DictionaryValue* details) } bool MatchFilter::MatchesCookie( - const net::CookieMonster::CookieListPair& cookie_pair) { - const net::CookieMonster::CanonicalCookie& cookie = cookie_pair.second; + const net::CookieMonster::CanonicalCookie& cookie) { return MatchesString(keys::kNameKey, cookie.Name()) && - MatchesDomain(cookie_pair.first) && + MatchesDomain(cookie.Domain()) && MatchesString(keys::kPathKey, cookie.Path()) && MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) && MatchesBoolean(keys::kSessionKey, !cookie.DoesExpire()); diff --git a/chrome/browser/extensions/extension_cookies_helpers.h b/chrome/browser/extensions/extension_cookies_helpers.h index 77284c6..a06621f 100644 --- a/chrome/browser/extensions/extension_cookies_helpers.h +++ b/chrome/browser/extensions/extension_cookies_helpers.h @@ -35,7 +35,7 @@ const char* GetStoreIdFromProfile(Profile* profile); // allocates a new DictionaryValue object; the caller is responsible for // freeing it. DictionaryValue* CreateCookieValue( - const net::CookieMonster::CookieListPair& cookie_pair, + const net::CookieMonster::CanonicalCookie& cookie, const std::string& store_id); // Constructs a CookieStore object as defined by the cookies API. This function @@ -54,8 +54,8 @@ net::CookieMonster::CookieList GetCookieListFromStore( // a cookie against the extension's host permissions. The Secure // property of the cookie defines the URL scheme, and the cookie's // domain becomes the URL host. -GURL GetURLFromCookiePair( - const net::CookieMonster::CookieListPair& cookie_pair); +GURL GetURLFromCanonicalCookie( + const net::CookieMonster::CanonicalCookie& cookie); // Looks through all cookies in the given cookie store, and appends to the // match list all the cookies that both match the given URL and cookie details @@ -86,7 +86,7 @@ class MatchFilter { // Returns true if the given cookie matches the properties in the match // filter. - bool MatchesCookie(const net::CookieMonster::CookieListPair& cookie_pair); + bool MatchesCookie(const net::CookieMonster::CanonicalCookie& cookie); private: // Returns true if the details dictionary contains a string with the given diff --git a/chrome/browser/extensions/extension_cookies_unittest.cc b/chrome/browser/extensions/extension_cookies_unittest.cc index 0f746f2..fbc1fdc 100644 --- a/chrome/browser/extensions/extension_cookies_unittest.cc +++ b/chrome/browser/extensions/extension_cookies_unittest.cc @@ -104,10 +104,9 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { net::CookieMonster::CanonicalCookie cookie1( "ABC", "DEF", "www.foobar.com", "/", false, false, base::Time(), base::Time(), false, base::Time()); - net::CookieMonster::CookieListPair cookie_pair1("www.foobar.com", cookie1); scoped_ptr<DictionaryValue> cookie_value1( extension_cookies_helpers::CreateCookieValue( - cookie_pair1, "some cookie store")); + cookie1, "some cookie store")); EXPECT_TRUE(cookie_value1->GetString(keys::kNameKey, &string_value)); EXPECT_EQ("ABC", string_value); EXPECT_TRUE(cookie_value1->GetString(keys::kValueKey, &string_value)); @@ -132,10 +131,9 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { net::CookieMonster::CanonicalCookie cookie2( "ABC", "DEF", ".foobar.com", "/", false, false, base::Time(), base::Time(), true, base::Time::FromDoubleT(10000)); - net::CookieMonster::CookieListPair cookie_pair2(".foobar.com", cookie2); scoped_ptr<DictionaryValue> cookie_value2( extension_cookies_helpers::CreateCookieValue( - cookie_pair2, "some cookie store")); + cookie2, "some cookie store")); EXPECT_TRUE(cookie_value2->GetBoolean(keys::kHostOnlyKey, &boolean_value)); EXPECT_EQ(false, boolean_value); EXPECT_TRUE(cookie_value2->GetBoolean(keys::kSessionKey, &boolean_value)); @@ -153,22 +151,20 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { EXPECT_EQ(tab_ids, value); } -TEST_F(ExtensionCookiesTest, GetURLFromCookiePair) { +TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) { net::CookieMonster::CanonicalCookie cookie1( "ABC", "DEF", "www.foobar.com", "/", false, false, base::Time(), base::Time(), false, base::Time()); - net::CookieMonster::CookieListPair cookie_pair1("www.foobar.com", cookie1); EXPECT_EQ("http://www.foobar.com/", - extension_cookies_helpers::GetURLFromCookiePair( - cookie_pair1).spec()); + extension_cookies_helpers::GetURLFromCanonicalCookie( + cookie1).spec()); net::CookieMonster::CanonicalCookie cookie2( "ABC", "DEF", ".helloworld.com", "/", true, false, base::Time(), base::Time(), false, base::Time()); - net::CookieMonster::CookieListPair cookie_pair2(".helloworld.com", cookie2); EXPECT_EQ("https://helloworld.com/", - extension_cookies_helpers::GetURLFromCookiePair( - cookie_pair2).spec()); + extension_cookies_helpers::GetURLFromCanonicalCookie( + cookie2).spec()); } TEST_F(ExtensionCookiesTest, EmptyDictionary) { @@ -176,9 +172,8 @@ TEST_F(ExtensionCookiesTest, EmptyDictionary) { extension_cookies_helpers::MatchFilter filter(details.get()); std::string domain; net::CookieMonster::CanonicalCookie cookie; - net::CookieMonster::CookieListPair cookie_pair(domain, cookie); - EXPECT_TRUE(filter.MatchesCookie(cookie_pair)); + EXPECT_TRUE(filter.MatchesCookie(cookie)); } TEST_F(ExtensionCookiesTest, DomainMatching) { @@ -193,11 +188,14 @@ TEST_F(ExtensionCookiesTest, DomainMatching) { }; scoped_ptr<DictionaryValue> details(new DictionaryValue()); - net::CookieMonster::CanonicalCookie cookie; for (size_t i = 0; i < arraysize(tests); ++i) { details->SetString(keys::kDomainKey, std::string(tests[i].filter)); extension_cookies_helpers::MatchFilter filter(details.get()); - net::CookieMonster::CookieListPair cookie_pair(tests[i].domain, cookie); - EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie_pair)); + net::CookieMonster::CanonicalCookie cookie("", "", tests[i].domain, + "", false, false, + base::Time(), + base::Time(), + false, base::Time()); + EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie)); } } diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc index bc171d2..b32f664 100644 --- a/chrome/browser/gtk/options/cookies_view.cc +++ b/chrome/browser/gtk/options/cookies_view.cc @@ -252,8 +252,8 @@ void CookiesView::EnableControls() { if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { gtk_chrome_cookie_view_display_cookie( GTK_CHROME_COOKIE_VIEW(cookie_display_), - detailed_info.cookie->first, - detailed_info.cookie->second); + detailed_info.cookie->Domain(), + *detailed_info.cookie); } else if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { gtk_chrome_cookie_view_display_database( diff --git a/chrome/browser/gtk/options/cookies_view_unittest.cc b/chrome/browser/gtk/options/cookies_view_unittest.cc index 8205032..903fe25 100644 --- a/chrome/browser/gtk/options/cookies_view_unittest.cc +++ b/chrome/browser/gtk/options/cookies_view_unittest.cc @@ -96,7 +96,7 @@ class CookiesViewTest : public testing::Test { std::vector<std::string> parts; net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); for (size_t i = 0; i < cookie_list.size(); ++i) - parts.push_back(cookie_list[i].second.Name()); + parts.push_back(cookie_list[i].Name()); return JoinString(parts, ','); } diff --git a/chrome/browser/net/chrome_cookie_notification_details.h b/chrome/browser/net/chrome_cookie_notification_details.h index a4ee4a0..e7b71dd 100644 --- a/chrome/browser/net/chrome_cookie_notification_details.h +++ b/chrome/browser/net/chrome_cookie_notification_details.h @@ -9,13 +9,13 @@ struct ChromeCookieDetails { public: - ChromeCookieDetails(net::CookieMonster::CookieListPair* cookie_pair_copy, + ChromeCookieDetails(net::CookieMonster::CanonicalCookie* cookie_copy, bool is_removed) - : cookie_pair(cookie_pair_copy), + : cookie(cookie_copy), removed(is_removed) { } - net::CookieMonster::CookieListPair* cookie_pair; + net::CookieMonster::CanonicalCookie* cookie; bool removed; }; diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 27fc4d7..17197a4 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -133,14 +133,13 @@ class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { // net::CookieMonster::Delegate implementation. virtual void OnCookieChanged( - const std::string& domain_key, const net::CookieMonster::CanonicalCookie& cookie, bool removed) { ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, - net::CookieMonster::CookieListPair(domain_key, cookie), + cookie, removed)); } @@ -193,10 +192,10 @@ class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { virtual ~ChromeCookieMonsterDelegate() {} void OnCookieChangedAsyncHelper( - net::CookieMonster::CookieListPair cookie_pair, + net::CookieMonster::CanonicalCookie cookie, bool removed) { if (profile_getter_->get()) { - ChromeCookieDetails cookie_details(&cookie_pair, removed); + ChromeCookieDetails cookie_details(&cookie, removed); NotificationService::current()->Notify( NotificationType::COOKIE_CHANGED, Source<Profile>(profile_getter_->get()), diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 698e385..eba40b6 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -254,11 +254,7 @@ class GetRawCookiesCompletion : public net::CompletionCallback { std::vector<webkit_glue::WebCookie> cookies; for (size_t i = 0; i < cookie_list.size(); ++i) { - // TODO(darin): url.host() is not necessarily the domain of the cookie. - // We need a different API on CookieMonster to provide the domain info. - // See http://crbug.com/34315. - cookies.push_back( - webkit_glue::WebCookie(cookie_list[i].first, cookie_list[i].second)); + cookies.push_back(webkit_glue::WebCookie(cookie_list[i])); } ViewHostMsg_GetRawCookies::WriteReplyParams(reply_msg_, cookies); diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc index 9bdbb67..ef730dd 100644 --- a/chrome/browser/views/options/cookies_view.cc +++ b/chrome/browser/views/options/cookies_view.cc @@ -215,8 +215,8 @@ void CookiesView::OnTreeViewSelectionChanged(views::TreeView* tree_view) { GetDetailedInfo(); if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE) { UpdateVisibleDetailedInfo(cookie_info_view_); - cookie_info_view_->SetCookie(detailed_info.cookie->first, - detailed_info.cookie->second); + cookie_info_view_->SetCookie(detailed_info.cookie->Domain(), + *detailed_info.cookie); } else if (detailed_info.node_type == CookieTreeNode::DetailedInfo::TYPE_DATABASE) { UpdateVisibleDetailedInfo(database_info_view_); diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index 183ca96..e79cf47 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -268,11 +268,11 @@ int CookieMonster::TrimDuplicateCookiesForHost( CookieMap::iterator end) { lock_.AssertAcquired(); - // List of cookies ordered by creation time. - typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieList; + // Set of cookies ordered by creation time. + typedef std::set<CookieMap::iterator, OrderByCreationTimeDesc> CookieSet; // Helper map we populate to find the duplicates. - typedef std::map<CookieSignature, CookieList> EquivalenceMap; + typedef std::map<CookieSignature, CookieSet> EquivalenceMap; EquivalenceMap equivalent_cookies; // The number of duplicate cookies that have been found. @@ -286,7 +286,7 @@ int CookieMonster::TrimDuplicateCookiesForHost( CookieSignature signature(cookie->Name(), cookie->Domain(), cookie->Path()); - CookieList& list = equivalent_cookies[signature]; + CookieSet& list = equivalent_cookies[signature]; // We found a duplicate! if (!list.empty()) @@ -307,7 +307,7 @@ int CookieMonster::TrimDuplicateCookiesForHost( it != equivalent_cookies.end(); ++it) { const CookieSignature& signature = it->first; - CookieList& dupes = it->second; + CookieSet& dupes = it->second; if (dupes.size() <= 1) continue; // This cookiename/path has no duplicates. @@ -327,7 +327,7 @@ int CookieMonster::TrimDuplicateCookiesForHost( // Remove all the cookies identified by |dupes|. It is valid to delete our // list of iterators one at a time, since |cookies_| is a multimap (they // don't invalidate existing iterators following deletion). - for (CookieList::iterator dupes_it = dupes.begin(); + for (CookieSet::iterator dupes_it = dupes.begin(); dupes_it != dupes.end(); ++dupes_it) { InternalDeleteCookie(*dupes_it, true /*sync_to_store*/, @@ -775,7 +775,7 @@ void CookieMonster::InternalInsertCookie(const std::string& key, store_->AddCookie(key, *cc); cookies_.insert(CookieMap::value_type(key, cc)); if (delegate_.get()) - delegate_->OnCookieChanged(key, *cc, false); + delegate_->OnCookieChanged(*cc, false); } void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc) { @@ -811,7 +811,7 @@ void CookieMonster::InternalDeleteCookie(CookieMap::iterator it, if (cc->IsPersistent() && store_ && sync_to_store) store_->DeleteCookie(*cc); if (delegate_.get()) - delegate_->OnCookieChanged(it->first, *cc, true); + delegate_->OnCookieChanged(*cc, true); cookies_.erase(it); delete cc; } @@ -1129,7 +1129,7 @@ CookieMonster::CookieList CookieMonster::GetAllCookies() { CookieList cookie_list; for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end(); ++it) - cookie_list.push_back(CookieListPair(it->first, *it->second)); + cookie_list.push_back(*it->second); return cookie_list; } @@ -1231,7 +1231,7 @@ void CookieMonster::FindRawCookies(const std::string& key, continue; if (!cc->IsOnPath(path)) continue; - list->push_back(CookieListPair(key, *cc)); + list->push_back(*cc); } } @@ -1682,3 +1682,4 @@ std::string CookieMonster::CanonicalCookie::DebugString() const { } } // namespace + diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index 96d98b3..623363f 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -51,8 +51,7 @@ class CookieMonster : public CookieStore { typedef std::multimap<std::string, CanonicalCookie*> CookieMap; typedef std::pair<CookieMap::iterator, CookieMap::iterator> CookieMapItPair; typedef std::pair<std::string, CanonicalCookie*> KeyedCanonicalCookie; - typedef std::pair<std::string, CanonicalCookie> CookieListPair; - typedef std::vector<CookieListPair> CookieList; + typedef std::vector<CanonicalCookie> CookieList; // The store passed in should not have had Init() called on it yet. This // class will take care of initializing it. The backing store is NOT owned by @@ -430,10 +429,9 @@ class CookieMonster::Delegate : public base::RefCountedThreadSafe<CookieMonster::Delegate> { public: // Will be called when a cookie is added or removed. The function is passed - // the respective |cookie| which was added to or removed from the cookies for - // |domain_key|. If |removed| is true, the cookie was deleted. - virtual void OnCookieChanged(const std::string& domain_key, - const CookieMonster::CanonicalCookie& cookie, + // the respective |cookie| which was added to or removed from the cookies. + // If |removed| is true, the cookie was deleted. + virtual void OnCookieChanged(const CookieMonster::CanonicalCookie& cookie, bool removed) = 0; protected: friend class base::RefCountedThreadSafe<CookieMonster::Delegate>; diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc index e9ffc7b..c61a782 100644 --- a/net/base/cookie_monster_unittest.cc +++ b/net/base/cookie_monster_unittest.cc @@ -103,18 +103,15 @@ class MockPersistentCookieStore // Mock for CookieMonster::Delegate class MockCookieMonsterDelegate : public net::CookieMonster::Delegate { public: - typedef std::pair<net::CookieMonster::CookieListPair, bool> + typedef std::pair<net::CookieMonster::CanonicalCookie, bool> CookieNotification; MockCookieMonsterDelegate() {} virtual void OnCookieChanged( - const std::string& domain_key, const net::CookieMonster::CanonicalCookie& cookie, bool removed) { - CookieNotification notification( - net::CookieMonster::CookieListPair(domain_key, cookie), - removed); + CookieNotification notification(cookie, removed); changes_.push_back(notification); } @@ -1139,7 +1136,7 @@ TEST(CookieMonsterTest, TestSecure) { static Time GetFirstCookieAccessDate(net::CookieMonster* cm) { const net::CookieMonster::CookieList all_cookies(cm->GetAllCookies()); - return all_cookies.front().second.LastAccessDate(); + return all_cookies.front().LastAccessDate(); } static const int kLastAccessThresholdMilliseconds = 200; @@ -1247,8 +1244,8 @@ static bool FindAndDeleteCookie(net::CookieMonster* cm, net::CookieMonster::CookieList cookies = cm->GetAllCookies(); for (net::CookieMonster::CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) - if (it->first == domain && it->second.Name() == name) - return cm->DeleteCookie(domain, it->second, false); + if (it->Domain() == domain && it->Name() == name) + return cm->DeleteCookie(domain, *it, false); return false; } @@ -1315,12 +1312,12 @@ TEST(CookieMonsterTest, GetAllCookiesForURL) { net::CookieMonster::CookieList::iterator it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("www.google.izzle", it->first); - EXPECT_EQ("A", it->second.Name()); + EXPECT_EQ("www.google.izzle", it->Domain()); + EXPECT_EQ("A", it->Name()); ASSERT_TRUE(++it != cookies.end()); - EXPECT_EQ(".google.izzle", it->first); - EXPECT_EQ("C", it->second.Name()); + EXPECT_EQ(".google.izzle", it->Domain()); + EXPECT_EQ("C", it->Name()); ASSERT_TRUE(++it == cookies.end()); @@ -1329,16 +1326,16 @@ TEST(CookieMonsterTest, GetAllCookiesForURL) { it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("www.google.izzle", it->first); - EXPECT_EQ("A", it->second.Name()); + EXPECT_EQ("www.google.izzle", it->Domain()); + EXPECT_EQ("A", it->Name()); ASSERT_TRUE(++it != cookies.end()); - EXPECT_EQ(".google.izzle", it->first); - EXPECT_EQ("C", it->second.Name()); + EXPECT_EQ(".google.izzle", it->Domain()); + EXPECT_EQ("C", it->Name()); ASSERT_TRUE(++it != cookies.end()); - EXPECT_EQ(".google.izzle", it->first); - EXPECT_EQ("E", it->second.Name()); + EXPECT_EQ(".google.izzle", it->Domain()); + EXPECT_EQ("E", it->Name()); ASSERT_TRUE(++it == cookies.end()); @@ -1369,12 +1366,12 @@ TEST(CookieMonsterTest, GetAllCookiesForURLPathMatching) { net::CookieMonster::CookieList::iterator it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("A", it->second.Name()); - EXPECT_EQ("/foo", it->second.Path()); + EXPECT_EQ("A", it->Name()); + EXPECT_EQ("/foo", it->Path()); ASSERT_TRUE(++it != cookies.end()); - EXPECT_EQ("E", it->second.Name()); - EXPECT_EQ("/", it->second.Path()); + EXPECT_EQ("E", it->Name()); + EXPECT_EQ("/", it->Path()); ASSERT_TRUE(++it == cookies.end()); @@ -1382,12 +1379,12 @@ TEST(CookieMonsterTest, GetAllCookiesForURLPathMatching) { it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("C", it->second.Name()); - EXPECT_EQ("/bar", it->second.Path()); + EXPECT_EQ("C", it->Name()); + EXPECT_EQ("/bar", it->Path()); ASSERT_TRUE(++it != cookies.end()); - EXPECT_EQ("E", it->second.Name()); - EXPECT_EQ("/", it->second.Path()); + EXPECT_EQ("E", it->Name()); + EXPECT_EQ("/", it->Path()); ASSERT_TRUE(++it == cookies.end()); } @@ -1410,8 +1407,8 @@ TEST(CookieMonsterTest, DeleteCookieByName) { EXPECT_EQ(expected_size, cookies.size()); for (net::CookieMonster::CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { - EXPECT_NE("A1", it->second.Value()); - EXPECT_NE("A2", it->second.Value()); + EXPECT_NE("A1", it->Value()); + EXPECT_NE("A2", it->Value()); } } @@ -1578,26 +1575,26 @@ TEST(CookieMonsterTest, Delegate) { EXPECT_EQ("A=B; C=D; E=F", cm->GetCookies(url_google)); ASSERT_EQ(3u, delegate->changes().size()); EXPECT_EQ(false, delegate->changes()[0].second); - EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first); - EXPECT_EQ("A", delegate->changes()[0].first.second.Name()); - EXPECT_EQ("B", delegate->changes()[0].first.second.Value()); - EXPECT_EQ(url_google.host(), delegate->changes()[1].first.first); + EXPECT_EQ(url_google.host(), delegate->changes()[0].first.Domain()); + EXPECT_EQ("A", delegate->changes()[0].first.Name()); + EXPECT_EQ("B", delegate->changes()[0].first.Value()); + EXPECT_EQ(url_google.host(), delegate->changes()[1].first.Domain()); EXPECT_EQ(false, delegate->changes()[1].second); - EXPECT_EQ("C", delegate->changes()[1].first.second.Name()); - EXPECT_EQ("D", delegate->changes()[1].first.second.Value()); - EXPECT_EQ(url_google.host(), delegate->changes()[2].first.first); + EXPECT_EQ("C", delegate->changes()[1].first.Name()); + EXPECT_EQ("D", delegate->changes()[1].first.Value()); + EXPECT_EQ(url_google.host(), delegate->changes()[2].first.Domain()); EXPECT_EQ(false, delegate->changes()[2].second); - EXPECT_EQ("E", delegate->changes()[2].first.second.Name()); - EXPECT_EQ("F", delegate->changes()[2].first.second.Value()); + EXPECT_EQ("E", delegate->changes()[2].first.Name()); + EXPECT_EQ("F", delegate->changes()[2].first.Value()); delegate->reset(); EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C")); EXPECT_EQ("A=B; E=F", cm->GetCookies(url_google)); ASSERT_EQ(1u, delegate->changes().size()); - EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first); + EXPECT_EQ(url_google.host(), delegate->changes()[0].first.Domain()); EXPECT_EQ(true, delegate->changes()[0].second); - EXPECT_EQ("C", delegate->changes()[0].first.second.Name()); - EXPECT_EQ("D", delegate->changes()[0].first.second.Value()); + EXPECT_EQ("C", delegate->changes()[0].first.Name()); + EXPECT_EQ("D", delegate->changes()[0].first.Value()); delegate->reset(); EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); @@ -1612,9 +1609,9 @@ TEST(CookieMonsterTest, Delegate) { EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); ASSERT_EQ(1u, delegate->changes().size()); EXPECT_EQ(false, delegate->changes()[0].second); - EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first); - EXPECT_EQ("a", delegate->changes()[0].first.second.Name()); - EXPECT_EQ("val1", delegate->changes()[0].first.second.Value()); + EXPECT_EQ(url_google.host(), delegate->changes()[0].first.Domain()); + EXPECT_EQ("a", delegate->changes()[0].first.Name()); + EXPECT_EQ("val1", delegate->changes()[0].first.Value()); delegate->reset(); // Insert a cookie "a" for path "/path1", that is httponly. This should @@ -1630,14 +1627,14 @@ TEST(CookieMonsterTest, Delegate) { EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); ASSERT_EQ(2u, delegate->changes().size()); - EXPECT_EQ(url_google.host(), delegate->changes()[0].first.first); + EXPECT_EQ(url_google.host(), delegate->changes()[0].first.Domain()); EXPECT_EQ(true, delegate->changes()[0].second); - EXPECT_EQ("a", delegate->changes()[0].first.second.Name()); - EXPECT_EQ("val1", delegate->changes()[0].first.second.Value()); - EXPECT_EQ(url_google.host(), delegate->changes()[1].first.first); + EXPECT_EQ("a", delegate->changes()[0].first.Name()); + EXPECT_EQ("val1", delegate->changes()[0].first.Value()); + EXPECT_EQ(url_google.host(), delegate->changes()[1].first.Domain()); EXPECT_EQ(false, delegate->changes()[1].second); - EXPECT_EQ("a", delegate->changes()[1].first.second.Name()); - EXPECT_EQ("val2", delegate->changes()[1].first.second.Value()); + EXPECT_EQ("a", delegate->changes()[1].first.Name()); + EXPECT_EQ("val2", delegate->changes()[1].first.Value()); delegate->reset(); } @@ -1681,14 +1678,13 @@ TEST(CookieMonsterTest, SetCookieWithDetails) { net::CookieMonster::CookieList::iterator it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("A", it->second.Name()); - EXPECT_EQ("B", it->second.Value()); - EXPECT_EQ("www.google.izzle", it->first); - EXPECT_EQ("www.google.izzle", it->second.Domain()); - EXPECT_EQ("/foo", it->second.Path()); - EXPECT_FALSE(it->second.DoesExpire()); - EXPECT_FALSE(it->second.IsSecure()); - EXPECT_FALSE(it->second.IsHttpOnly()); + EXPECT_EQ("A", it->Name()); + EXPECT_EQ("B", it->Value()); + EXPECT_EQ("www.google.izzle", it->Domain()); + EXPECT_EQ("/foo", it->Path()); + EXPECT_FALSE(it->DoesExpire()); + EXPECT_FALSE(it->IsSecure()); + EXPECT_FALSE(it->IsHttpOnly()); ASSERT_TRUE(++it == cookies.end()); @@ -1696,13 +1692,12 @@ TEST(CookieMonsterTest, SetCookieWithDetails) { it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("C", it->second.Name()); - EXPECT_EQ("D", it->second.Value()); - EXPECT_EQ(".google.izzle", it->first); - EXPECT_EQ(".google.izzle", it->second.Domain()); - EXPECT_EQ("/bar", it->second.Path()); - EXPECT_FALSE(it->second.IsSecure()); - EXPECT_TRUE(it->second.IsHttpOnly()); + EXPECT_EQ("C", it->Name()); + EXPECT_EQ("D", it->Value()); + EXPECT_EQ(".google.izzle", it->Domain()); + EXPECT_EQ("/bar", it->Path()); + EXPECT_FALSE(it->IsSecure()); + EXPECT_TRUE(it->IsHttpOnly()); ASSERT_TRUE(++it == cookies.end()); @@ -1710,12 +1705,12 @@ TEST(CookieMonsterTest, SetCookieWithDetails) { it = cookies.begin(); ASSERT_TRUE(it != cookies.end()); - EXPECT_EQ("E", it->second.Name()); - EXPECT_EQ("F", it->second.Value()); - EXPECT_EQ("/", it->second.Path()); - EXPECT_EQ("www.google.izzle", it->second.Domain()); - EXPECT_TRUE(it->second.IsSecure()); - EXPECT_FALSE(it->second.IsHttpOnly()); + EXPECT_EQ("E", it->Name()); + EXPECT_EQ("F", it->Value()); + EXPECT_EQ("/", it->Path()); + EXPECT_EQ("www.google.izzle", it->Domain()); + EXPECT_TRUE(it->IsSecure()); + EXPECT_FALSE(it->IsHttpOnly()); ASSERT_TRUE(++it == cookies.end()); } diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index d1a542a..bd4e56a 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -1637,7 +1637,7 @@ TEST_F(URLRequestTest, CookiePolicy_ForceSession) { net::CookieMonster::CookieList cookies = context->cookie_store()->GetCookieMonster()->GetAllCookies(); EXPECT_EQ(1U, cookies.size()); - EXPECT_FALSE(cookies[0].second.IsPersistent()); + EXPECT_FALSE(cookies[0].IsPersistent()); context->set_cookie_policy(NULL); } diff --git a/webkit/glue/webcookie.h b/webkit/glue/webcookie.h index 2feb800..e2f11e2 100644 --- a/webkit/glue/webcookie.h +++ b/webkit/glue/webcookie.h @@ -28,11 +28,10 @@ struct WebCookie { session(session) { } - WebCookie(const std::string& domain, - const net::CookieMonster::CanonicalCookie& c) + explicit WebCookie(const net::CookieMonster::CanonicalCookie& c) : name(c.Name()), value(c.Value()), - domain(domain), + domain(c.Domain()), path(c.Path()), expires(c.ExpiryDate().ToDoubleT() * 1000), http_only(c.IsHttpOnly()), |