Commit 4c6e1a05 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

NetS13nSW: Initialize URLLoaderFactoryGetter properly

Previously, URLLoaderFactoryGetter expects that the NetworkContext is ready when
it's initialized (URLLoaderFactoryGetter::Initialize()). However, when
ServiceWorkerServicification is on without NetworkService, the initialization
fails because URLRequestContext which is necessary to create a dummy
NetworkContext is not set at that point.
This CL splits the initialization process into two parts: creating valid
InterfacePtrs (URLLoaderFactoryGetter::Initialize()) and passing the
InterfaceRequests to the appropriate places
(URLLoaderFactoryGetter::EstablishConnection()).  NetworkContext is used only
for the latter, so EstablishConnection() is called after URLRequestContext is
set if ServiceWorkerServicification is on without NetworkService.

Bug: 829251
Change-Id: I5fbbaa2d48232965681fc96d802711369cd96528
Reviewed-on: https://chromium-review.googlesource.com/1025490Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553405}
parent 668481a7
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "content/browser/streams/stream_registry.h" #include "content/browser/streams/stream_registry.h"
#include "content/browser/streams/stream_url_request_job.h" #include "content/browser/streams/stream_url_request_job.h"
#include "content/browser/webui/url_data_manager_backend.h" #include "content/browser/webui/url_data_manager_backend.h"
#include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
#include "crypto/sha2.h" #include "crypto/sha2.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/features.h"
#include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/blob_url_request_job_factory.h" #include "storage/browser/blob/blob_url_request_job_factory.h"
#include "storage/browser/fileapi/file_system_url_request_job_factory.h" #include "storage/browser/fileapi/file_system_url_request_job_factory.h"
...@@ -435,6 +437,17 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( ...@@ -435,6 +437,17 @@ StoragePartitionImpl* StoragePartitionImplMap::Get(
browser_context_->CreateMediaRequestContextForStoragePartition( browser_context_->CreateMediaRequestContextForStoragePartition(
partition->GetPath(), in_memory)); partition->GetPath(), in_memory));
if (ServiceWorkerUtils::IsServicificationEnabled() &&
!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
// This needs to happen after SetURLRequestContext() since we need this
// code path only for non-NetworkService case where NetworkContext needs to
// be initialized using |url_request_context_|, which is initialized by
// SetURLRequestContext().
DCHECK(partition->url_loader_factory_getter());
DCHECK(partition->url_request_context_);
partition->url_loader_factory_getter()->HandleFactoryRequests();
}
PostCreateInitialization(partition, in_memory); PostCreateInitialization(partition, in_memory);
return partition; return partition;
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/feature_list.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/network_service.mojom.h" #include "services/network/public/mojom/network_service.mojom.h"
...@@ -107,14 +109,19 @@ URLLoaderFactoryGetter::URLLoaderFactoryGetter() {} ...@@ -107,14 +109,19 @@ URLLoaderFactoryGetter::URLLoaderFactoryGetter() {}
void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) { void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) {
DCHECK(partition); DCHECK(partition);
partition_ = partition; DCHECK(!pending_network_factory_request_.is_pending());
DCHECK(!pending_blob_factory_request_.is_pending());
partition_ = partition;
network::mojom::URLLoaderFactoryPtr network_factory; network::mojom::URLLoaderFactoryPtr network_factory;
HandleNetworkFactoryRequestOnUIThread(MakeRequest(&network_factory));
network::mojom::URLLoaderFactoryPtr blob_factory; network::mojom::URLLoaderFactoryPtr blob_factory;
partition_->GetBlobURLLoaderFactory()->HandleRequest( pending_network_factory_request_ = MakeRequest(&network_factory);
mojo::MakeRequest(&blob_factory)); pending_blob_factory_request_ = mojo::MakeRequest(&blob_factory);
// If NetworkService is disabled, HandleFactoryRequests should be called after
// NetworkContext in |partition_| is ready.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
HandleFactoryRequests();
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
...@@ -123,6 +130,16 @@ void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) { ...@@ -123,6 +130,16 @@ void URLLoaderFactoryGetter::Initialize(StoragePartitionImpl* partition) {
blob_factory.PassInterface())); blob_factory.PassInterface()));
} }
void URLLoaderFactoryGetter::HandleFactoryRequests() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(pending_network_factory_request_.is_pending());
DCHECK(pending_blob_factory_request_.is_pending());
HandleNetworkFactoryRequestOnUIThread(
std::move(pending_network_factory_request_));
partition_->GetBlobURLLoaderFactory()->HandleRequest(
std::move(pending_blob_factory_request_));
}
void URLLoaderFactoryGetter::OnStoragePartitionDestroyed() { void URLLoaderFactoryGetter::OnStoragePartitionDestroyed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
partition_ = nullptr; partition_ = nullptr;
......
...@@ -31,10 +31,19 @@ class URLLoaderFactoryGetter ...@@ -31,10 +31,19 @@ class URLLoaderFactoryGetter
CONTENT_EXPORT URLLoaderFactoryGetter(); CONTENT_EXPORT URLLoaderFactoryGetter();
// Initializes this object on the UI thread. The |partition| is used to // Initializes this object on the UI thread. The |partition| is used to
// initialize the URLLoaderFactories for the network service and AppCache, and // initialize the URLLoaderFactories for the network service, AppCache, and
// will be cached to recover from connection error. // ServiceWorkers, and will be cached to recover from connection error.
// After Initialize(), you can get URLLoaderFactories from this
// getter. However, any messages on it will be queued until
// HandleFactoryRequests() is called.
void Initialize(StoragePartitionImpl* partition); void Initialize(StoragePartitionImpl* partition);
// Called on the UI thread to actually instantiate factories whose pointers
// are to be exposed by this getter. This must be called after NetworkContext
// is initialized.
// TODO(shimazu): Remove this once NetworkService is shipped.
void HandleFactoryRequests();
// Clear the cached pointer to |StoragePartitionImpl| on the UI thread. Should // Clear the cached pointer to |StoragePartitionImpl| on the UI thread. Should
// be called when the partition is going away. // be called when the partition is going away.
void OnStoragePartitionDestroyed(); void OnStoragePartitionDestroyed();
...@@ -106,6 +115,10 @@ class URLLoaderFactoryGetter ...@@ -106,6 +115,10 @@ class URLLoaderFactoryGetter
// Call |network_factory_.FlushForTesting()|. For test use only. // Call |network_factory_.FlushForTesting()|. For test use only.
void FlushNetworkInterfaceForTesting(); void FlushNetworkInterfaceForTesting();
// Bound with appropriate URLLoaderFactories at HandleFactoryRequests().
network::mojom::URLLoaderFactoryRequest pending_network_factory_request_;
network::mojom::URLLoaderFactoryRequest pending_blob_factory_request_;
// Only accessed on IO thread. // Only accessed on IO thread.
network::mojom::URLLoaderFactoryPtr network_factory_; network::mojom::URLLoaderFactoryPtr network_factory_;
network::mojom::URLLoaderFactoryPtr blob_factory_; network::mojom::URLLoaderFactoryPtr blob_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment