зеркало из https://github.com/electron/electron.git
Avoid storing JobFactory in BrowserContext
JobFactory should always be created and accessed in IO thread.
This commit is contained in:
Родитель
9372d4df32
Коммит
659384383e
|
@ -27,10 +27,8 @@ namespace atom {
|
|||
namespace api {
|
||||
|
||||
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
||||
: browser_context_(browser_context),
|
||||
request_context_getter_(browser_context->GetRequestContext()),
|
||||
: request_context_getter_(browser_context->GetRequestContext()),
|
||||
weak_factory_(this) {
|
||||
CHECK(job_factory());
|
||||
Init(isolate);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,16 +19,12 @@
|
|||
#include "native_mate/arguments.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
}
|
||||
|
||||
namespace net {
|
||||
class URLRequest;
|
||||
class URLRequestContextGetter;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
@ -50,7 +46,10 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
|
||||
AtomURLRequestJobFactory* job_factory() const {
|
||||
return browser_context_->job_factory();
|
||||
request_context_getter_->GetURLRequestContext(); // Force init.
|
||||
return static_cast<AtomURLRequestJobFactory*>(
|
||||
static_cast<brightray::URLRequestContextGetter*>(
|
||||
request_context_getter_.get())->job_factory());
|
||||
}
|
||||
|
||||
base::WeakPtr<Protocol> GetWeakPtr() {
|
||||
|
@ -123,7 +122,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
return PROTOCOL_REGISTERED;
|
||||
std::unique_ptr<CustomProtocolHandler<RequestJob>> protocol_handler(
|
||||
new CustomProtocolHandler<RequestJob>(
|
||||
isolate(), request_context_getter_, handler));
|
||||
isolate(), request_context_getter_.get(), handler));
|
||||
if (job_factory()->SetProtocolHandler(scheme, std::move(protocol_handler)))
|
||||
return PROTOCOL_OK;
|
||||
else
|
||||
|
@ -165,7 +164,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
return PROTOCOL_INTERCEPTED;
|
||||
std::unique_ptr<CustomProtocolHandler<RequestJob>> protocol_handler(
|
||||
new CustomProtocolHandler<RequestJob>(
|
||||
isolate(), request_context_getter_, handler));
|
||||
isolate(), request_context_getter_.get(), handler));
|
||||
original_protocols_.set(
|
||||
scheme,
|
||||
job_factory()->ReplaceProtocol(scheme, std::move(protocol_handler)));
|
||||
|
@ -182,8 +181,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
|||
// Convert error code to string.
|
||||
std::string ErrorCodeToString(ProtocolError error);
|
||||
|
||||
scoped_refptr<AtomBrowserContext> browser_context_;
|
||||
net::URLRequestContextGetter* request_context_getter_;
|
||||
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
|
||||
|
||||
// Map that stores the original protocols of schemes.
|
||||
using OriginalProtocolsMap = base::ScopedPtrHashMap<
|
||||
|
|
|
@ -20,14 +20,15 @@
|
|||
#include "atom/common/options_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "base/threading/worker_pool.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
|
@ -66,7 +67,6 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
|||
bool in_memory)
|
||||
: brightray::BrowserContext(partition, in_memory),
|
||||
cert_verifier_(new AtomCertVerifier),
|
||||
job_factory_(new AtomURLRequestJobFactory),
|
||||
network_delegate_(new AtomNetworkDelegate) {
|
||||
}
|
||||
|
||||
|
@ -96,15 +96,15 @@ std::string AtomBrowserContext::GetUserAgent() {
|
|||
|
||||
std::unique_ptr<net::URLRequestJobFactory>
|
||||
AtomBrowserContext::CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* handlers,
|
||||
content::URLRequestInterceptorScopedVector* interceptors) {
|
||||
std::unique_ptr<AtomURLRequestJobFactory> job_factory(job_factory_);
|
||||
content::ProtocolHandlerMap* protocol_handlers) {
|
||||
std::unique_ptr<AtomURLRequestJobFactory> job_factory(
|
||||
new AtomURLRequestJobFactory);
|
||||
|
||||
for (auto& it : *handlers) {
|
||||
for (auto& it : *protocol_handlers) {
|
||||
job_factory->SetProtocolHandler(it.first,
|
||||
make_scoped_ptr(it.second.release()));
|
||||
base::WrapUnique(it.second.release()));
|
||||
}
|
||||
handlers->clear();
|
||||
protocol_handlers->clear();
|
||||
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler));
|
||||
|
@ -132,16 +132,7 @@ AtomBrowserContext::CreateURLRequestJobFactory(
|
|||
make_scoped_ptr(new net::FtpProtocolHandler(
|
||||
new net::FtpNetworkLayer(host_resolver))));
|
||||
|
||||
// Set up interceptors in the reverse order.
|
||||
std::unique_ptr<net::URLRequestJobFactory> top_job_factory =
|
||||
std::move(job_factory);
|
||||
content::URLRequestInterceptorScopedVector::reverse_iterator it;
|
||||
for (it = interceptors->rbegin(); it != interceptors->rend(); ++it)
|
||||
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
||||
std::move(top_job_factory), make_scoped_ptr(*it)));
|
||||
interceptors->weak_clear();
|
||||
|
||||
return top_job_factory;
|
||||
return std::move(job_factory);
|
||||
}
|
||||
|
||||
net::HttpCache::BackendFactory*
|
||||
|
|
|
@ -15,7 +15,6 @@ class AtomDownloadManagerDelegate;
|
|||
class AtomCertVerifier;
|
||||
class AtomNetworkDelegate;
|
||||
class AtomPermissionManager;
|
||||
class AtomURLRequestJobFactory;
|
||||
class WebViewManager;
|
||||
|
||||
class AtomBrowserContext : public brightray::BrowserContext {
|
||||
|
@ -27,8 +26,7 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
|||
net::NetworkDelegate* CreateNetworkDelegate() override;
|
||||
std::string GetUserAgent() override;
|
||||
std::unique_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory(
|
||||
content::ProtocolHandlerMap* handlers,
|
||||
content::URLRequestInterceptorScopedVector* interceptors) override;
|
||||
content::ProtocolHandlerMap* protocol_handlers) override;
|
||||
net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory(
|
||||
const base::FilePath& base_path) override;
|
||||
std::unique_ptr<net::CertVerifier> CreateCertVerifier() override;
|
||||
|
@ -43,9 +41,6 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
|||
void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
|
||||
|
||||
AtomCertVerifier* cert_verifier() const { return cert_verifier_; }
|
||||
|
||||
AtomURLRequestJobFactory* job_factory() const { return job_factory_; }
|
||||
|
||||
AtomNetworkDelegate* network_delegate() const { return network_delegate_; }
|
||||
|
||||
private:
|
||||
|
@ -55,7 +50,6 @@ class AtomBrowserContext : public brightray::BrowserContext {
|
|||
|
||||
// Managed by brightray::BrowserContext.
|
||||
AtomCertVerifier* cert_verifier_;
|
||||
AtomURLRequestJobFactory* job_factory_;
|
||||
AtomNetworkDelegate* network_delegate_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 55423bdca586a20fe052f6c0e19565710dcebd42
|
||||
Subproject commit 717d92968d7959814060b9409c4720ab647bd90e
|
Загрузка…
Ссылка в новой задаче