chore: cache URLLoaderFactory per-session (#19998)
* cache the URLLoaderFactory in AtomBrowserContext * use cached loader factory in AtomURLLoaderFactory
This commit is contained in:
parent
eed72c35d7
commit
b3947d6a83
4 changed files with 50 additions and 40 deletions
|
@ -6,15 +6,12 @@
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "content/public/browser/storage_partition.h"
|
|
||||||
#include "mojo/public/cpp/system/string_data_source.h"
|
#include "mojo/public/cpp/system/string_data_source.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/http/http_util.h"
|
#include "net/http/http_util.h"
|
||||||
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
|
||||||
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
||||||
#include "shell/browser/api/atom_api_session.h"
|
#include "shell/browser/api/atom_api_session.h"
|
||||||
#include "shell/browser/atom_browser_client.h"
|
|
||||||
#include "shell/browser/atom_browser_context.h"
|
#include "shell/browser/atom_browser_context.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/net_converter.h"
|
#include "shell/common/native_mate_converters/net_converter.h"
|
||||||
|
@ -181,37 +178,7 @@ URLRequestNS::URLRequestNS(mate::Arguments* args) : weak_factory_(this) {
|
||||||
session = Session::FromPartition(args->isolate(), "");
|
session = Session::FromPartition(args->isolate(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* browser_context = session->browser_context();
|
url_loader_factory_ = session->browser_context()->GetURLLoaderFactory();
|
||||||
auto* storage_partition =
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context);
|
|
||||||
|
|
||||||
network::mojom::URLLoaderFactoryPtr network_factory;
|
|
||||||
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_request =
|
|
||||||
mojo::MakeRequest(&network_factory);
|
|
||||||
|
|
||||||
// Consult the embedder.
|
|
||||||
network::mojom::TrustedURLLoaderHeaderClientPtrInfo header_client;
|
|
||||||
static_cast<content::ContentBrowserClient*>(AtomBrowserClient::Get())
|
|
||||||
->WillCreateURLLoaderFactory(
|
|
||||||
browser_context, nullptr, -1,
|
|
||||||
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
|
||||||
url::Origin(), &factory_request, &header_client, nullptr);
|
|
||||||
|
|
||||||
network::mojom::URLLoaderFactoryParamsPtr params =
|
|
||||||
network::mojom::URLLoaderFactoryParams::New();
|
|
||||||
params->header_client = std::move(header_client);
|
|
||||||
params->process_id = network::mojom::kBrowserProcessId;
|
|
||||||
params->is_trusted = true;
|
|
||||||
params->is_corb_enabled = false;
|
|
||||||
// The tests of net module would fail if this setting is true, it seems that
|
|
||||||
// the non-NetworkService implementation always has web security enabled.
|
|
||||||
params->disable_web_security = false;
|
|
||||||
|
|
||||||
storage_partition->GetNetworkContext()->CreateURLLoaderFactory(
|
|
||||||
std::move(factory_request), std::move(params));
|
|
||||||
url_loader_factory_ =
|
|
||||||
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
|
|
||||||
std::move(network_factory));
|
|
||||||
|
|
||||||
InitWith(args->isolate(), args->GetThis());
|
InitWith(args->isolate(), args->GetThis());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "content/public/browser/storage_partition.h"
|
#include "content/public/browser/storage_partition.h"
|
||||||
#include "net/base/escape.h"
|
#include "net/base/escape.h"
|
||||||
#include "services/network/public/cpp/features.h"
|
#include "services/network/public/cpp/features.h"
|
||||||
|
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
||||||
#include "shell/browser/atom_blob_reader.h"
|
#include "shell/browser/atom_blob_reader.h"
|
||||||
#include "shell/browser/atom_browser_client.h"
|
#include "shell/browser/atom_browser_client.h"
|
||||||
#include "shell/browser/atom_browser_main_parts.h"
|
#include "shell/browser/atom_browser_main_parts.h"
|
||||||
|
@ -271,6 +272,43 @@ predictors::PreconnectManager* AtomBrowserContext::GetPreconnectManager() {
|
||||||
return preconnect_manager_.get();
|
return preconnect_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scoped_refptr<network::SharedURLLoaderFactory>
|
||||||
|
AtomBrowserContext::GetURLLoaderFactory() {
|
||||||
|
if (url_loader_factory_)
|
||||||
|
return url_loader_factory_;
|
||||||
|
|
||||||
|
network::mojom::URLLoaderFactoryPtr network_factory;
|
||||||
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_request =
|
||||||
|
mojo::MakeRequest(&network_factory);
|
||||||
|
|
||||||
|
// Consult the embedder.
|
||||||
|
network::mojom::TrustedURLLoaderHeaderClientPtrInfo header_client;
|
||||||
|
static_cast<content::ContentBrowserClient*>(AtomBrowserClient::Get())
|
||||||
|
->WillCreateURLLoaderFactory(
|
||||||
|
this, nullptr, -1,
|
||||||
|
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
||||||
|
url::Origin(), &factory_request, &header_client, nullptr);
|
||||||
|
|
||||||
|
network::mojom::URLLoaderFactoryParamsPtr params =
|
||||||
|
network::mojom::URLLoaderFactoryParams::New();
|
||||||
|
params->header_client = std::move(header_client);
|
||||||
|
params->process_id = network::mojom::kBrowserProcessId;
|
||||||
|
params->is_trusted = true;
|
||||||
|
params->is_corb_enabled = false;
|
||||||
|
// The tests of net module would fail if this setting is true, it seems that
|
||||||
|
// the non-NetworkService implementation always has web security enabled.
|
||||||
|
params->disable_web_security = false;
|
||||||
|
|
||||||
|
auto* storage_partition =
|
||||||
|
content::BrowserContext::GetDefaultStoragePartition(this);
|
||||||
|
storage_partition->GetNetworkContext()->CreateURLLoaderFactory(
|
||||||
|
std::move(factory_request), std::move(params));
|
||||||
|
url_loader_factory_ =
|
||||||
|
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
|
||||||
|
std::move(network_factory));
|
||||||
|
return url_loader_factory_;
|
||||||
|
}
|
||||||
|
|
||||||
content::PushMessagingService* AtomBrowserContext::GetPushMessagingService() {
|
content::PushMessagingService* AtomBrowserContext::GetPushMessagingService() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,17 @@
|
||||||
#include "content/public/browser/browser_context.h"
|
#include "content/public/browser/browser_context.h"
|
||||||
#include "content/public/browser/resource_context.h"
|
#include "content/public/browser/resource_context.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
|
#include "services/network/public/mojom/url_loader_factory.mojom.h"
|
||||||
#include "shell/browser/media/media_device_id_salt.h"
|
#include "shell/browser/media/media_device_id_salt.h"
|
||||||
|
|
||||||
class PrefRegistrySimple;
|
class PrefRegistrySimple;
|
||||||
class PrefService;
|
class PrefService;
|
||||||
class ValueMapPrefStore;
|
class ValueMapPrefStore;
|
||||||
|
|
||||||
|
namespace network {
|
||||||
|
class SharedURLLoaderFactory;
|
||||||
|
}
|
||||||
|
|
||||||
namespace storage {
|
namespace storage {
|
||||||
class SpecialStoragePolicy;
|
class SpecialStoragePolicy;
|
||||||
}
|
}
|
||||||
|
@ -87,8 +92,8 @@ class AtomBrowserContext
|
||||||
int GetMaxCacheSize() const;
|
int GetMaxCacheSize() const;
|
||||||
AtomBlobReader* GetBlobReader();
|
AtomBlobReader* GetBlobReader();
|
||||||
ResolveProxyHelper* GetResolveProxyHelper();
|
ResolveProxyHelper* GetResolveProxyHelper();
|
||||||
|
|
||||||
predictors::PreconnectManager* GetPreconnectManager();
|
predictors::PreconnectManager* GetPreconnectManager();
|
||||||
|
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory();
|
||||||
|
|
||||||
// content::BrowserContext:
|
// content::BrowserContext:
|
||||||
base::FilePath GetPath() override;
|
base::FilePath GetPath() override;
|
||||||
|
@ -180,6 +185,9 @@ class AtomBrowserContext
|
||||||
extensions::AtomExtensionSystem* extension_system_;
|
extensions::AtomExtensionSystem* extension_system_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Shared URLLoaderFactory.
|
||||||
|
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
|
||||||
|
|
||||||
base::WeakPtrFactory<AtomBrowserContext> weak_factory_;
|
base::WeakPtrFactory<AtomBrowserContext> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
|
||||||
|
|
|
@ -396,12 +396,9 @@ void AtomURLLoaderFactory::StartLoadingHttp(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory =
|
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context.get())
|
|
||||||
->GetURLLoaderFactoryForBrowserProcess();
|
|
||||||
new URLPipeLoader(
|
new URLPipeLoader(
|
||||||
url_loader_factory, std::move(request), std::move(loader),
|
browser_context->GetURLLoaderFactory(), std::move(request),
|
||||||
std::move(client),
|
std::move(loader), std::move(client),
|
||||||
static_cast<net::NetworkTrafficAnnotationTag>(traffic_annotation),
|
static_cast<net::NetworkTrafficAnnotationTag>(traffic_annotation),
|
||||||
std::move(upload_data));
|
std::move(upload_data));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue