зеркало из https://github.com/electron/electron.git
re-use request context from IOThread
This commit is contained in:
Родитель
97fcf7079b
Коммит
c3f8f6bc42
|
@ -47,9 +47,6 @@
|
|||
#include "content/public/common/url_constants.h"
|
||||
#include "content/public/common/web_preferences.h"
|
||||
#include "net/ssl/ssl_cert_request_info.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_builder.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
@ -69,45 +66,6 @@ std::string g_custom_service_worker_schemes = "";
|
|||
void Noop(scoped_refptr<content::SiteInstance>) {
|
||||
}
|
||||
|
||||
class GeoURLRequestContextGetter : public net::URLRequestContextGetter {
|
||||
public:
|
||||
GeoURLRequestContextGetter() = default;
|
||||
~GeoURLRequestContextGetter() override {
|
||||
if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&GeoURLRequestContextGetter::NotifyContextShutdownOnIO,
|
||||
this));
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyContextShutdownOnIO() {
|
||||
url_request_context_.reset();
|
||||
net::URLRequestContextGetter::NotifyContextShuttingDown();
|
||||
}
|
||||
|
||||
net::URLRequestContext* GetURLRequestContext() override {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
if (!url_request_context_.get()) {
|
||||
net::URLRequestContextBuilder builder;
|
||||
builder.set_proxy_config_service(
|
||||
net::ProxyService::CreateSystemProxyConfigService(
|
||||
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
|
||||
url_request_context_ = builder.Build();
|
||||
}
|
||||
return url_request_context_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
|
||||
const override {
|
||||
return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<net::URLRequestContext> url_request_context_;
|
||||
DISALLOW_COPY_AND_ASSIGN(GeoURLRequestContextGetter);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
|
@ -120,9 +78,7 @@ void AtomBrowserClient::SetCustomServiceWorkerSchemes(
|
|||
g_custom_service_worker_schemes = base::JoinString(schemes, ",");
|
||||
}
|
||||
|
||||
AtomBrowserClient::AtomBrowserClient()
|
||||
: delegate_(nullptr),
|
||||
geo_request_context_getter_(new GeoURLRequestContextGetter) {}
|
||||
AtomBrowserClient::AtomBrowserClient() : delegate_(nullptr) {}
|
||||
|
||||
AtomBrowserClient::~AtomBrowserClient() {
|
||||
}
|
||||
|
@ -384,20 +340,14 @@ void AtomBrowserClient::DidCreatePpapiPlugin(
|
|||
base::WrapUnique(new chrome::ChromeBrowserPepperHostFactory(host)));
|
||||
}
|
||||
|
||||
scoped_refptr<net::URLRequestContextGetter>
|
||||
AtomBrowserClient::GetGeoRequestContextGetterFromUIThread() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
return geo_request_context_getter_;
|
||||
}
|
||||
|
||||
void AtomBrowserClient::GetGeolocationRequestContext(
|
||||
base::OnceCallback<void(scoped_refptr<net::URLRequestContextGetter>)>
|
||||
callback) {
|
||||
BrowserThread::PostTaskAndReplyWithResult(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::BindOnce(&AtomBrowserClient::GetGeoRequestContextGetterFromUIThread,
|
||||
base::Unretained(this)),
|
||||
std::move(callback));
|
||||
auto io_thread = AtomBrowserMainParts::Get()->io_thread();
|
||||
auto context = io_thread->GetRequestContext();
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(std::move(callback), base::RetainedRef(context)));
|
||||
}
|
||||
|
||||
std::string AtomBrowserClient::GetGeolocationApiKey() {
|
||||
|
|
|
@ -21,7 +21,6 @@ class ClientCertificateDelegate;
|
|||
|
||||
namespace net {
|
||||
class SSLCertRequestInfo;
|
||||
class URLRequestContextGetter;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
@ -134,8 +133,6 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
bool IsRendererSandboxed(int process_id);
|
||||
bool RendererUsesNativeWindowOpen(int process_id);
|
||||
bool RendererDisablesPopups(int process_id);
|
||||
scoped_refptr<net::URLRequestContextGetter>
|
||||
GetGeoRequestContextGetterFromUIThread();
|
||||
|
||||
// pending_render_process => web contents.
|
||||
std::map<int, content::WebContents*> pending_processes_;
|
||||
|
@ -151,8 +148,6 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
|
||||
Delegate* delegate_;
|
||||
|
||||
scoped_refptr<net::URLRequestContextGetter> geo_request_context_getter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient);
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ class BrowserMainParts : public content::BrowserMainParts {
|
|||
BrowserMainParts();
|
||||
~BrowserMainParts();
|
||||
|
||||
IOThread* io_thread() const { return io_thread_.get(); }
|
||||
|
||||
protected:
|
||||
// content::BrowserMainParts:
|
||||
void PreEarlyInitialization() override;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "net/proxy/proxy_service.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_builder.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
#include "net/cert_net/nss_ocsp.h"
|
||||
|
@ -28,8 +29,10 @@ IOThread::~IOThread() {
|
|||
void IOThread::Init() {
|
||||
net::URLRequestContextBuilder builder;
|
||||
builder.set_proxy_service(net::ProxyService::CreateDirect());
|
||||
builder.DisableHttpCache();
|
||||
url_request_context_ = builder.Build();
|
||||
url_request_context_getter_ = new net::TrivialURLRequestContextGetter(
|
||||
url_request_context_.get(), base::ThreadTaskRunnerHandle::Get());
|
||||
url_request_context_getter_->AddRef();
|
||||
|
||||
#if defined(USE_NSS_CERTS)
|
||||
net::SetMessageLoopForNSSHttpIO();
|
||||
|
@ -42,6 +45,8 @@ void IOThread::CleanUp() {
|
|||
net::ShutdownNSSHttpIO();
|
||||
net::SetURLRequestContextForNSSHttpIO(nullptr);
|
||||
#endif
|
||||
// Explicitly release before the IO thread gets destroyed.
|
||||
url_request_context_getter_->Release();
|
||||
url_request_context_.reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace net {
|
||||
class URLRequestContext;
|
||||
class URLRequestContextGetter;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
@ -21,6 +22,10 @@ class IOThread : public content::BrowserThreadDelegate {
|
|||
IOThread();
|
||||
~IOThread() override;
|
||||
|
||||
net::URLRequestContextGetter* GetRequestContext() {
|
||||
return url_request_context_getter_;
|
||||
}
|
||||
|
||||
protected:
|
||||
// BrowserThreadDelegate Implementation, runs on the IO thread.
|
||||
void Init() override;
|
||||
|
@ -28,6 +33,7 @@ class IOThread : public content::BrowserThreadDelegate {
|
|||
|
||||
private:
|
||||
std::unique_ptr<net::URLRequestContext> url_request_context_;
|
||||
net::URLRequestContextGetter* url_request_context_getter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IOThread);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче