Commit 2a2bc271 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[AppCache] No need to branch on network service when making requests.

Primarily this is getting rid of the abstraction in AppCacheUpdateRequestBase
to either map to AppCacheUpdateURLRequest or AppCacheUpdateURLLoaderRequest.
I.e. this changes things such that requests made by the app cache code
always take the URLLoader code path, as that should work regardless of if
network service is enabled.

Everything else is just updating tests to work with these changes.

Bug: 925585
Change-Id: Icd4fc4510231efd4e49e5dda9bc25520f2817419
Reviewed-on: https://chromium-review.googlesource.com/c/1437325
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarNicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#627719}
parent 09082aa3
...@@ -399,14 +399,10 @@ jumbo_source_set("browser") { ...@@ -399,14 +399,10 @@ jumbo_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.cc",
"appcache/appcache_update_url_loader_request.h", "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",
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "content/browser/appcache/appcache_frontend.h" #include "content/browser/appcache/appcache_frontend.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/browser/appcache/appcache_update_url_loader_request.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"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
...@@ -372,7 +372,7 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(URLFetcher* fetcher, ...@@ -372,7 +372,7 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(URLFetcher* fetcher,
manifest_fetcher_ = nullptr; manifest_fetcher_ = nullptr;
UpdateRequestBase* request = fetcher->request(); UpdateURLLoaderRequest* 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) {
...@@ -508,7 +508,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher, ...@@ -508,7 +508,7 @@ void AppCacheUpdateJob::HandleUrlFetchCompleted(URLFetcher* fetcher,
int net_error) { int net_error) {
DCHECK(internal_state_ == DOWNLOADING); DCHECK(internal_state_ == DOWNLOADING);
UpdateRequestBase* request = fetcher->request(); UpdateURLLoaderRequest* request = fetcher->request();
const GURL& url = request->GetURL(); const GURL& url = request->GetURL();
pending_url_fetches_.erase(url); pending_url_fetches_.erase(url);
NotifyAllProgress(url); NotifyAllProgress(url);
...@@ -609,7 +609,7 @@ void AppCacheUpdateJob::HandleMasterEntryFetchCompleted(URLFetcher* fetcher, ...@@ -609,7 +609,7 @@ 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.
UpdateRequestBase* request = fetcher->request(); UpdateURLLoaderRequest* request = fetcher->request();
const GURL& url = request->GetURL(); const GURL& url = request->GetURL();
master_entry_fetches_.erase(url); master_entry_fetches_.erase(url);
++master_entries_completed_; ++master_entries_completed_;
......
// 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_loader_request.h"
#include "content/browser/appcache/appcache_update_url_request.h"
#include "content/public/common/content_features.h"
#include "net/url_request/url_request_context.h"
#include "services/network/public/cpp/features.h"
namespace content {
namespace {
constexpr net::NetworkTrafficAnnotationTag kAppCacheTrafficAnnotation =
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::UpdateRequestBase::~UpdateRequestBase() {}
// static
std::unique_ptr<AppCacheUpdateJob::UpdateRequestBase>
AppCacheUpdateJob::UpdateRequestBase::Create(
AppCacheServiceImpl* appcache_service,
const GURL& url,
int buffer_size,
URLFetcher* fetcher) {
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
return std::unique_ptr<UpdateRequestBase>(new UpdateURLRequest(
appcache_service->request_context(), url, buffer_size, fetcher));
} else {
return std::unique_ptr<UpdateRequestBase>(new UpdateURLLoaderRequest(
appcache_service->url_loader_factory_getter(), url, buffer_size,
fetcher));
}
}
AppCacheUpdateJob::UpdateRequestBase::UpdateRequestBase() {}
net::NetworkTrafficAnnotationTag
AppCacheUpdateJob::UpdateRequestBase::GetTrafficAnnotation() {
return kAppCacheTrafficAnnotation;
}
} // 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 content {
class AppCacheUpdateJob::UpdateRequestBase {
public:
virtual ~UpdateRequestBase();
// Creates an instance of the AppCacheUpdateRequestBase subclass.
static std::unique_ptr<UpdateRequestBase> Create(
AppCacheServiceImpl* appcache_service,
const GURL& url,
int buffer_size,
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;
// 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 SetSiteForCookies(const GURL& site_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 const net::HttpResponseInfo& GetResponseInfo() const = 0;
// Initiates an asynchronous read. Multiple concurrent reads are not
// supported.
virtual void Read() = 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();
// Returns the traffic annotation information to be used for the outgoing
// request.
static net::NetworkTrafficAnnotationTag GetTrafficAnnotation();
};
} // namespace content
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_REQUEST_BASE_H_
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "content/browser/appcache/appcache_update_url_fetcher.h" #include "content/browser/appcache/appcache_update_url_fetcher.h"
#include <memory>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/network_session_configurator/common/network_switches.h" #include "components/network_session_configurator/common/network_switches.h"
#include "content/browser/appcache/appcache_update_request_base.h" #include "content/browser/appcache/appcache_update_url_loader_request.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/http/http_request_headers.h" #include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
...@@ -32,8 +34,11 @@ AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, ...@@ -32,8 +34,11 @@ AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url,
job_(job), job_(job),
fetch_type_(fetch_type), fetch_type_(fetch_type),
retry_503_attempts_(0), retry_503_attempts_(0),
request_( request_(std::make_unique<UpdateURLLoaderRequest>(
UpdateRequestBase::Create(job->service_, url, buffer_size, this)), job->service_->url_loader_factory_getter(),
url,
buffer_size,
this)),
result_(AppCacheUpdateJob::UPDATE_OK), result_(AppCacheUpdateJob::UPDATE_OK),
redirect_response_code_(-1), redirect_response_code_(-1),
buffer_size_(buffer_size) {} buffer_size_(buffer_size) {}
...@@ -245,8 +250,8 @@ bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { ...@@ -245,8 +250,8 @@ bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() {
} }
++retry_503_attempts_; ++retry_503_attempts_;
result_ = AppCacheUpdateJob::UPDATE_OK; result_ = AppCacheUpdateJob::UPDATE_OK;
request_ = request_ = std::make_unique<UpdateURLLoaderRequest>(
UpdateRequestBase::Create(job_->service_, url_, buffer_size_, this); job_->service_->url_loader_factory_getter(), url_, buffer_size_, this);
Start(); Start();
return true; return true;
} }
......
...@@ -33,7 +33,7 @@ class AppCacheUpdateJob::URLFetcher { ...@@ -33,7 +33,7 @@ class AppCacheUpdateJob::URLFetcher {
~URLFetcher(); ~URLFetcher();
void Start(); void Start();
FetchType fetch_type() const { return fetch_type_; } FetchType fetch_type() const { return fetch_type_; }
UpdateRequestBase* request() const { return request_.get(); } UpdateURLLoaderRequest* 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 {
...@@ -60,14 +60,13 @@ class AppCacheUpdateJob::URLFetcher { ...@@ -60,14 +60,13 @@ class AppCacheUpdateJob::URLFetcher {
void OnResponseCompleted(int net_error); void OnResponseCompleted(int net_error);
bool MaybeRetryRequest(); bool MaybeRetryRequest();
friend class UpdateURLRequest;
friend class UpdateURLLoaderRequest; 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_;
std::unique_ptr<UpdateRequestBase> request_; std::unique_ptr<UpdateURLLoaderRequest> 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_;
...@@ -79,4 +78,4 @@ class AppCacheUpdateJob::URLFetcher { ...@@ -79,4 +78,4 @@ class AppCacheUpdateJob::URLFetcher {
} // namespace content. } // namespace content.
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_FETCHER_H_ #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_FETCHER_H_
\ No newline at end of file
...@@ -12,6 +12,38 @@ ...@@ -12,6 +12,38 @@
namespace content { namespace content {
namespace {
constexpr net::NetworkTrafficAnnotationTag kAppCacheTrafficAnnotation =
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::UpdateURLLoaderRequest::~UpdateURLLoaderRequest() {} AppCacheUpdateJob::UpdateURLLoaderRequest::~UpdateURLLoaderRequest() {}
void AppCacheUpdateJob::UpdateURLLoaderRequest::Start() { void AppCacheUpdateJob::UpdateURLLoaderRequest::Start() {
...@@ -25,7 +57,7 @@ void AppCacheUpdateJob::UpdateURLLoaderRequest::Start() { ...@@ -25,7 +57,7 @@ void AppCacheUpdateJob::UpdateURLLoaderRequest::Start() {
loader_factory_getter_->GetNetworkFactory()->CreateLoaderAndStart( loader_factory_getter_->GetNetworkFactory()->CreateLoaderAndStart(
mojo::MakeRequest(&url_loader_), -1, -1, mojo::MakeRequest(&url_loader_), -1, -1,
network::mojom::kURLLoadOptionNone, request_, std::move(client), network::mojom::kURLLoadOptionNone, request_, std::move(client),
net::MutableNetworkTrafficAnnotationTag(GetTrafficAnnotation())); net::MutableNetworkTrafficAnnotationTag(kAppCacheTrafficAnnotation));
} }
void AppCacheUpdateJob::UpdateURLLoaderRequest::SetExtraRequestHeaders( void AppCacheUpdateJob::UpdateURLLoaderRequest::SetExtraRequestHeaders(
......
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include <string>
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/appcache/appcache_update_request_base.h" #include "content/browser/appcache/appcache_update_job.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/simple_watcher.h" #include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
...@@ -31,25 +32,62 @@ class URLLoaderFactoryGetter; ...@@ -31,25 +32,62 @@ class URLLoaderFactoryGetter;
// functionality to update the AppCache using functionality provided by the // functionality to update the AppCache using functionality provided by the
// network URL loader. // network URL loader.
class AppCacheUpdateJob::UpdateURLLoaderRequest class AppCacheUpdateJob::UpdateURLLoaderRequest
: public AppCacheUpdateJob::UpdateRequestBase, : public network::mojom::URLLoaderClient {
public network::mojom::URLLoaderClient {
public: public:
UpdateURLLoaderRequest(URLLoaderFactoryGetter* loader_factory_getter,
const GURL& url,
int buffer_size,
URLFetcher* fetcher);
~UpdateURLLoaderRequest() override; ~UpdateURLLoaderRequest() override;
// UpdateRequestBase overrides. // This method is called to start the request.
void Start() override; void Start();
void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override;
GURL GetURL() const override; // Sets all extra request headers. Any extra request headers set by other
void SetLoadFlags(int flags) override; // methods are overwritten by this method. This method may only be called
int GetLoadFlags() const override; // before Start() is called. It is an error to call it later.
std::string GetMimeType() const override; void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers);
void SetSiteForCookies(const GURL& site_for_cookies) override;
void SetInitiator(const base::Optional<url::Origin>& initiator) override; // Returns the request URL.
net::HttpResponseHeaders* GetResponseHeaders() const override; GURL GetURL() const;
int GetResponseCode() const override;
const net::HttpResponseInfo& GetResponseInfo() const override; // Sets flags which control the request load. e.g. if it can be loaded
void Read() override; // from cache, etc.
int Cancel() override; void SetLoadFlags(int flags);
// Gets the load flags on the request.
int GetLoadFlags() const;
// Get the mime type. This method may only be called after the response was
// started.
std::string GetMimeType() const;
// Cookie policy.
void SetSiteForCookies(const GURL& site_for_cookies);
// Sets the origin of the context which initiated the request.
void SetInitiator(const base::Optional<url::Origin>& initiator);
// Get all response headers, as a HttpResponseHeaders object. See comments
// in HttpResponseHeaders class as to the format of the data.
net::HttpResponseHeaders* GetResponseHeaders() const;
// 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.
int GetResponseCode() const;
// Get the HTTP response info in its entirety.
const net::HttpResponseInfo& GetResponseInfo() const;
// Initiates an asynchronous read. Multiple concurrent reads are not
// supported.
void Read();
// 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.
int Cancel();
// network::mojom::URLLoaderClient implementation. // network::mojom::URLLoaderClient implementation.
// These methods are called by the network loader. // These methods are called by the network loader.
...@@ -68,11 +106,6 @@ class AppCacheUpdateJob::UpdateURLLoaderRequest ...@@ -68,11 +106,6 @@ class AppCacheUpdateJob::UpdateURLLoaderRequest
void OnComplete(const network::URLLoaderCompletionStatus& status) override; void OnComplete(const network::URLLoaderCompletionStatus& status) override;
private: private:
UpdateURLLoaderRequest(URLLoaderFactoryGetter* loader_factory_getter,
const GURL& url,
int buffer_size,
URLFetcher* fetcher);
// Helper function to initiate an asynchronous read on the data pipe. // Helper function to initiate an asynchronous read on the data pipe.
void StartReading(MojoResult unused); void StartReading(MojoResult unused);
...@@ -81,8 +114,6 @@ class AppCacheUpdateJob::UpdateURLLoaderRequest ...@@ -81,8 +114,6 @@ class AppCacheUpdateJob::UpdateURLLoaderRequest
// a pending read. // a pending read.
void MaybeStartReading(); void MaybeStartReading();
friend class AppCacheUpdateJob::UpdateRequestBase;
URLFetcher* fetcher_; URLFetcher* fetcher_;
// Used to retrieve the network URLLoader interface to issue network // Used to retrieve the network URLLoader interface to issue network
// requests // requests
......
// 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 "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/browser/appcache/appcache_update_url_fetcher.h"
#include "net/url_request/url_request_context.h"
namespace content {
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();
}
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::SetSiteForCookies(
const GURL& site_for_cookies) {
request_->set_site_for_cookies(site_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();
}
const net::HttpResponseInfo&
AppCacheUpdateJob::UpdateURLRequest::GetResponseInfo() const {
return request_->response_info();
}
void AppCacheUpdateJob::UpdateURLRequest::Read() {
int bytes_read = request_->Read(buffer_.get(), buffer_size_);
if (bytes_read != net::ERR_IO_PENDING) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&AppCacheUpdateJob::UpdateURLRequest::OnReadCompleted,
weak_factory_.GetWeakPtr(), request_.get(), bytes_read));
}
}
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(buffer_.get(), bytes_read);
}
AppCacheUpdateJob::UpdateURLRequest::UpdateURLRequest(
net::URLRequestContext* request_context,
const GURL& url,
int buffer_size,
URLFetcher* fetcher)
: request_(request_context->CreateRequest(url,
net::DEFAULT_PRIORITY,
this,
GetTrafficAnnotation())),
fetcher_(fetcher),
buffer_(base::MakeRefCounted<net::IOBuffer>(buffer_size)),
buffer_size_(buffer_size),
weak_factory_(this) {}
} // 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 "base/memory/weak_ptr.h"
#include "content/browser/appcache/appcache_update_request_base.h"
#include "net/base/io_buffer.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;
void SetLoadFlags(int flags) override;
int GetLoadFlags() const override;
std::string GetMimeType() const override;
void SetSiteForCookies(const GURL& site_for_cookies) override;
void SetInitiator(const base::Optional<url::Origin>& initiator) override;
net::HttpResponseHeaders* GetResponseHeaders() const override;
int GetResponseCode() const override;
const net::HttpResponseInfo& GetResponseInfo() const override;
void Read() 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,
int buffer_size,
URLFetcher* fetcher);
friend class AppCacheUpdateJob::UpdateRequestBase;
std::unique_ptr<net::URLRequest> request_;
URLFetcher* fetcher_;
scoped_refptr<net::IOBuffer> buffer_;
int buffer_size_;
base::WeakPtrFactory<AppCacheUpdateJob::UpdateURLRequest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UpdateURLRequest);
};
} // namespace content
#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_URL_REQUEST_H_
...@@ -67,7 +67,8 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() { ...@@ -67,7 +67,8 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() {
// We signal our caller with an empy callback that it needs to perform // We signal our caller with an empy callback that it needs to perform
// the network load. // the network load.
DCHECK(loader_callback_ && !binding_.is_bound()); DCHECK(loader_callback_);
DCHECK(!binding_.is_bound());
std::move(loader_callback_).Run({}); std::move(loader_callback_).Run({});
DeleteSoon(); DeleteSoon();
} }
......
...@@ -18,7 +18,7 @@ Refer to README.md for content description and update process. ...@@ -18,7 +18,7 @@ Refer to README.md for content description and update process.
<item id="affiliation_lookup" hash_code="111904019" type="0" content_hash_code="81061452" os_list="linux,windows" file_path="components/password_manager/core/browser/android_affiliation/affiliation_fetcher.cc"/> <item id="affiliation_lookup" hash_code="111904019" type="0" content_hash_code="81061452" os_list="linux,windows" file_path="components/password_manager/core/browser/android_affiliation/affiliation_fetcher.cc"/>
<item id="android_device_manager_socket" hash_code="37249086" type="0" content_hash_code="6436865" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_device_manager.cc"/> <item id="android_device_manager_socket" hash_code="37249086" type="0" content_hash_code="6436865" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_device_manager.cc"/>
<item id="android_web_socket" hash_code="39356976" type="0" content_hash_code="12310113" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_web_socket.cc"/> <item id="android_web_socket" hash_code="39356976" type="0" content_hash_code="12310113" os_list="linux,windows" file_path="chrome/browser/devtools/device/android_web_socket.cc"/>
<item id="appcache_update_job" hash_code="25790702" type="0" content_hash_code="27424887" os_list="linux,windows" file_path="content/browser/appcache/appcache_update_request_base.cc"/> <item id="appcache_update_job" hash_code="25790702" type="0" content_hash_code="27424887" os_list="linux,windows" file_path="content/browser/appcache/appcache_update_url_loader_request.cc"/>
<item id="autofill_query" hash_code="88863520" type="0" content_hash_code="15563339" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/> <item id="autofill_query" hash_code="88863520" type="0" content_hash_code="15563339" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/>
<item id="autofill_upload" hash_code="104798869" type="0" content_hash_code="110634763" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/> <item id="autofill_upload" hash_code="104798869" type="0" content_hash_code="110634763" os_list="linux,windows" file_path="components/autofill/core/browser/autofill_download_manager.cc"/>
<item id="backdrop_collection_images_download" hash_code="34767164" type="0" content_hash_code="103835921" os_list="linux,windows" file_path="chrome/browser/search/background/ntp_background_service.cc"/> <item id="backdrop_collection_images_download" hash_code="34767164" type="0" content_hash_code="103835921" os_list="linux,windows" file_path="chrome/browser/search/background/ntp_background_service.cc"/>
......
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