Commit d42af8f3 authored by Anantanarayanan Iyengar's avatar Anantanarayanan Iyengar Committed by Commit Bot

Add an abstraction for the URLRequest class which is used by the AppCacheUpdateJob's URLFetcher.

This is to ensure that we can provide functionality to update the AppCache using the URLLoader.
The plan is to implement the URLLoaderClient part of the update job in a subsequent patch.

This patch has the following changes:
1. We have a new class AppCacheUpdateRequestBase which provides the interface which is
   implemented by the URLRequest and URLLoaderClient subclasses. This interface is used
   by the URLFetcher and the AppCacheUpdateJob.

2. Subclasses AppCacheUpdateURLRequest and AppCacheUpdateURLLoaderRequest. These implement
   the URLRequest and URLLoaderClient portion of the update functionality. The URLRequest
   one is fully functional at this point.

3. I have left most of the reading and updating logic unchanged in URLFetcher unchanged.
   Will revisit this when I start working on the URLLoaderClient functionality.

4. The AppCacheUpdateURLRequest subclass maintains a pointer to the URLFetcher base and
   invokes its methods when it receives a response/redirect notification/data, etc.

BUG=715632

Change-Id: I16497e41aa5dbfab0c06c1ab0fc114945dd279e8
Reviewed-on: https://chromium-review.googlesource.com/592809Reviewed-by: default avatarMichael Nordman <michaeln@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Ananta Iyengar <ananta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491147}
parent 0b90a2a5
...@@ -353,8 +353,14 @@ source_set("browser") { ...@@ -353,8 +353,14 @@ source_set("browser") {
"appcache/appcache_subresource_url_factory.h", "appcache/appcache_subresource_url_factory.h",
"appcache/appcache_update_job.cc", "appcache/appcache_update_job.cc",
"appcache/appcache_update_job.h", "appcache/appcache_update_job.h",
"appcache/appcache_update_request_base.cc",
"appcache/appcache_update_request_base.h",
"appcache/appcache_update_url_fetcher.cc", "appcache/appcache_update_url_fetcher.cc",
"appcache/appcache_update_url_fetcher.h", "appcache/appcache_update_url_fetcher.h",
"appcache/appcache_update_url_loader_request.cc",
"appcache/appcache_update_url_loader_request.h",
"appcache/appcache_update_url_request.cc",
"appcache/appcache_update_url_request.h",
"appcache/appcache_url_loader_job.cc", "appcache/appcache_url_loader_job.cc",
"appcache/appcache_url_loader_job.h", "appcache/appcache_url_loader_job.h",
"appcache/appcache_url_loader_request.cc", "appcache/appcache_url_loader_request.cc",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/appcache/appcache_group.h" #include "content/browser/appcache/appcache_group.h"
#include "content/browser/appcache/appcache_histograms.h" #include "content/browser/appcache/appcache_histograms.h"
#include "content/browser/appcache/appcache_update_request_base.h"
#include "content/browser/appcache/appcache_update_url_fetcher.h" #include "content/browser/appcache/appcache_update_url_fetcher.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
...@@ -342,22 +343,21 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(URLFetcher* fetcher, ...@@ -342,22 +343,21 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(URLFetcher* fetcher,
manifest_fetcher_ = NULL; manifest_fetcher_ = NULL;
net::URLRequest* request = fetcher->request(); UpdateRequestBase* request = fetcher->request();
int response_code = -1; int response_code = -1;
bool is_valid_response_code = false; bool is_valid_response_code = false;
if (net_error == net::OK) { if (net_error == net::OK) {
response_code = request->GetResponseCode(); response_code = request->GetResponseCode();
is_valid_response_code = (response_code / 100 == 2); is_valid_response_code = (response_code / 100 == 2);
std::string mime_type; std::string mime_type = request->GetMimeType();
request->GetMimeType(&mime_type);
manifest_has_valid_mime_type_ = (mime_type == "text/cache-manifest"); manifest_has_valid_mime_type_ = (mime_type == "text/cache-manifest");
} }
if (is_valid_response_code) { if (is_valid_response_code) {
manifest_data_ = fetcher->manifest_data(); manifest_data_ = fetcher->manifest_data();
manifest_response_info_.reset( manifest_response_info_.reset(
new net::HttpResponseInfo(request->response_info())); new net::HttpResponseInfo(request->GetResponseInfo()));
if (update_type_ == UPGRADE_ATTEMPT) if (update_type_ == UPGRADE_ATTEMPT)
CheckIfManifestChanged(); // continues asynchronously CheckIfManifestChanged(); // continues asynchronously
else else
...@@ -484,8 +484,8 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher, ...@@ -484,8 +484,8 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher,
int net_error) { int net_error) {
DCHECK(internal_state_ == DOWNLOADING); DCHECK(internal_state_ == DOWNLOADING);
net::URLRequest* request = fetcher->request(); UpdateRequestBase* request = fetcher->request();
const GURL& url = request->original_url(); const GURL& url = request->GetOriginalURL();
pending_url_fetches_.erase(url); pending_url_fetches_.erase(url);
NotifyAllProgress(url); NotifyAllProgress(url);
++url_fetches_completed_; ++url_fetches_completed_;
...@@ -585,8 +585,8 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher, ...@@ -585,8 +585,8 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher,
// master entry fetches when entering cache failure state so this will never // master entry fetches when entering cache failure state so this will never
// be called in CACHE_FAILURE state. // be called in CACHE_FAILURE state.
net::URLRequest* request = fetcher->request(); UpdateRequestBase* request = fetcher->request();
const GURL& url = request->original_url(); const GURL& url = request->GetOriginalURL();
master_entry_fetches_.erase(url); master_entry_fetches_.erase(url);
++master_entries_completed_; ++master_entries_completed_;
...@@ -638,13 +638,10 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher, ...@@ -638,13 +638,10 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher,
const char kFormatString[] = "Manifest fetch failed (%d) %s"; const char kFormatString[] = "Manifest fetch failed (%d) %s";
std::string message = FormatUrlErrorMessage( std::string message = FormatUrlErrorMessage(
kFormatString, request->url(), fetcher->result(), response_code); kFormatString, request->GetURL(), fetcher->result(), response_code);
host_notifier.SendErrorNotifications( host_notifier.SendErrorNotifications(AppCacheErrorDetails(
AppCacheErrorDetails(message, message, APPCACHE_MANIFEST_ERROR, request->GetURL(), response_code,
APPCACHE_MANIFEST_ERROR, false /*is_cross_origin*/));
request->url(),
response_code,
false /*is_cross_origin*/));
// In downloading case, update result is different if all master entries // In downloading case, update result is different if all master entries
// failed vs. only some failing. // failed vs. only some failing.
...@@ -655,13 +652,11 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher, ...@@ -655,13 +652,11 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher,
// Section 6.9.4, step 22.3. // Section 6.9.4, step 22.3.
if (update_type_ == CACHE_ATTEMPT && pending_master_entries_.empty()) { if (update_type_ == CACHE_ATTEMPT && pending_master_entries_.empty()) {
HandleCacheFailure(AppCacheErrorDetails(message, HandleCacheFailure(
APPCACHE_MANIFEST_ERROR, AppCacheErrorDetails(message, APPCACHE_MANIFEST_ERROR,
request->url(), request->GetURL(), response_code,
response_code, false /*is_cross_origin*/),
false /*is_cross_origin*/), fetcher->result(), GURL());
fetcher->result(),
GURL());
return; return;
} }
} }
......
...@@ -61,7 +61,11 @@ class CONTENT_EXPORT AppCacheUpdateJob ...@@ -61,7 +61,11 @@ class CONTENT_EXPORT AppCacheUpdateJob
private: private:
friend class content::AppCacheGroupTest; friend class content::AppCacheGroupTest;
friend class content::AppCacheUpdateJobTest; friend class content::AppCacheUpdateJobTest;
friend class URLFetcher;
class URLFetcher;
class UpdateRequestBase;
class UpdateURLLoaderRequest;
class UpdateURLRequest;
// Master entries have multiple hosts, for example, the same page is opened // Master entries have multiple hosts, for example, the same page is opened
// in different tabs. // in different tabs.
......
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/appcache/appcache_update_request_base.h"
#include "content/browser/appcache/appcache_update_url_request.h"
#include "net/url_request/url_request_context.h"
namespace content {
AppCacheUpdateJob::UpdateRequestBase::~UpdateRequestBase() {}
// static
std::unique_ptr<AppCacheUpdateJob::UpdateRequestBase>
AppCacheUpdateJob::UpdateRequestBase::Create(
net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher) {
return std::unique_ptr<UpdateRequestBase>(
new UpdateURLRequest(request_context, url, fetcher));
}
AppCacheUpdateJob::UpdateRequestBase::UpdateRequestBase() {}
} // namespace content
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_REQUEST_BASE_H_
#define CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_REQUEST_BASE_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/optional.h"
#include "content/browser/appcache/appcache_update_job.h"
#include "net/base/io_buffer.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace net {
class URLRequestContext;
}
namespace content {
class AppCacheUpdateJob::UpdateRequestBase {
public:
virtual ~UpdateRequestBase();
// Creates an instance of the AppCacheUpdateRequestBase subclass.
static std::unique_ptr<UpdateRequestBase> Create(
net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher);
// This method is called to start the request.
virtual void Start() = 0;
// Sets all extra request headers. Any extra request headers set by other
// methods are overwritten by this method. This method may only be called
// before Start() is called. It is an error to call it later.
virtual void SetExtraRequestHeaders(
const net::HttpRequestHeaders& headers) = 0;
// Returns the request URL.
virtual GURL GetURL() const = 0;
// Returns the original URL of the request. The original url is the url used
// to initialize the request, and it may differ from the url if the request
// was redirected.
virtual GURL GetOriginalURL() const = 0;
// Sets flags which control the request load. e.g. if it can be loaded
// from cache, etc.
virtual void SetLoadFlags(int flags) = 0;
// Gets the load flags on the request.
virtual int GetLoadFlags() const = 0;
// Get the mime type. This method may only be called after the response was
// started.
virtual std::string GetMimeType() const = 0;
// Cookie policy.
virtual void SetFirstPartyForCookies(const GURL& first_party_for_cookies) = 0;
// Sets the origin of the context which initiated the request.
virtual void SetInitiator(const base::Optional<url::Origin>& initiator) = 0;
// Get all response headers, as a HttpResponseHeaders object. See comments
// in HttpResponseHeaders class as to the format of the data.
virtual net::HttpResponseHeaders* GetResponseHeaders() const = 0;
// Returns the HTTP response code (e.g., 200, 404, and so on). This method
// may only be called once the delegate's OnResponseStarted method has been
// called. For non-HTTP requests, this method returns -1.
virtual int GetResponseCode() const = 0;
// Get the HTTP response info in its entirety.
virtual net::HttpResponseInfo GetResponseInfo() const = 0;
// Used to specify the context (cookie store, cache) for this request.
virtual const net::URLRequestContext* GetRequestContext() const = 0;
// Initiates an asynchronous read. Could return net::ERR_IO_PENDING or the
// number of bytes read.
virtual int Read(net::IOBuffer* buf, int max_bytes) = 0;
// This method may be called at any time after Start() has been called to
// cancel the request.
// Returns net::ERR_ABORTED or any applicable net error.
virtual int Cancel() = 0;
protected:
UpdateRequestBase();
};
} // namespace content
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_REQUEST_BASE_H_
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "content/browser/appcache/appcache_response.h" #include "content/browser/appcache/appcache_response.h"
#include "content/browser/appcache/appcache_update_job.h" #include "content/browser/appcache/appcache_update_job.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content { namespace content {
...@@ -19,7 +18,7 @@ namespace content { ...@@ -19,7 +18,7 @@ namespace content {
// Helper class to fetch resources. Depending on the fetch type, // Helper class to fetch resources. Depending on the fetch type,
// can either fetch to an in-memory string or write the response // can either fetch to an in-memory string or write the response
// data out to the disk cache. // data out to the disk cache.
class URLFetcher : public net::URLRequest::Delegate { class AppCacheUpdateJob::URLFetcher {
public: public:
enum FetchType { enum FetchType {
MANIFEST_FETCH, MANIFEST_FETCH,
...@@ -31,10 +30,10 @@ class URLFetcher : public net::URLRequest::Delegate { ...@@ -31,10 +30,10 @@ class URLFetcher : public net::URLRequest::Delegate {
FetchType fetch_type, FetchType fetch_type,
AppCacheUpdateJob* job, AppCacheUpdateJob* job,
int buffer_size); int buffer_size);
~URLFetcher() override; ~URLFetcher();
void Start(); void Start();
FetchType fetch_type() const { return fetch_type_; } FetchType fetch_type() const { return fetch_type_; }
net::URLRequest* request() const { return request_.get(); } UpdateRequestBase* request() const { return request_.get(); }
const AppCacheEntry& existing_entry() const { return existing_entry_; } const AppCacheEntry& existing_entry() const { return existing_entry_; }
const std::string& manifest_data() const { return manifest_data_; } const std::string& manifest_data() const { return manifest_data_; }
AppCacheResponseWriter* response_writer() const { AppCacheResponseWriter* response_writer() const {
...@@ -50,12 +49,9 @@ class URLFetcher : public net::URLRequest::Delegate { ...@@ -50,12 +49,9 @@ class URLFetcher : public net::URLRequest::Delegate {
int redirect_response_code() const { return redirect_response_code_; } int redirect_response_code() const { return redirect_response_code_; }
private: private:
// URLRequest::Delegate overrides void OnReceivedRedirect(const net::RedirectInfo& redirect_info);
void OnReceivedRedirect(net::URLRequest* request, void OnResponseStarted(int net_error);
const net::RedirectInfo& redirect_info, void OnReadCompleted(int bytes_read);
bool* defer_redirect) override;
void OnResponseStarted(net::URLRequest* request, int net_error) override;
void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
void AddConditionalHeaders(const net::HttpResponseHeaders* headers); void AddConditionalHeaders(const net::HttpResponseHeaders* headers);
void OnWriteComplete(int result); void OnWriteComplete(int result);
...@@ -64,12 +60,15 @@ class URLFetcher : public net::URLRequest::Delegate { ...@@ -64,12 +60,15 @@ class URLFetcher : public net::URLRequest::Delegate {
void OnResponseCompleted(int net_error); void OnResponseCompleted(int net_error);
bool MaybeRetryRequest(); bool MaybeRetryRequest();
friend class UpdateURLRequest;
friend class UpdateURLLoaderRequest;
GURL url_; GURL url_;
AppCacheUpdateJob* job_; AppCacheUpdateJob* job_;
FetchType fetch_type_; FetchType fetch_type_;
int retry_503_attempts_; int retry_503_attempts_;
scoped_refptr<net::IOBuffer> buffer_; scoped_refptr<net::IOBuffer> buffer_;
std::unique_ptr<net::URLRequest> request_; std::unique_ptr<UpdateRequestBase> request_;
AppCacheEntry existing_entry_; AppCacheEntry existing_entry_;
scoped_refptr<net::HttpResponseHeaders> existing_response_headers_; scoped_refptr<net::HttpResponseHeaders> existing_response_headers_;
std::string manifest_data_; std::string manifest_data_;
......
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/appcache/appcache_update_url_loader_request.h"
#include "content/browser/appcache/appcache_update_url_fetcher.h"
#include "net/url_request/url_request_context.h"
namespace content {
AppCacheUpdateJob::UpdateURLLoaderRequest::~UpdateURLLoaderRequest() {}
void AppCacheUpdateJob::UpdateURLLoaderRequest::Start() {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::SetExtraRequestHeaders(
const net::HttpRequestHeaders& headers) {
NOTIMPLEMENTED();
}
GURL AppCacheUpdateJob::UpdateURLLoaderRequest::GetURL() const {
NOTIMPLEMENTED();
return GURL();
}
GURL AppCacheUpdateJob::UpdateURLLoaderRequest::GetOriginalURL() const {
NOTIMPLEMENTED();
return GURL();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::SetLoadFlags(int flags) {
NOTIMPLEMENTED();
}
int AppCacheUpdateJob::UpdateURLLoaderRequest::GetLoadFlags() const {
NOTIMPLEMENTED();
return 0;
}
std::string AppCacheUpdateJob::UpdateURLLoaderRequest::GetMimeType() const {
NOTIMPLEMENTED();
return std::string();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::SetFirstPartyForCookies(
const GURL& first_party_for_cookies) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::SetInitiator(
const base::Optional<url::Origin>& initiator) {
NOTIMPLEMENTED();
}
net::HttpResponseHeaders*
AppCacheUpdateJob::UpdateURLLoaderRequest::GetResponseHeaders() const {
NOTIMPLEMENTED();
return nullptr;
}
int AppCacheUpdateJob::UpdateURLLoaderRequest::GetResponseCode() const {
NOTIMPLEMENTED();
return 0;
}
net::HttpResponseInfo
AppCacheUpdateJob::UpdateURLLoaderRequest::GetResponseInfo() const {
NOTIMPLEMENTED();
return net::HttpResponseInfo();
}
const net::URLRequestContext*
AppCacheUpdateJob::UpdateURLLoaderRequest::GetRequestContext() const {
NOTIMPLEMENTED();
return nullptr;
}
int AppCacheUpdateJob::UpdateURLLoaderRequest::Read(net::IOBuffer* buf,
int max_bytes) {
NOTIMPLEMENTED();
return 0;
}
int AppCacheUpdateJob::UpdateURLLoaderRequest::Cancel() {
NOTIMPLEMENTED();
return 0;
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnReceiveResponse(
const ResourceResponseHead& response_head,
const base::Optional<net::SSLInfo>& ssl_info,
mojom::DownloadedTempFilePtr downloaded_file) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnReceiveRedirect(
const net::RedirectInfo& redirect_info,
const ResourceResponseHead& response_head) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnDataDownloaded(
int64_t data_len,
int64_t encoded_data_len) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnUploadProgress(
int64_t current_position,
int64_t total_size,
OnUploadProgressCallback ack_callback) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnReceiveCachedMetadata(
const std::vector<uint8_t>& data) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnTransferSizeUpdated(
int32_t transfer_size_diff) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body) {
NOTIMPLEMENTED();
}
void AppCacheUpdateJob::UpdateURLLoaderRequest::OnComplete(
const ResourceRequestCompletionStatus& status) {
NOTIMPLEMENTED();
}
AppCacheUpdateJob::UpdateURLLoaderRequest::UpdateURLLoaderRequest(
net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher) {}
} // namespace content
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_LOADER_REQUEST_H_
#define CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_LOADER_REQUEST_H_
#include <stddef.h>
#include <stdint.h>
#include "base/macros.h"
#include "content/browser/appcache/appcache_update_request_base.h"
#include "content/public/common/url_loader.mojom.h"
namespace content {
// URLLoaderClient subclass for the UpdateRequestBase class. Provides
// functionality to update the AppCache using functionality provided by the
// network URL loader
class AppCacheUpdateJob::UpdateURLLoaderRequest
: public AppCacheUpdateJob::UpdateRequestBase,
public mojom::URLLoaderClient {
public:
~UpdateURLLoaderRequest() override;
// UpdateRequestBase overrides.
void Start() override;
void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
GURL GetURL() const override;
GURL GetOriginalURL() const override;
void SetLoadFlags(int flags) override;
int GetLoadFlags() const override;
std::string GetMimeType() const override;
void SetFirstPartyForCookies(const GURL& first_party_for_cookies) override;
void SetInitiator(const base::Optional<url::Origin>& initiator) override;
net::HttpResponseHeaders* GetResponseHeaders() const override;
int GetResponseCode() const override;
net::HttpResponseInfo GetResponseInfo() const override;
const net::URLRequestContext* GetRequestContext() const override;
int Read(net::IOBuffer* buf, int max_bytes) override;
int Cancel() override;
// mojom::URLLoaderClient implementation.
// These methods are called by the network loader.
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;
private:
UpdateURLLoaderRequest(net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher);
friend class AppCacheUpdateJob::UpdateRequestBase;
URLFetcher* fetcher_;
DISALLOW_COPY_AND_ASSIGN(UpdateURLLoaderRequest);
};
} // namespace content
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_LOADER_REQUEST_H_
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/appcache/appcache_update_url_request.h"
#include "content/browser/appcache/appcache_update_url_fetcher.h"
#include "net/url_request/url_request_context.h"
namespace content {
namespace {
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("appcache_update_job", R"(
semantics {
sender: "HTML5 AppCache System"
description:
"Web pages can include a link to a manifest file which lists "
"resources to be cached for offline access. The AppCache system"
"retrieves those resources in the background."
trigger:
"User visits a web page containing a <html manifest=manifestUrl> "
"tag, or navigates to a document retrieved from an existing appcache "
"and some resource should be updated."
data: "None"
destination: WEBSITE
}
policy {
cookies_allowed: YES
cookies_store: "user"
setting:
"Users can control this feature via the 'Cookies' setting under "
"'Privacy, Content settings'. If cookies are disabled for a single "
"site, appcaches are disabled for the site only. If they are totally "
"disabled, all appcache requests will be stopped."
chrome_policy {
DefaultCookiesSetting {
DefaultCookiesSetting: 2
}
}
})");
}
AppCacheUpdateJob::UpdateURLRequest::~UpdateURLRequest() {
// To defend against URLRequest calling delegate methods during
// destruction, we test for a !request_ in those methods.
std::unique_ptr<net::URLRequest> temp = std::move(request_);
}
void AppCacheUpdateJob::UpdateURLRequest::Start() {
request_->Start();
}
void AppCacheUpdateJob::UpdateURLRequest::SetExtraRequestHeaders(
const net::HttpRequestHeaders& headers) {
request_->SetExtraRequestHeaders(headers);
}
GURL AppCacheUpdateJob::UpdateURLRequest::GetURL() const {
return request_->url();
}
GURL AppCacheUpdateJob::UpdateURLRequest::GetOriginalURL() const {
return request_->original_url();
}
void AppCacheUpdateJob::UpdateURLRequest::SetLoadFlags(int flags) {
request_->SetLoadFlags(flags);
}
int AppCacheUpdateJob::UpdateURLRequest::GetLoadFlags() const {
return request_->load_flags();
}
std::string AppCacheUpdateJob::UpdateURLRequest::GetMimeType() const {
std::string mime_type;
request_->GetMimeType(&mime_type);
return mime_type;
}
void AppCacheUpdateJob::UpdateURLRequest::SetFirstPartyForCookies(
const GURL& first_party_for_cookies) {
request_->set_first_party_for_cookies(first_party_for_cookies);
}
void AppCacheUpdateJob::UpdateURLRequest::SetInitiator(
const base::Optional<url::Origin>& initiator) {
request_->set_initiator(initiator);
}
net::HttpResponseHeaders*
AppCacheUpdateJob::UpdateURLRequest::GetResponseHeaders() const {
return request_->response_headers();
}
int AppCacheUpdateJob::UpdateURLRequest::GetResponseCode() const {
return request_->GetResponseCode();
}
net::HttpResponseInfo AppCacheUpdateJob::UpdateURLRequest::GetResponseInfo()
const {
return request_->response_info();
}
const net::URLRequestContext*
AppCacheUpdateJob::UpdateURLRequest::GetRequestContext() const {
return request_->context();
}
int AppCacheUpdateJob::UpdateURLRequest::Read(net::IOBuffer* buf,
int max_bytes) {
return request_->Read(buf, max_bytes);
}
int AppCacheUpdateJob::UpdateURLRequest::Cancel() {
return request_->Cancel();
}
void AppCacheUpdateJob::UpdateURLRequest::OnReceivedRedirect(
net::URLRequest* request,
const net::RedirectInfo& redirect_info,
bool* defer_redirect) {
if (!request_)
return;
DCHECK_EQ(request_.get(), request);
fetcher_->OnReceivedRedirect(redirect_info);
}
void AppCacheUpdateJob::UpdateURLRequest::OnResponseStarted(
net::URLRequest* request,
int net_error) {
if (!request_)
return;
DCHECK_EQ(request_.get(), request);
fetcher_->OnResponseStarted(net_error);
}
void AppCacheUpdateJob::UpdateURLRequest::OnReadCompleted(
net::URLRequest* request,
int bytes_read) {
if (!request_)
return;
DCHECK_EQ(request_.get(), request);
fetcher_->OnReadCompleted(bytes_read);
}
AppCacheUpdateJob::UpdateURLRequest::UpdateURLRequest(
net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher)
: request_(request_context->CreateRequest(url,
net::DEFAULT_PRIORITY,
this,
kTrafficAnnotation)),
fetcher_(fetcher) {}
} // namespace content
// Copyright (c) 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_REQUEST_H_
#define CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_REQUEST_H_
#include <stddef.h>
#include <stdint.h>
#include "base/macros.h"
#include "content/browser/appcache/appcache_update_request_base.h"
#include "net/url_request/url_request.h"
namespace content {
// URLRequest subclass for the UpdateRequestBase class. Provides functionality
// to update the AppCache using functionality provided by the URLRequest class.
class AppCacheUpdateJob::UpdateURLRequest
: public AppCacheUpdateJob::UpdateRequestBase,
public net::URLRequest::Delegate {
public:
~UpdateURLRequest() override;
// UpdateRequestBase overrides.
void Start() override;
void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
GURL GetURL() const override;
GURL GetOriginalURL() const override;
void SetLoadFlags(int flags) override;
int GetLoadFlags() const override;
std::string GetMimeType() const override;
void SetFirstPartyForCookies(const GURL& first_party_for_cookies) override;
void SetInitiator(const base::Optional<url::Origin>& initiator) override;
net::HttpResponseHeaders* GetResponseHeaders() const override;
int GetResponseCode() const override;
net::HttpResponseInfo GetResponseInfo() const override;
const net::URLRequestContext* GetRequestContext() const override;
int Read(net::IOBuffer* buf, int max_bytes) override;
int Cancel() override;
// URLRequest::Delegate overrides
void OnReceivedRedirect(net::URLRequest* request,
const net::RedirectInfo& redirect_info,
bool* defer_redirect) override;
void OnResponseStarted(net::URLRequest* request, int net_error) override;
void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
private:
UpdateURLRequest(net::URLRequestContext* request_context,
const GURL& url,
URLFetcher* fetcher);
friend class AppCacheUpdateJob::UpdateRequestBase;
std::unique_ptr<net::URLRequest> request_;
URLFetcher* fetcher_;
DISALLOW_COPY_AND_ASSIGN(UpdateURLRequest);
};
} // namespace content
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_REQUEST_H_
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