REVIEW: let browser context manage cookie change sub list

This commit is contained in:
deepak1556 2017-11-28 12:53:42 +05:30 committed by Cheng Zhao
parent 9fa08fdbc0
commit 5eb0a89579
7 changed files with 53 additions and 45 deletions

View file

@ -238,12 +238,11 @@ 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()) {
: browser_context_(browser_context),
request_context_getter_(browser_context->url_request_context_getter()) {
Init(isolate);
cookie_change_subscription_ =
browser_context->url_request_context_getter()
->RegisterCookieChangeCallback(
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
cookie_change_subscription_ = browser_context->RegisterCookieChangeCallback(
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
}
Cookies::~Cookies() {}
@ -281,7 +280,7 @@ void Cookies::FlushStore(const base::Closure& callback) {
base::Bind(FlushCookieStoreOnIOThread, getter, callback));
}
void Cookies::OnCookieChanged(const brightray::CookieDetails* details) {
void Cookies::OnCookieChanged(const 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/cookie_details.h"
#include "base/callback.h"
#include "brightray/browser/net/cookie_details.h"
#include "native_mate/handle.h"
#include "net/cookies/canonical_cookie.h"
@ -54,15 +54,17 @@ class Cookies : public mate::TrackableObject<Cookies> {
void Set(const base::DictionaryValue& details, const SetCallback& callback);
void FlushStore(const base::Closure& callback);
// brightray::URLRequestContextGetter subscription:
void OnCookieChanged(const brightray::CookieDetails*);
// AtomBrowserContext::RegisterCookieChangeCallback subscription:
void OnCookieChanged(const CookieDetails*);
private:
net::URLRequestContextGetter* request_context_getter_;
std::unique_ptr<
base::CallbackList<void(const brightray::CookieDetails*)>::Subscription>
// Store a reference to ensure this class gets destroyed before the context.
scoped_refptr<AtomBrowserContext> browser_context_;
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
cookie_change_subscription_;
net::URLRequestContextGetter* request_context_getter_;
DISALLOW_COPY_AND_ASSIGN(Cookies);
};