[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
|
@ -78,13 +78,13 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const override {
|
||||
RequestJob* request_job = new RequestJob(request, network_delegate);
|
||||
request_job->SetHandlerInfo(isolate_, request_context_.get(), handler_);
|
||||
request_job->SetHandlerInfo(isolate_, request_context_, handler_);
|
||||
return request_job;
|
||||
}
|
||||
|
||||
private:
|
||||
v8::Isolate* isolate_;
|
||||
scoped_refptr<net::URLRequestContextGetter> request_context_;
|
||||
net::URLRequestContextGetter* request_context_;
|
||||
Protocol::Handler handler_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CustomProtocolHandler);
|
||||
|
@ -113,8 +113,8 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const Handler& handler) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
auto* job_factory = static_cast<const AtomURLRequestJobFactory*>(
|
||||
request_context_getter->GetURLRequestContext()->job_factory());
|
||||
if (job_factory->IsHandledProtocol(scheme))
|
||||
return PROTOCOL_REGISTERED;
|
||||
auto protocol_handler = std::make_unique<CustomProtocolHandler<RequestJob>>(
|
||||
|
@ -158,13 +158,10 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
v8::Isolate* isolate,
|
||||
const std::string& scheme,
|
||||
const Handler& handler) {
|
||||
auto* job_factory = static_cast<AtomURLRequestJobFactory*>(
|
||||
request_context_getter->job_factory());
|
||||
auto* job_factory = static_cast<const AtomURLRequestJobFactory*>(
|
||||
request_context_getter->GetURLRequestContext()->job_factory());
|
||||
if (!job_factory->IsHandledProtocol(scheme))
|
||||
return PROTOCOL_NOT_REGISTERED;
|
||||
// It is possible a protocol is handled but can not be intercepted.
|
||||
if (!job_factory->HasProtocolHandler(scheme))
|
||||
return PROTOCOL_FAIL;
|
||||
auto protocol_handler = std::make_unique<CustomProtocolHandler<RequestJob>>(
|
||||
isolate, request_context_getter.get(), handler);
|
||||
if (!job_factory->InterceptProtocol(scheme, std::move(protocol_handler)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue