Skip to content

Commit

Permalink
Refactor CookieStore/CookieMonster
Browse files Browse the repository at this point in the history
Make GetAllCookiesForURLAsync part of CookieStore, so that the most common
use cases do not need to know about CookieMonster any more.

R=erikwright@chromium.org, jam@chromium.org, mmenke@chromium.org

Review URL: https://codereview.chromium.org/198913002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259018 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tburkard@chromium.org committed Mar 24, 2014
1 parent 545de6c commit dc8313a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
10 changes: 4 additions & 6 deletions content/browser/renderer_host/render_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "net/base/mime_util.h"
#include "net/base/request_priority.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_cache.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
Expand Down Expand Up @@ -594,7 +594,7 @@ void RenderMessageFilter::OnSetCookie(int render_frame_id,
net::CookieStore* cookie_store = GetCookieStoreForURL(url);
// Pass a null callback since we don't care about when the 'set' completes.
cookie_store->SetCookieWithOptionsAsync(
url, cookie, options, net::CookieMonster::SetCookiesCallback());
url, cookie, options, net::CookieStore::SetCookiesCallback());
}
}

Expand All @@ -616,8 +616,7 @@ void RenderMessageFilter::OnGetCookies(int render_frame_id,
base::debug::Alias(url_buf);

net::CookieStore* cookie_store = GetCookieStoreForURL(url);
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
cookie_monster->GetAllCookiesForURLAsync(
cookie_store->GetAllCookiesForURLAsync(
url, base::Bind(&RenderMessageFilter::CheckPolicyForCookies, this,
render_frame_id, url, first_party_for_cookies,
reply_msg));
Expand All @@ -643,8 +642,7 @@ void RenderMessageFilter::OnGetRawCookies(
// be applied to outbound requests for the given URL. Since this cookie info
// is visible in the developer tools, it is helpful to make it match reality.
net::CookieStore* cookie_store = GetCookieStoreForURL(url);
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
cookie_monster->GetAllCookiesForURLAsync(
cookie_store->GetAllCookiesForURLAsync(
url, base::Bind(&RenderMessageFilter::SendGetRawCookiesResponse,
this, reply_msg));
}
Expand Down
11 changes: 6 additions & 5 deletions net/cookies/cookie_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ class NET_EXPORT CookieMonster : public CookieStore {
const CookieOptions& options,
const GetCookieListCallback& callback);

// Invokes GetAllCookiesForURLWithOptions with options set to include HTTP
// only cookies.
void GetAllCookiesForURLAsync(const GURL& url,
const GetCookieListCallback& callback);

// Deletes all of the cookies.
void DeleteAllAsync(const DeleteCallback& callback);

Expand Down Expand Up @@ -257,6 +252,12 @@ class NET_EXPORT CookieMonster : public CookieStore {
const CookieOptions& options,
const GetCookiesCallback& callback) OVERRIDE;

// Invokes GetAllCookiesForURLWithOptions with options set to include HTTP
// only cookies.
virtual void GetAllCookiesForURLAsync(
const GURL& url,
const GetCookieListCallback& callback) OVERRIDE;

// Deletes all cookies with that might apply to |url| that has |cookie_name|.
virtual void DeleteCookieAsync(
const GURL& url, const std::string& cookie_name,
Expand Down
11 changes: 9 additions & 2 deletions net/cookies/cookie_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "net/base/net_export.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_options.h"

class GURL;
Expand All @@ -28,8 +29,8 @@ class CookieMonster;
class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> {
public:
// Callback definitions.
typedef base::Callback<void(const std::string& cookie)>
GetCookiesCallback;
typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback;
typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback;
typedef base::Callback<void(bool success)> SetCookiesCallback;
typedef base::Callback<void(int num_deleted)> DeleteCallback;

Expand All @@ -55,6 +56,12 @@ class NET_EXPORT CookieStore : public base::RefCountedThreadSafe<CookieStore> {
const CookieOptions& options,
const GetCookiesCallback& callback) = 0;

// Returns all matching cookies without marking them as accessed,
// including HTTP only cookies.
virtual void GetAllCookiesForURLAsync(
const GURL& url,
const GetCookieListCallback& callback) = 0;

// Deletes the passed in cookie for the specified URL.
virtual void DeleteCookieAsync(const GURL& url,
const std::string& cookie_name,
Expand Down
6 changes: 6 additions & 0 deletions net/cookies/cookie_store_test_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ void DelayedCookieMonster::GetCookiesWithOptionsAsync(
base::TimeDelta::FromMilliseconds(kDelayedTime));
}

void DelayedCookieMonster::GetAllCookiesForURLAsync(
const GURL& url,
const GetCookieListCallback& callback) {
cookie_monster_->GetAllCookiesForURLAsync(url, callback);
}

void DelayedCookieMonster::InvokeSetCookiesCallback(
const CookieMonster::SetCookiesCallback& callback) {
if (!callback.is_null())
Expand Down
4 changes: 4 additions & 0 deletions net/cookies/cookie_store_test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class DelayedCookieMonster : public CookieStore {
const CookieOptions& options,
const CookieMonster::GetCookiesCallback& callback) OVERRIDE;

virtual void GetAllCookiesForURLAsync(
const GURL& url,
const GetCookieListCallback& callback) OVERRIDE;

virtual bool SetCookieWithOptions(const GURL& url,
const std::string& cookie_line,
const CookieOptions& options);
Expand Down
15 changes: 5 additions & 10 deletions net/url_request/url_request_http_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "net/base/network_delegate.h"
#include "net/base/sdch_manager.h"
#include "net/cert/cert_status_flags.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
#include "net/http/http_content_disposition.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_headers.h"
Expand Down Expand Up @@ -550,15 +550,10 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() {

CookieStore* cookie_store = GetCookieStore();
if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) {
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
if (cookie_monster) {
cookie_monster->GetAllCookiesForURLAsync(
request_->url(),
base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad,
weak_factory_.GetWeakPtr()));
} else {
CheckCookiePolicyAndLoad(CookieList());
}
cookie_store->GetAllCookiesForURLAsync(
request_->url(),
base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad,
weak_factory_.GetWeakPtr()));
} else {
DoStartTransaction();
}
Expand Down
6 changes: 6 additions & 0 deletions net/websockets/websocket_job_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ class MockCookieStore : public CookieStore {
callback.Run(GetCookiesWithOptions(url, options));
}

virtual void GetAllCookiesForURLAsync(
const GURL& url,
const GetCookieListCallback& callback) OVERRIDE {
ADD_FAILURE();
}

virtual void DeleteCookieAsync(const GURL& url,
const std::string& cookie_name,
const base::Closure& callback) OVERRIDE {
Expand Down

0 comments on commit dc8313a

Please sign in to comment.