Cookie Store: Extract change notifications to separate classes.
https://chromium-review.googlesource.com/c/chromium/src/+/919159
This commit is contained in:
parent
806acbdf12
commit
bf55d856d2
6 changed files with 32 additions and 33 deletions
|
@ -14,7 +14,6 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/cookies/cookie_monster.h"
|
|
||||||
#include "net/cookies/cookie_store.h"
|
#include "net/cookies/cookie_store.h"
|
||||||
#include "net/cookies/cookie_util.h"
|
#include "net/cookies/cookie_util.h"
|
||||||
#include "net/url_request/url_request_context.h"
|
#include "net/url_request/url_request_context.h"
|
||||||
|
@ -55,24 +54,24 @@ struct Converter<net::CanonicalCookie> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<net::CookieStore::ChangeCause> {
|
struct Converter<net::CookieChangeCause> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const net::CookieStore::ChangeCause& val) {
|
const net::CookieChangeCause& val) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case net::CookieStore::ChangeCause::INSERTED:
|
case net::CookieChangeCause::INSERTED:
|
||||||
case net::CookieStore::ChangeCause::EXPLICIT:
|
case net::CookieChangeCause::EXPLICIT:
|
||||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN:
|
case net::CookieChangeCause::EXPLICIT_DELETE_BETWEEN:
|
||||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE:
|
case net::CookieChangeCause::EXPLICIT_DELETE_PREDICATE:
|
||||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE:
|
case net::CookieChangeCause::EXPLICIT_DELETE_SINGLE:
|
||||||
case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL:
|
case net::CookieChangeCause::EXPLICIT_DELETE_CANONICAL:
|
||||||
return mate::StringToV8(isolate, "explicit");
|
return mate::StringToV8(isolate, "explicit");
|
||||||
case net::CookieStore::ChangeCause::OVERWRITE:
|
case net::CookieChangeCause::OVERWRITE:
|
||||||
return mate::StringToV8(isolate, "overwrite");
|
return mate::StringToV8(isolate, "overwrite");
|
||||||
case net::CookieStore::ChangeCause::EXPIRED:
|
case net::CookieChangeCause::EXPIRED:
|
||||||
return mate::StringToV8(isolate, "expired");
|
return mate::StringToV8(isolate, "expired");
|
||||||
case net::CookieStore::ChangeCause::EVICTED:
|
case net::CookieChangeCause::EVICTED:
|
||||||
return mate::StringToV8(isolate, "evicted");
|
return mate::StringToV8(isolate, "evicted");
|
||||||
case net::CookieStore::ChangeCause::EXPIRED_OVERWRITE:
|
case net::CookieChangeCause::EXPIRED_OVERWRITE:
|
||||||
return mate::StringToV8(isolate, "expired-overwrite");
|
return mate::StringToV8(isolate, "expired-overwrite");
|
||||||
default:
|
default:
|
||||||
return mate::StringToV8(isolate, "unknown");
|
return mate::StringToV8(isolate, "unknown");
|
||||||
|
|
|
@ -203,10 +203,9 @@ std::vector<std::string> AtomBrowserContext::GetCookieableSchemes() {
|
||||||
return default_schemes;
|
return default_schemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserContext::NotifyCookieChange(
|
void AtomBrowserContext::NotifyCookieChange(const net::CanonicalCookie& cookie,
|
||||||
const net::CanonicalCookie& cookie,
|
bool removed,
|
||||||
bool removed,
|
net::CookieChangeCause cause) {
|
||||||
net::CookieStore::ChangeCause cause) {
|
|
||||||
CookieDetails cookie_details(&cookie, removed, cause);
|
CookieDetails cookie_details(&cookie, removed, cause);
|
||||||
cookie_change_sub_list_.Notify(&cookie_details);
|
cookie_change_sub_list_.Notify(&cookie_details);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
||||||
std::vector<std::string> GetCookieableSchemes() override;
|
std::vector<std::string> GetCookieableSchemes() override;
|
||||||
void NotifyCookieChange(const net::CanonicalCookie& cookie,
|
void NotifyCookieChange(const net::CanonicalCookie& cookie,
|
||||||
bool removed,
|
bool removed,
|
||||||
net::CookieStore::ChangeCause cause) override;
|
net::CookieChangeCause cause) override;
|
||||||
|
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#define ATOM_BROWSER_NET_COOKIE_DETAILS_H_
|
#define ATOM_BROWSER_NET_COOKIE_DETAILS_H_
|
||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "net/cookies/cookie_store.h"
|
#include "net/cookies/cookie_change_dispatcher.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -14,12 +14,12 @@ struct CookieDetails {
|
||||||
public:
|
public:
|
||||||
CookieDetails(const net::CanonicalCookie* cookie_copy,
|
CookieDetails(const net::CanonicalCookie* cookie_copy,
|
||||||
bool is_removed,
|
bool is_removed,
|
||||||
net::CookieStore::ChangeCause cause)
|
net::CookieChangeCause cause)
|
||||||
: cookie(cookie_copy), removed(is_removed), cause(cause) {}
|
: cookie(cookie_copy), removed(is_removed), cause(cause) {}
|
||||||
|
|
||||||
const net::CanonicalCookie* cookie;
|
const net::CanonicalCookie* cookie;
|
||||||
bool removed;
|
bool removed;
|
||||||
net::CookieStore::ChangeCause cause;
|
net::CookieChangeCause cause;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -168,7 +168,7 @@ void URLRequestContextGetter::NotifyContextShutdownOnIO() {
|
||||||
|
|
||||||
void URLRequestContextGetter::OnCookieChanged(
|
void URLRequestContextGetter::OnCookieChanged(
|
||||||
const net::CanonicalCookie& cookie,
|
const net::CanonicalCookie& cookie,
|
||||||
net::CookieStore::ChangeCause cause) {
|
net::CookieChangeCause cause) {
|
||||||
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
|
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
|
||||||
|
|
||||||
if (!delegate_ || context_shutting_down_)
|
if (!delegate_ || context_shutting_down_)
|
||||||
|
@ -176,9 +176,9 @@ void URLRequestContextGetter::OnCookieChanged(
|
||||||
|
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE,
|
content::BrowserThread::UI, FROM_HERE,
|
||||||
base::BindOnce(
|
base::BindOnce(&Delegate::NotifyCookieChange, base::Unretained(delegate_),
|
||||||
&Delegate::NotifyCookieChange, base::Unretained(delegate_), cookie,
|
cookie, !(cause == net::CookieChangeCause::INSERTED),
|
||||||
!(cause == net::CookieStore::ChangeCause::INSERTED), cause));
|
cause));
|
||||||
}
|
}
|
||||||
|
|
||||||
net::HostResolver* URLRequestContextGetter::host_resolver() {
|
net::HostResolver* URLRequestContextGetter::host_resolver() {
|
||||||
|
@ -223,8 +223,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
// Cookie store will outlive notifier by order of declaration
|
// Cookie store will outlive notifier by order of declaration
|
||||||
// in the header.
|
// in the header.
|
||||||
cookie_change_sub_ =
|
cookie_change_sub_ =
|
||||||
url_request_context_->cookie_store()->AddCallbackForAllChanges(
|
url_request_context_->cookie_store()
|
||||||
base::Bind(&URLRequestContextGetter::OnCookieChanged, this));
|
->GetChangeDispatcher()
|
||||||
|
.AddCallbackForAllChanges(
|
||||||
|
base::Bind(&URLRequestContextGetter::OnCookieChanged, this));
|
||||||
|
|
||||||
storage_->set_channel_id_service(std::make_unique<net::ChannelIDService>(
|
storage_->set_channel_id_service(std::make_unique<net::ChannelIDService>(
|
||||||
new net::DefaultChannelIDStore(nullptr)));
|
new net::DefaultChannelIDStore(nullptr)));
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
#include "content/public/browser/content_browser_client.h"
|
#include "content/public/browser/content_browser_client.h"
|
||||||
#include "net/cookies/cookie_store.h"
|
#include "net/cookies/cookie_change_dispatcher.h"
|
||||||
#include "net/http/http_cache.h"
|
#include "net/http/http_cache.h"
|
||||||
#include "net/http/transport_security_state.h"
|
#include "net/http/transport_security_state.h"
|
||||||
#include "net/http/url_security_manager.h"
|
#include "net/http/url_security_manager.h"
|
||||||
|
@ -60,7 +60,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||||
virtual std::vector<std::string> GetCookieableSchemes();
|
virtual std::vector<std::string> GetCookieableSchemes();
|
||||||
virtual void NotifyCookieChange(const net::CanonicalCookie& cookie,
|
virtual void NotifyCookieChange(const net::CanonicalCookie& cookie,
|
||||||
bool removed,
|
bool removed,
|
||||||
net::CookieStore::ChangeCause cause) {}
|
net::CookieChangeCause cause) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
URLRequestContextGetter(
|
URLRequestContextGetter(
|
||||||
|
@ -72,9 +72,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||||
content::ProtocolHandlerMap* protocol_handlers,
|
content::ProtocolHandlerMap* protocol_handlers,
|
||||||
content::URLRequestInterceptorScopedVector protocol_interceptors);
|
content::URLRequestInterceptorScopedVector protocol_interceptors);
|
||||||
|
|
||||||
// net::CookieStore::CookieChangedCallback implementation.
|
// net::CookieChangeDispatcher::CookieChangedCallback implementation.
|
||||||
void OnCookieChanged(const net::CanonicalCookie& cookie,
|
void OnCookieChanged(const net::CanonicalCookie& cookie,
|
||||||
net::CookieStore::ChangeCause cause);
|
net::CookieChangeCause cause);
|
||||||
|
|
||||||
// net::URLRequestContextGetter:
|
// net::URLRequestContextGetter:
|
||||||
net::URLRequestContext* GetURLRequestContext() override;
|
net::URLRequestContext* GetURLRequestContext() override;
|
||||||
|
@ -109,8 +109,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
||||||
std::unique_ptr<net::HostMappingRules> host_mapping_rules_;
|
std::unique_ptr<net::HostMappingRules> host_mapping_rules_;
|
||||||
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
|
std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences_;
|
||||||
std::unique_ptr<net::HttpNetworkSession> http_network_session_;
|
std::unique_ptr<net::HttpNetworkSession> http_network_session_;
|
||||||
std::unique_ptr<net::CookieStore::CookieChangedSubscription>
|
std::unique_ptr<net::CookieChangeSubscription> cookie_change_sub_;
|
||||||
cookie_change_sub_;
|
|
||||||
content::ProtocolHandlerMap protocol_handlers_;
|
content::ProtocolHandlerMap protocol_handlers_;
|
||||||
content::URLRequestInterceptorScopedVector protocol_interceptors_;
|
content::URLRequestInterceptorScopedVector protocol_interceptors_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue