Commit 2ec63638 authored by ananta's avatar ananta Committed by Commit Bot

Add support for subresource request fallback in AppCache for the network service..

This patch builds on patch https://codereview.chromium.org/2956373002/ for adding fallback
support for subresource requests. This is implemented by passing a proxy URLLoaderClient
interface to the network URL service for subresource requests which are sent to the network.
We intercept the OnReceiveResponse, OnReceiveRedirect and OnComplete calls for supporting
fallback responses in these cases. We could potentially look at moving fallback response
reading to the renderer in a later patchset.

The changes in this patchset are as below:
1. Add support for passing the ResourceResponseHead to the AppCacheURLLoaderJob. This is
   required for supporting fallback responses. The request handler looks at headers in
   the response and the status code to make a call whether a fallback is required.

2. AppCacheRequestHandler::MaybeLoadFallbackForResponse() and MaybeLoadFallbackForRedirect() have
   changed to allow for the fact that they are called in the network service code by the
   AppCacheURLLoaderJob. We don't create new job for delivering the fallback in this case.

3. Added methods in the AppCacheRequest class  to return the URLRequest override and URLLoader
   override respectively.

Next step is to add support for main resource fallback.

BUG=715632

Review-Url: https://codereview.chromium.org/2974733002
Cr-Commit-Position: refs/heads/master@{#487640}
parent d654e49c
...@@ -25,8 +25,8 @@ std::unique_ptr<AppCacheJob> AppCacheJob::Create( ...@@ -25,8 +25,8 @@ std::unique_ptr<AppCacheJob> AppCacheJob::Create(
const OnPrepareToRestartCallback& restart_callback) { const OnPrepareToRestartCallback& restart_callback) {
std::unique_ptr<AppCacheJob> job; std::unique_ptr<AppCacheJob> job;
if (base::FeatureList::IsEnabled(features::kNetworkService)) { if (base::FeatureList::IsEnabled(features::kNetworkService)) {
job.reset( job.reset(new AppCacheURLLoaderJob(*(request->GetResourceRequest()),
new AppCacheURLLoaderJob(*(request->GetResourceRequest()), storage)); request->AsURLLoaderRequest(), storage));
} else { } else {
job.reset(new AppCacheURLRequestJob(request->GetURLRequest(), job.reset(new AppCacheURLRequestJob(request->GetURLRequest(),
network_delegate, storage, host, network_delegate, storage, host,
......
...@@ -27,4 +27,12 @@ ResourceRequest* AppCacheRequest::GetResourceRequest() { ...@@ -27,4 +27,12 @@ ResourceRequest* AppCacheRequest::GetResourceRequest() {
return nullptr; return nullptr;
} }
AppCacheURLRequest* AppCacheRequest::AsURLRequest() {
return nullptr;
}
AppCacheURLLoaderRequest* AppCacheRequest::AsURLLoaderRequest() {
return nullptr;
}
} // namespace content } // namespace content
...@@ -16,6 +16,8 @@ class URLRequest; ...@@ -16,6 +16,8 @@ class URLRequest;
} }
namespace content { namespace content {
class AppCacheURLLoaderRequest;
class AppCacheURLRequest;
struct ResourceRequest; struct ResourceRequest;
// Interface for an AppCache request. Subclasses implement this interface to // Interface for an AppCache request. Subclasses implement this interface to
...@@ -58,6 +60,14 @@ class CONTENT_EXPORT AppCacheRequest { ...@@ -58,6 +60,14 @@ class CONTENT_EXPORT AppCacheRequest {
static bool IsSchemeAndMethodSupportedForAppCache( static bool IsSchemeAndMethodSupportedForAppCache(
const AppCacheRequest* request); const AppCacheRequest* request);
// Returns the underlying AppCacheURLRequest if any. This only applies to
// AppCache requests loaded via the URLRequest mechanism
virtual AppCacheURLRequest* AsURLRequest();
// Returns the underlying AppCacheURLLoaderRequest if any. This only applies
// to AppCache requests loaded via the URLLoader mechanism.
virtual AppCacheURLLoaderRequest* AsURLLoaderRequest();
protected: protected:
friend class AppCacheRequestHandler; friend class AppCacheRequestHandler;
// Enables the AppCacheJob to call GetURLRequest() and GetResourceRequest(). // Enables the AppCacheJob to call GetURLRequest() and GetResourceRequest().
......
...@@ -127,19 +127,24 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( ...@@ -127,19 +127,24 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect(
if (request_->GetURL().GetOrigin() == location.GetOrigin()) if (request_->GetURL().GetOrigin() == location.GetOrigin())
return NULL; return NULL;
DCHECK(!job_.get()); // our jobs never generate redirects // In network service land, the existing job initiates a fallback request.
if (!base::FeatureList::IsEnabled(features::kNetworkService)) {
DCHECK(!job_.get()); // our jobs never generate redirects
} else {
DCHECK(job_.get());
}
std::unique_ptr<AppCacheJob> job; std::unique_ptr<AppCacheJob> job;
if (found_fallback_entry_.has_response_id()) { if (found_fallback_entry_.has_response_id()) {
job = MaybeCreateJobForFallback(network_delegate);
// 6.9.6, step 4: If this results in a redirect to another origin, // 6.9.6, step 4: If this results in a redirect to another origin,
// get the resource of the fallback entry. // get the resource of the fallback entry.
job = CreateJob(network_delegate);
DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_,
found_manifest_url_, true, found_manifest_url_, true,
found_namespace_entry_url_); found_namespace_entry_url_);
} else if (!found_network_namespace_) { } else if (!found_network_namespace_) {
// 6.9.6, step 6: Fail the resource load. // 6.9.6, step 6: Fail the resource load.
job = CreateJob(network_delegate); job = MaybeCreateJobForFallback(network_delegate);
DeliverErrorResponse(); DeliverErrorResponse();
} else { } else {
// 6.9.6 step 3 and 5: Fetch the resource normally. // 6.9.6 step 3 and 5: Fetch the resource normally.
...@@ -163,7 +168,7 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( ...@@ -163,7 +168,7 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse(
} }
// We don't fallback for responses that we delivered. // We don't fallback for responses that we delivered.
if (job_.get()) { if (job_.get() && !base::FeatureList::IsEnabled(features::kNetworkService)) {
DCHECK(!job_->IsDeliveringNetworkResponse()); DCHECK(!job_->IsDeliveringNetworkResponse());
return NULL; return NULL;
} }
...@@ -186,7 +191,12 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( ...@@ -186,7 +191,12 @@ AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse(
// 6.9.6, step 4: If this results in a 4xx or 5xx status code // 6.9.6, step 4: If this results in a 4xx or 5xx status code
// or there were network errors, get the resource of the fallback entry. // or there were network errors, get the resource of the fallback entry.
std::unique_ptr<AppCacheJob> job = CreateJob(network_delegate);
// In network service land, the job initiates a fallback request. We reuse
// the existing job to deliver the fallback response.
std::unique_ptr<AppCacheJob> job =
MaybeCreateJobForFallback(network_delegate);
DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_,
found_manifest_url_, true, found_manifest_url_, true,
found_namespace_entry_url_); found_namespace_entry_url_);
...@@ -342,6 +352,16 @@ std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( ...@@ -342,6 +352,16 @@ std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob(
return job; return job;
} }
std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback(
net::NetworkDelegate* network_delegate) {
if (!base::FeatureList::IsEnabled(features::kNetworkService))
return CreateJob(network_delegate);
// In network service land, the job initiates a fallback request. We reuse
// the existing job to deliver the fallback response.
DCHECK(job_.get());
return std::unique_ptr<AppCacheJob>(job_.get());
}
// Main-resource handling ---------------------------------------------- // Main-resource handling ----------------------------------------------
std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
......
...@@ -124,6 +124,10 @@ class CONTENT_EXPORT AppCacheRequestHandler ...@@ -124,6 +124,10 @@ class CONTENT_EXPORT AppCacheRequestHandler
std::unique_ptr<AppCacheJob> CreateJob( std::unique_ptr<AppCacheJob> CreateJob(
net::NetworkDelegate* network_delegate); net::NetworkDelegate* network_delegate);
// Helper method to create an AppCacheJob for fallback responses.
std::unique_ptr<AppCacheJob> MaybeCreateJobForFallback(
net::NetworkDelegate* network_delegate);
// Helper to retrieve a pointer to the storage object. // Helper to retrieve a pointer to the storage object.
AppCacheStorage* storage() const; AppCacheStorage* storage() const;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "content/browser/appcache/appcache_histograms.h" #include "content/browser/appcache/appcache_histograms.h"
#include "content/browser/appcache/appcache_subresource_url_factory.h" #include "content/browser/appcache/appcache_subresource_url_factory.h"
#include "content/browser/appcache/appcache_url_loader_request.h"
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
#include "content/common/net_adapters.h" #include "content/common/net_adapters.h"
#include "content/public/common/resource_type.h" #include "content/public/common/resource_type.h"
...@@ -76,13 +77,16 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() { ...@@ -76,13 +77,16 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() {
// request. The loader callback is valid only for navigation requests. // request. The loader callback is valid only for navigation requests.
std::move(main_resource_loader_callback_).Run(StartLoaderCallback()); std::move(main_resource_loader_callback_).Run(StartLoaderCallback());
} else { } else {
mojom::URLLoaderClientPtr client_ptr;
network_loader_client_binding_.Bind(mojo::MakeRequest(&client_ptr));
default_url_loader_factory_getter_->GetNetworkFactory() default_url_loader_factory_getter_->GetNetworkFactory()
->get() ->get()
->CreateLoaderAndStart( ->CreateLoaderAndStart(
mojo::MakeRequest(&network_loader_request_), mojo::MakeRequest(&network_loader_),
subresource_load_info_->routing_id, subresource_load_info_->routing_id,
subresource_load_info_->request_id, subresource_load_info_->options, subresource_load_info_->request_id, subresource_load_info_->options,
subresource_load_info_->request, std::move(client_info_), subresource_load_info_->request, std::move(client_ptr),
subresource_load_info_->traffic_annotation); subresource_load_info_->traffic_annotation);
} }
} }
...@@ -91,7 +95,7 @@ void AppCacheURLLoaderJob::DeliverErrorResponse() { ...@@ -91,7 +95,7 @@ void AppCacheURLLoaderJob::DeliverErrorResponse() {
delivery_type_ = ERROR_DELIVERY; delivery_type_ = ERROR_DELIVERY;
// We expect the URLLoaderClient pointer to be valid at this point. // We expect the URLLoaderClient pointer to be valid at this point.
DCHECK(client_info_); DCHECK(client_);
// AppCacheURLRequestJob uses ERR_FAILED as the error code here. That seems // AppCacheURLRequestJob uses ERR_FAILED as the error code here. That seems
// to map to HTTP_INTERNAL_SERVER_ERROR. // to map to HTTP_INTERNAL_SERVER_ERROR.
...@@ -103,7 +107,7 @@ void AppCacheURLLoaderJob::DeliverErrorResponse() { ...@@ -103,7 +107,7 @@ void AppCacheURLLoaderJob::DeliverErrorResponse() {
ResourceResponseHead response; ResourceResponseHead response;
response.headers = new net::HttpResponseHeaders(status); response.headers = new net::HttpResponseHeaders(status);
client_info_->OnReceiveResponse(response, base::nullopt, nullptr); client_->OnReceiveResponse(response, base::nullopt, nullptr);
NotifyCompleted(net::ERR_FAILED); NotifyCompleted(net::ERR_FAILED);
...@@ -120,14 +124,90 @@ AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() { ...@@ -120,14 +124,90 @@ AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() {
} }
void AppCacheURLLoaderJob::FollowRedirect() { void AppCacheURLLoaderJob::FollowRedirect() {
if (network_loader_request_) if (network_loader_)
network_loader_request_->FollowRedirect(); network_loader_->FollowRedirect();
} }
void AppCacheURLLoaderJob::SetPriority(net::RequestPriority priority, void AppCacheURLLoaderJob::SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) { int32_t intra_priority_value) {
if (network_loader_request_) if (network_loader_)
network_loader_request_->SetPriority(priority, intra_priority_value); network_loader_->SetPriority(priority, intra_priority_value);
}
void AppCacheURLLoaderJob::OnReceiveResponse(
const ResourceResponseHead& response_head,
const base::Optional<net::SSLInfo>& ssl_info,
mojom::DownloadedTempFilePtr downloaded_file) {
appcache_request_->set_response(response_head);
// The MaybeLoadFallbackForResponse() call below can pass a fallback
// response to us. Reset the delivery_type_ to ensure that we can
// receive it
delivery_type_ = AWAITING_DELIVERY_ORDERS;
if (!sub_resource_handler_->MaybeLoadFallbackForResponse(nullptr)) {
client_->OnReceiveResponse(response_head, ssl_info,
std::move(downloaded_file));
} else {
// Disconnect from the network loader as we are delivering a fallback
// response to the client.
DisconnectFromNetworkLoader();
}
}
void AppCacheURLLoaderJob::OnReceiveRedirect(
const net::RedirectInfo& redirect_info,
const ResourceResponseHead& response_head) {
appcache_request_->set_response(response_head);
// The MaybeLoadFallbackForRedirect() call below can pass a fallback
// response to us. Reset the delivery_type_ to ensure that we can
// receive it
delivery_type_ = AWAITING_DELIVERY_ORDERS;
if (!sub_resource_handler_->MaybeLoadFallbackForRedirect(
nullptr, redirect_info.new_url)) {
client_->OnReceiveRedirect(redirect_info, response_head);
} else {
// Disconnect from the network loader as we are delivering a fallback
// response to the client.
DisconnectFromNetworkLoader();
}
}
void AppCacheURLLoaderJob::OnDataDownloaded(int64_t data_len,
int64_t encoded_data_len) {
client_->OnDataDownloaded(data_len, encoded_data_len);
}
void AppCacheURLLoaderJob::OnUploadProgress(
int64_t current_position,
int64_t total_size,
OnUploadProgressCallback ack_callback) {
client_->OnUploadProgress(current_position, total_size,
std::move(ack_callback));
}
void AppCacheURLLoaderJob::OnReceiveCachedMetadata(
const std::vector<uint8_t>& data) {
client_->OnReceiveCachedMetadata(data);
}
void AppCacheURLLoaderJob::OnTransferSizeUpdated(int32_t transfer_size_diff) {
client_->OnTransferSizeUpdated(transfer_size_diff);
}
void AppCacheURLLoaderJob::OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body) {
client_->OnStartLoadingResponseBody(std::move(body));
}
void AppCacheURLLoaderJob::OnComplete(
const ResourceRequestCompletionStatus& status) {
delivery_type_ = AWAITING_DELIVERY_ORDERS;
if (!sub_resource_handler_->MaybeLoadFallbackForResponse(nullptr)) {
client_->OnComplete(status);
} else {
// Disconnect from the network loader as we are delivering a fallback
// response to the client.
DisconnectFromNetworkLoader();
}
} }
void AppCacheURLLoaderJob::SetSubresourceLoadInfo( void AppCacheURLLoaderJob::SetSubresourceLoadInfo(
...@@ -140,7 +220,7 @@ void AppCacheURLLoaderJob::SetSubresourceLoadInfo( ...@@ -140,7 +220,7 @@ void AppCacheURLLoaderJob::SetSubresourceLoadInfo(
associated_binding_->set_connection_error_handler(base::Bind( associated_binding_->set_connection_error_handler(base::Bind(
&AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this)));
client_info_ = std::move(subresource_load_info_->client); client_ = std::move(subresource_load_info_->client);
default_url_loader_factory_getter_ = default_url_loader; default_url_loader_factory_getter_ = default_url_loader;
} }
...@@ -152,15 +232,17 @@ void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request, ...@@ -152,15 +232,17 @@ void AppCacheURLLoaderJob::Start(mojom::URLLoaderRequest request,
binding_.set_connection_error_handler(base::Bind( binding_.set_connection_error_handler(base::Bind(
&AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this))); &AppCacheURLLoaderJob::OnConnectionError, StaticAsWeakPtr(this)));
client_info_ = std::move(client); client_ = std::move(client);
// Send the cached AppCacheResponse if any. // Send the cached AppCacheResponse if any.
if (info_.get()) if (info_.get())
SendResponseInfo(); SendResponseInfo();
} }
AppCacheURLLoaderJob::AppCacheURLLoaderJob(const ResourceRequest& request, AppCacheURLLoaderJob::AppCacheURLLoaderJob(
AppCacheStorage* storage) const ResourceRequest& request,
AppCacheURLLoaderRequest* appcache_request,
AppCacheStorage* storage)
: request_(request), : request_(request),
storage_(storage->GetWeakPtr()), storage_(storage->GetWeakPtr()),
start_time_tick_(base::TimeTicks::Now()), start_time_tick_(base::TimeTicks::Now()),
...@@ -168,7 +250,9 @@ AppCacheURLLoaderJob::AppCacheURLLoaderJob(const ResourceRequest& request, ...@@ -168,7 +250,9 @@ AppCacheURLLoaderJob::AppCacheURLLoaderJob(const ResourceRequest& request,
is_fallback_(false), is_fallback_(false),
binding_(this), binding_(this),
writable_handle_watcher_(FROM_HERE, writable_handle_watcher_(FROM_HERE,
mojo::SimpleWatcher::ArmingPolicy::MANUAL) {} mojo::SimpleWatcher::ArmingPolicy::MANUAL),
network_loader_client_binding_(this),
appcache_request_(appcache_request) {}
void AppCacheURLLoaderJob::OnResponseInfoLoaded( void AppCacheURLLoaderJob::OnResponseInfoLoaded(
AppCacheResponseInfo* response_info, AppCacheResponseInfo* response_info,
...@@ -206,7 +290,7 @@ void AppCacheURLLoaderJob::OnResponseInfoLoaded( ...@@ -206,7 +290,7 @@ void AppCacheURLLoaderJob::OnResponseInfoLoaded(
base::Bind(&AppCacheURLLoaderJob::OnResponseBodyStreamReady, base::Bind(&AppCacheURLLoaderJob::OnResponseBodyStreamReady,
StaticAsWeakPtr(this))); StaticAsWeakPtr(this)));
if (client_info_) if (client_)
SendResponseInfo(); SendResponseInfo();
ReadMore(); ReadMore();
...@@ -260,7 +344,7 @@ void AppCacheURLLoaderJob::OnConnectionError() { ...@@ -260,7 +344,7 @@ void AppCacheURLLoaderJob::OnConnectionError() {
} }
void AppCacheURLLoaderJob::SendResponseInfo() { void AppCacheURLLoaderJob::SendResponseInfo() {
DCHECK(client_info_); DCHECK(client_);
// If this is null it means the response information was sent to the client. // If this is null it means the response information was sent to the client.
if (!data_pipe_.consumer_handle.is_valid()) if (!data_pipe_.consumer_handle.is_valid())
return; return;
...@@ -293,11 +377,12 @@ void AppCacheURLLoaderJob::SendResponseInfo() { ...@@ -293,11 +377,12 @@ void AppCacheURLLoaderJob::SendResponseInfo() {
response_head.load_timing = load_timing_info_; response_head.load_timing = load_timing_info_;
client_info_->OnReceiveResponse(response_head, http_info->ssl_info, appcache_request_->set_response(response_head);
mojom::DownloadedTempFilePtr());
client_info_->OnStartLoadingResponseBody( client_->OnReceiveResponse(response_head, http_info->ssl_info,
std::move(data_pipe_.consumer_handle)); mojom::DownloadedTempFilePtr());
client_->OnStartLoadingResponseBody(std::move(data_pipe_.consumer_handle));
} }
void AppCacheURLLoaderJob::ReadMore() { void AppCacheURLLoaderJob::ReadMore() {
...@@ -363,7 +448,14 @@ void AppCacheURLLoaderJob::NotifyCompleted(int error_code) { ...@@ -363,7 +448,14 @@ void AppCacheURLLoaderJob::NotifyCompleted(int error_code) {
request_complete_data.decoded_body_length = request_complete_data.decoded_body_length =
request_complete_data.encoded_body_length; request_complete_data.encoded_body_length;
} }
client_info_->OnComplete(request_complete_data); client_->OnComplete(request_complete_data);
}
void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() {
// Close the pipe to the network loader as we are delivering a fallback
// response to the client.
network_loader_client_binding_.Close();
network_loader_ = nullptr;
} }
} // namespace content } // namespace content
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
namespace content { namespace content {
class AppCacheRequest; class AppCacheRequest;
class AppCacheURLLoaderRequest;
class NetToMojoPendingBuffer; class NetToMojoPendingBuffer;
class URLLoaderFactoryGetter; class URLLoaderFactoryGetter;
struct SubresourceLoadInfo;
// Holds information about the subresource load request like the routing id, // Holds information about the subresource load request like the routing id,
// request id, the client pointer, etc. // request id, the client pointer, etc.
...@@ -49,7 +49,8 @@ struct SubresourceLoadInfo { ...@@ -49,7 +49,8 @@ struct SubresourceLoadInfo {
// responses stored in the AppCache. // responses stored in the AppCache.
class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
public AppCacheStorage::Delegate, public AppCacheStorage::Delegate,
public mojom::URLLoader { public mojom::URLLoader,
public mojom::URLLoaderClient {
public: public:
~AppCacheURLLoaderJob() override; ~AppCacheURLLoaderJob() override;
...@@ -73,6 +74,25 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -73,6 +74,25 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
void SetPriority(net::RequestPriority priority, void SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) override; int32_t intra_priority_value) override;
// mojom::URLLoaderClient implementation.
// These methods are called by the network loader for subresource requests
// which go to the network. We serve fallback content in these methods
// if applicable.
void OnReceiveResponse(const ResourceResponseHead& response_head,
const base::Optional<net::SSLInfo>& ssl_info,
mojom::DownloadedTempFilePtr downloaded_file) override;
void OnReceiveRedirect(const net::RedirectInfo& redirect_info,
const ResourceResponseHead& response_head) override;
void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override;
void OnUploadProgress(int64_t current_position,
int64_t total_size,
OnUploadProgressCallback ack_callback) override;
void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override;
void OnTransferSizeUpdated(int32_t transfer_size_diff) override;
void OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body) override;
void OnComplete(const ResourceRequestCompletionStatus& status) override;
void set_main_resource_loader_callback(LoaderCallback callback) { void set_main_resource_loader_callback(LoaderCallback callback) {
main_resource_loader_callback_ = std::move(callback); main_resource_loader_callback_ = std::move(callback);
} }
...@@ -97,6 +117,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -97,6 +117,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
friend class AppCacheJob; friend class AppCacheJob;
AppCacheURLLoaderJob(const ResourceRequest& request, AppCacheURLLoaderJob(const ResourceRequest& request,
AppCacheURLLoaderRequest* appcache_request,
AppCacheStorage* storage); AppCacheStorage* storage);
// AppCacheStorage::Delegate methods // AppCacheStorage::Delegate methods
...@@ -120,6 +141,10 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -120,6 +141,10 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
// Notifies the client about request completion. // Notifies the client about request completion.
void NotifyCompleted(int error_code); void NotifyCompleted(int error_code);
// Disconnects the mojo pipe to the network loader and releases related
// resources.
void DisconnectFromNetworkLoader();
// The current request. // The current request.
ResourceRequest request_; ResourceRequest request_;
...@@ -147,7 +172,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -147,7 +172,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
// The URLLoaderClient pointer. We call this interface with notifications // The URLLoaderClient pointer. We call this interface with notifications
// about the URL load // about the URL load
mojom::URLLoaderClientPtr client_info_; mojom::URLLoaderClientPtr client_;
// mojo data pipe entities. // mojo data pipe entities.
mojo::ScopedDataPipeProducerHandle response_body_stream_; mojo::ScopedDataPipeProducerHandle response_body_stream_;
...@@ -173,7 +198,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -173,7 +198,7 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
net::LoadTimingInfo load_timing_info_; net::LoadTimingInfo load_timing_info_;
// Used for subresource requests which go to the network. // Used for subresource requests which go to the network.
mojom::URLLoaderAssociatedPtr network_loader_request_; mojom::URLLoaderAssociatedPtr network_loader_;
// Binds the subresource URLLoaderClient with us. We can use the regular // Binds the subresource URLLoaderClient with us. We can use the regular
// binding_ member above when we remove the need for the associated requests // binding_ member above when we remove the need for the associated requests
...@@ -181,6 +206,13 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, ...@@ -181,6 +206,13 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob,
std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>> std::unique_ptr<mojo::AssociatedBinding<mojom::URLLoader>>
associated_binding_; associated_binding_;
// Network URLLoaderClient binding for subresource requests.
mojo::Binding<mojom::URLLoaderClient> network_loader_client_binding_;
// The AppCacheURLLoaderRequest instance. We use this to set the response
// info when we receive it.
AppCacheURLLoaderRequest* appcache_request_;
DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob);
}; };
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/appcache/appcache_url_loader_request.h" #include "content/browser/appcache/appcache_url_loader_request.h"
#include "content/public/common/resource_type.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
namespace content { namespace content {
...@@ -33,7 +34,8 @@ const GURL AppCacheURLLoaderRequest::GetReferrer() const { ...@@ -33,7 +34,8 @@ const GURL AppCacheURLLoaderRequest::GetReferrer() const {
} }
bool AppCacheURLLoaderRequest::IsSuccess() const { bool AppCacheURLLoaderRequest::IsSuccess() const {
return false; int response_code = GetResponseCode();
return (response_code >= 200 && response_code <= 226);
} }
bool AppCacheURLLoaderRequest::IsCancelled() const { bool AppCacheURLLoaderRequest::IsCancelled() const {
...@@ -45,6 +47,8 @@ bool AppCacheURLLoaderRequest::IsError() const { ...@@ -45,6 +47,8 @@ bool AppCacheURLLoaderRequest::IsError() const {
} }
int AppCacheURLLoaderRequest::GetResponseCode() const { int AppCacheURLLoaderRequest::GetResponseCode() const {
if (response_.headers)
return response_.headers->response_code();
return 0; return 0;
} }
...@@ -57,6 +61,10 @@ ResourceRequest* AppCacheURLLoaderRequest::GetResourceRequest() { ...@@ -57,6 +61,10 @@ ResourceRequest* AppCacheURLLoaderRequest::GetResourceRequest() {
return &request_; return &request_;
} }
AppCacheURLLoaderRequest* AppCacheURLLoaderRequest::AsURLLoaderRequest() {
return this;
}
AppCacheURLLoaderRequest::AppCacheURLLoaderRequest( AppCacheURLLoaderRequest::AppCacheURLLoaderRequest(
const ResourceRequest& request) const ResourceRequest& request)
: request_(request) {} : request_(request) {}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "content/browser/appcache/appcache_request.h" #include "content/browser/appcache/appcache_request.h"
#include "content/public/common/resource_request.h" #include "content/public/common/resource_request.h"
#include "content/public/common/resource_response.h"
namespace content { namespace content {
...@@ -39,12 +40,18 @@ class CONTENT_EXPORT AppCacheURLLoaderRequest : public AppCacheRequest { ...@@ -39,12 +40,18 @@ class CONTENT_EXPORT AppCacheURLLoaderRequest : public AppCacheRequest {
int GetResponseCode() const override; int GetResponseCode() const override;
std::string GetResponseHeaderByName(const std::string& name) const override; std::string GetResponseHeaderByName(const std::string& name) const override;
ResourceRequest* GetResourceRequest() override; ResourceRequest* GetResourceRequest() override;
AppCacheURLLoaderRequest* AsURLLoaderRequest() override;
void set_response(const ResourceResponseHead& response) {
response_ = response;
}
protected: protected:
explicit AppCacheURLLoaderRequest(const ResourceRequest& request); explicit AppCacheURLLoaderRequest(const ResourceRequest& request);
private: private:
ResourceRequest request_; ResourceRequest request_;
ResourceResponseHead response_;
DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderRequest); DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderRequest);
}; };
......
...@@ -58,6 +58,10 @@ net::URLRequest* AppCacheURLRequest::GetURLRequest() { ...@@ -58,6 +58,10 @@ net::URLRequest* AppCacheURLRequest::GetURLRequest() {
return url_request_; return url_request_;
} }
AppCacheURLRequest* AppCacheURLRequest::AsURLRequest() {
return this;
}
AppCacheURLRequest::AppCacheURLRequest(net::URLRequest* url_request) AppCacheURLRequest::AppCacheURLRequest(net::URLRequest* url_request)
: url_request_(url_request) {} : url_request_(url_request) {}
......
...@@ -33,8 +33,8 @@ class CONTENT_EXPORT AppCacheURLRequest : public AppCacheRequest { ...@@ -33,8 +33,8 @@ class CONTENT_EXPORT AppCacheURLRequest : public AppCacheRequest {
bool IsError() const override; bool IsError() const override;
int GetResponseCode() const override; int GetResponseCode() const override;
std::string GetResponseHeaderByName(const std::string& name) const override; std::string GetResponseHeaderByName(const std::string& name) const override;
net::URLRequest* GetURLRequest() override; net::URLRequest* GetURLRequest() override;
AppCacheURLRequest* AsURLRequest() override;
protected: protected:
explicit AppCacheURLRequest(net::URLRequest* url_request); explicit AppCacheURLRequest(net::URLRequest* url_request);
......
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