diff options
author | mmenke <mmenke@chromium.org> | 2016-01-22 15:36:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-22 23:37:31 +0000 |
commit | 9fa44f2db2146a84215a92e5ae6efe08358232fe (patch) | |
tree | 3383d40a52ec8fccd4a91518563daa501fa73f7e /ios/net | |
parent | 3193cb26e8bed7b64d9e3d4fe94a9abf622e9672 (diff) | |
download | chromium_src-9fa44f2db2146a84215a92e5ae6efe08358232fe.zip chromium_src-9fa44f2db2146a84215a92e5ae6efe08358232fe.tar.gz chromium_src-9fa44f2db2146a84215a92e5ae6efe08358232fe.tar.bz2 |
Promote GetAllCookiesAsync from CookieMonster to CookieStore.
This means that more classes can just use the CookieStore interface,
rather than depending on a particular implementation of it.
BUG=579653
Review URL: https://codereview.chromium.org/1618943002
Cr-Commit-Position: refs/heads/master@{#371080}
Diffstat (limited to 'ios/net')
-rw-r--r-- | ios/net/cookies/cookie_store_ios.h | 6 | ||||
-rw-r--r-- | ios/net/cookies/cookie_store_ios.mm | 58 | ||||
-rw-r--r-- | ios/net/cookies/cookie_store_ios_unittest.mm | 5 |
3 files changed, 63 insertions, 6 deletions
diff --git a/ios/net/cookies/cookie_store_ios.h b/ios/net/cookies/cookie_store_ios.h index 79b5482..bb30c81 100644 --- a/ios/net/cookies/cookie_store_ios.h +++ b/ios/net/cookies/cookie_store_ios.h @@ -124,6 +124,7 @@ class CookieStoreIOS : public net::CookieStore, const GetCookiesCallback& callback) override; void GetAllCookiesForURLAsync(const GURL& url, const GetCookieListCallback& callback) override; + void GetAllCookiesAsync(const GetCookieListCallback& callback) override; void DeleteCookieAsync(const GURL& url, const std::string& cookie_name, const base::Closure& callback) override; @@ -287,6 +288,11 @@ class CookieStoreIOS : public net::CookieStore, void UpdateCachesAfterDelete(const DeleteCallback& callback, int num_deleted); void UpdateCachesAfterClosure(const base::Closure& callback); + // Takes an NSArray of NSHTTPCookies as returns a net::CookieList. + // The returned cookies are ordered by longest path, then earliest + // creation date. + net::CookieList CanonicalCookieListFromSystemCookies(NSArray* cookies); + // These three functions are used for wrapping user-supplied callbacks given // to CookieStoreIOS mutator methods. Given a callback, they return a new // callback that invokes UpdateCachesFromCookieMonster() to schedule an diff --git a/ios/net/cookies/cookie_store_ios.mm b/ios/net/cookies/cookie_store_ios.mm index a7d20d7..ee12b25 100644 --- a/ios/net/cookies/cookie_store_ios.mm +++ b/ios/net/cookies/cookie_store_ios.mm @@ -210,6 +210,15 @@ NSArray* GetCookiesForURL(NSHTTPCookieStorage* system_store, return [cookies sortedArrayUsingFunction:CompareCookies context:manager]; } +// Gets all cookies from the system cookie store. +NSArray* GetAllCookies(NSHTTPCookieStorage* system_store, + CookieCreationTimeManager* manager) { + NSArray* cookies = [system_store cookies]; + + // Sort cookies by decreasing path length, then creation time, as per RFC6265. + return [cookies sortedArrayUsingFunction:CompareCookies context:manager]; +} + // Builds a cookie line (such as "key1=value1; key2=value2") from an array of // cookies. std::string BuildCookieLine(NSArray* cookies, @@ -475,18 +484,44 @@ void CookieStoreIOS::GetAllCookiesForURLAsync( NSArray* cookies = GetCookiesForURL(system_store_, url, creation_time_manager_.get()); - net::CookieList cookie_list; - cookie_list.reserve([cookies count]); - for (NSHTTPCookie* cookie in cookies) { - base::Time created = creation_time_manager_->GetCreationTime(cookie); - cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); - } + net::CookieList cookie_list = CanonicalCookieListFromSystemCookies( + cookies); if (!callback.is_null()) callback.Run(cookie_list); break; } } +void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) { + DCHECK(thread_checker_.CalledOnValidThread()); + + switch (synchronization_state_) { + case NOT_SYNCHRONIZED: + cookie_monster_->GetAllCookiesAsync(callback); + break; + case SYNCHRONIZING: + tasks_pending_synchronization_.push_back(base::Bind( + &CookieStoreIOS::GetAllCookiesAsync, this, callback)); + break; + case SYNCHRONIZED: + if (!SystemCookiesAllowed()) { + // If cookies are not allowed, the cookies are stashed in the + // CookieMonster, so get them from there. + cookie_monster_->GetAllCookiesAsync(callback); + return; + } + + NSArray* cookies = GetAllCookies(system_store_, + creation_time_manager_.get()); + net::CookieList cookie_list = CanonicalCookieListFromSystemCookies( + cookies); + if (!callback.is_null()) { + callback.Run(cookie_list); + } + break; + } +} + void CookieStoreIOS::DeleteCookieAsync(const GURL& url, const std::string& cookie_name, const base::Closure& callback) { @@ -990,6 +1025,17 @@ void CookieStoreIOS::UpdateCachesAfterClosure(const base::Closure& callback) { callback.Run(); } +net::CookieList +CookieStoreIOS::CanonicalCookieListFromSystemCookies(NSArray* cookies) { + net::CookieList cookie_list; + cookie_list.reserve([cookies count]); + for (NSHTTPCookie* cookie in cookies) { + base::Time created = creation_time_manager_->GetCreationTime(cookie); + cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); + } + return cookie_list; +} + CookieStoreIOS::SetCookiesCallback CookieStoreIOS::WrapSetCallback( const SetCookiesCallback& callback) { DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/ios/net/cookies/cookie_store_ios_unittest.mm b/ios/net/cookies/cookie_store_ios_unittest.mm index 2180a29..ef1907d 100644 --- a/ios/net/cookies/cookie_store_ios_unittest.mm +++ b/ios/net/cookies/cookie_store_ios_unittest.mm @@ -101,6 +101,11 @@ class RoundTripTestCookieStore : public net::CookieStore { store_->GetAllCookiesForURLAsync(url, callback); } + void GetAllCookiesAsync(const GetCookieListCallback& callback) override { + RoundTrip(); + store_->GetAllCookiesAsync(callback); + } + void DeleteCookieAsync(const GURL& url, const std::string& cookie_name, const base::Closure& callback) override { |