REVIEW: Subscribe to cookie store for changes in place of CookieMonsterDelegate

This commit is contained in:
deepak1556 2017-11-27 08:57:14 +05:30 committed by Cheng Zhao
parent 60f69ad77b
commit 248d572077
11 changed files with 94 additions and 131 deletions

View file

@ -20,7 +20,6 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
using atom::AtomCookieDelegate;
using content::BrowserThread;
namespace mate {
@ -238,17 +237,16 @@ void SetCookieOnIO(scoped_refptr<net::URLRequestContextGetter> getter,
} // namespace
Cookies::Cookies(v8::Isolate* isolate,
AtomBrowserContext* browser_context)
: request_context_getter_(browser_context->url_request_context_getter()),
cookie_delegate_(browser_context->cookie_delegate()) {
Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: request_context_getter_(browser_context->url_request_context_getter()) {
Init(isolate);
cookie_delegate_->AddObserver(this);
cookie_change_subscription_ =
browser_context->url_request_context_getter()
->RegisterCookieChangeCallback(
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
}
Cookies::~Cookies() {
cookie_delegate_->RemoveObserver(this);
}
Cookies::~Cookies() {}
void Cookies::Get(const base::DictionaryValue& filter,
const GetCallback& callback) {
@ -283,10 +281,8 @@ void Cookies::FlushStore(const base::Closure& callback) {
base::Bind(FlushCookieStoreOnIOThread, getter, callback));
}
void Cookies::OnCookieChanged(const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause) {
Emit("changed", cookie, cause, removed);
void Cookies::OnCookieChanged(const brightray::CookieDetails* details) {
Emit("changed", *(details->cookie), details->cause, details->removed);
}

View file

@ -8,8 +8,8 @@
#include <string>
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/net/atom_cookie_delegate.h"
#include "base/callback.h"
#include "brightray/browser/net/cookie_details.h"
#include "native_mate/handle.h"
#include "net/cookies/canonical_cookie.h"
@ -27,8 +27,7 @@ class AtomBrowserContext;
namespace api {
class Cookies : public mate::TrackableObject<Cookies>,
public AtomCookieDelegate::Observer {
class Cookies : public mate::TrackableObject<Cookies> {
public:
enum Error {
SUCCESS,
@ -55,14 +54,14 @@ class Cookies : public mate::TrackableObject<Cookies>,
void Set(const base::DictionaryValue& details, const SetCallback& callback);
void FlushStore(const base::Closure& callback);
// AtomCookieDelegate::Observer:
void OnCookieChanged(const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause) override;
// brightray::URLRequestContextGetter subscription:
void OnCookieChanged(const brightray::CookieDetails*);
private:
net::URLRequestContextGetter* request_context_getter_;
scoped_refptr<AtomCookieDelegate> cookie_delegate_;
std::unique_ptr<
base::CallbackList<void(const brightray::CookieDetails*)>::Subscription>
cookie_change_subscription_;
DISALLOW_COPY_AND_ASSIGN(Cookies);
};