[WIP] refactor: (Part I) make the ownership of URLRequestContextGetter more clear (#13956)
* refactor: desttroy URLRequestContextGetter on IO thread * Accepts a factory class that can customize the creation of URLRequestContext * Use a separate request context for media which is derived from the default * Notify URLRequestContextGetter observers and cleanup on IO thread * Move most of brightray net/ classes into atom net/ * refactor: remove refs to URLRequestContextGetter on shutdown * refactor: remove brigtray switches.{cc|h} * refactor: remove brightray network_delegate.{cc|h} * refactor: make AtomURLRequestJobFactory the top level factory. * Allows to use the default handler from content/ for http{s}, ws{s} schemes. * Removes the storage of job factory in URLRequestContextGetter.
This commit is contained in:
parent
cb4b3e7be0
commit
1c0bb06d4a
34 changed files with 985 additions and 1121 deletions
|
@ -11,7 +11,6 @@
|
|||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "brightray/browser/browser_client.h"
|
||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||
#include "brightray/browser/network_delegate.h"
|
||||
#include "brightray/browser/special_storage_policy.h"
|
||||
#include "brightray/browser/zoom_level_delegate.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
|
@ -20,7 +19,6 @@
|
|||
#include "components/prefs/pref_service.h"
|
||||
#include "components/prefs/pref_service_factory.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/resource_context.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "net/base/escape.h"
|
||||
|
||||
|
@ -37,26 +35,6 @@ std::string MakePartitionName(const std::string& input) {
|
|||
|
||||
} // namespace
|
||||
|
||||
class BrowserContext::ResourceContext : public content::ResourceContext {
|
||||
public:
|
||||
ResourceContext() : getter_(nullptr) {}
|
||||
|
||||
void set_url_request_context_getter(URLRequestContextGetter* getter) {
|
||||
getter_ = getter;
|
||||
}
|
||||
|
||||
private:
|
||||
net::HostResolver* GetHostResolver() override {
|
||||
return getter_->host_resolver();
|
||||
}
|
||||
|
||||
net::URLRequestContext* GetRequestContext() override {
|
||||
return getter_->GetURLRequestContext();
|
||||
}
|
||||
|
||||
URLRequestContextGetter* getter_;
|
||||
};
|
||||
|
||||
// static
|
||||
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
||||
|
||||
|
@ -72,7 +50,6 @@ scoped_refptr<BrowserContext> BrowserContext::Get(const std::string& partition,
|
|||
|
||||
BrowserContext::BrowserContext(const std::string& partition, bool in_memory)
|
||||
: in_memory_(in_memory),
|
||||
resource_context_(new ResourceContext),
|
||||
storage_policy_(new SpecialStoragePolicy),
|
||||
weak_factory_(this) {
|
||||
if (!PathService::Get(DIR_USER_DATA, &path_)) {
|
||||
|
@ -88,6 +65,8 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory)
|
|||
|
||||
content::BrowserContext::Initialize(this, path_);
|
||||
|
||||
io_handle_ = new URLRequestContextGetter::Handle(GetWeakPtr());
|
||||
|
||||
browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr();
|
||||
}
|
||||
|
||||
|
@ -95,14 +74,7 @@ BrowserContext::~BrowserContext() {
|
|||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
NotifyWillBeDestroyed(this);
|
||||
ShutdownStoragePartitions();
|
||||
if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
|
||||
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
|
||||
resource_context_.release());
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&URLRequestContextGetter::NotifyContextShutdownOnIO,
|
||||
base::RetainedRef(url_request_getter_)));
|
||||
}
|
||||
io_handle_->ShutdownOnUIThread();
|
||||
}
|
||||
|
||||
void BrowserContext::InitPrefs() {
|
||||
|
@ -135,17 +107,9 @@ URLRequestContextGetter* BrowserContext::GetRequestContext() {
|
|||
net::URLRequestContextGetter* BrowserContext::CreateRequestContext(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
||||
DCHECK(!url_request_getter_.get());
|
||||
url_request_getter_ = new URLRequestContextGetter(
|
||||
this, static_cast<NetLog*>(BrowserClient::Get()->GetNetLog()), GetPath(),
|
||||
in_memory_, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
|
||||
auto* factory = GetFactoryForMainRequestContext(
|
||||
protocol_handlers, std::move(protocol_interceptors));
|
||||
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
||||
return url_request_getter_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<net::NetworkDelegate> BrowserContext::CreateNetworkDelegate() {
|
||||
return std::make_unique<NetworkDelegate>();
|
||||
return io_handle_->CreateMainRequestContextGetter(factory).get();
|
||||
}
|
||||
|
||||
std::string BrowserContext::GetMediaDeviceIDSalt() {
|
||||
|
@ -171,7 +135,7 @@ bool BrowserContext::IsOffTheRecord() const {
|
|||
}
|
||||
|
||||
content::ResourceContext* BrowserContext::GetResourceContext() {
|
||||
return resource_context_.get();
|
||||
return io_handle_->GetResourceContext();
|
||||
}
|
||||
|
||||
content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() {
|
||||
|
@ -214,17 +178,19 @@ BrowserContext::CreateRequestContextForStoragePartition(
|
|||
bool in_memory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* BrowserContext::CreateMediaRequestContext() {
|
||||
return url_request_getter_.get();
|
||||
return io_handle_->GetMediaRequestContextGetter().get();
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter*
|
||||
BrowserContext::CreateMediaRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue