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

@ -1,27 +0,0 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef BRIGHTRAY_BROWSER_NET_COOKIE_DETAILS_H_
#define BRIGHTRAY_BROWSER_NET_COOKIE_DETAILS_H_
#include "base/macros.h"
#include "net/cookies/cookie_store.h"
namespace brightray {
struct CookieDetails {
public:
CookieDetails(const net::CanonicalCookie* cookie_copy,
bool is_removed,
net::CookieStore::ChangeCause cause)
: cookie(cookie_copy), removed(is_removed), cause(cause) {}
const net::CanonicalCookie* cookie;
bool removed;
net::CookieStore::ChangeCause cause;
};
} // namespace brightray
#endif // BRIGHTRAY_BROWSER_NET_COOKIE_DETAILS_H_

View file

@ -13,7 +13,6 @@
#include "base/threading/sequenced_worker_pool.h"
#include "base/threading/worker_pool.h"
#include "brightray/browser/browser_client.h"
#include "brightray/browser/net/cookie_details.h"
#include "brightray/browser/net/devtools_network_controller_handle.h"
#include "brightray/browser/net/devtools_network_transaction_factory.h"
#include "brightray/browser/net/require_ct_delegate.h"
@ -155,30 +154,19 @@ URLRequestContextGetter::URLRequestContextGetter(
URLRequestContextGetter::~URLRequestContextGetter() {
}
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
URLRequestContextGetter::RegisterCookieChangeCallback(
const base::Callback<void(const CookieDetails*)>& cb) {
return cookie_change_sub_list_.Add(cb);
}
void URLRequestContextGetter::NotifyCookieChange(
const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause) {
CookieDetails cookie_details(&cookie, removed, cause);
cookie_change_sub_list_.Notify(&cookie_details);
}
void URLRequestContextGetter::OnCookieChanged(
const net::CanonicalCookie& cookie,
net::CookieStore::ChangeCause cause) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
if (!delegate_)
return;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&URLRequestContextGetter::NotifyCookieChange, this, cookie,
!(cause == net::CookieStore::ChangeCause::INSERTED),
cause));
base::BindOnce(
&Delegate::NotifyCookieChange, base::Unretained(delegate_), cookie,
!(cause == net::CookieStore::ChangeCause::INSERTED), cause));
}
net::HostResolver* URLRequestContextGetter::host_resolver() {

View file

@ -8,7 +8,6 @@
#include <string>
#include <vector>
#include "base/callback_list.h"
#include "base/files/file_path.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
@ -38,7 +37,6 @@ namespace brightray {
class RequireCTDelegate;
class DevToolsNetworkControllerHandle;
class NetLog;
struct CookieDetails;
class URLRequestContextGetter : public net::URLRequestContextGetter {
public:
@ -59,6 +57,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
RequireCTDelegate* ct_delegate);
virtual net::SSLConfigService* CreateSSLConfigService();
virtual std::vector<std::string> GetCookieableSchemes();
virtual void NotifyCookieChange(const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause) {}
};
URLRequestContextGetter(
@ -72,13 +73,6 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
content::URLRequestInterceptorScopedVector protocol_interceptors);
virtual ~URLRequestContextGetter();
// Register callbacks that needs to notified on any cookie store changes.
std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
RegisterCookieChangeCallback(
const base::Callback<void(const CookieDetails*)>& cb);
void NotifyCookieChange(const net::CanonicalCookie& cookie,
bool removed,
net::CookieStore::ChangeCause cause);
// net::CookieStore::CookieChangedCallback implementation.
void OnCookieChanged(const net::CanonicalCookie& cookie,
net::CookieStore::ChangeCause cause);
@ -119,7 +113,6 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector protocol_interceptors_;
base::CallbackList<void(const CookieDetails*)> cookie_change_sub_list_;
net::URLRequestJobFactory* job_factory_; // weak ref
DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter);