Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: content/browser/appcache/appcache_url_request_job.cc

Issue 2865613002: Add an abstraction for a job in the AppCacheRequestHandler class. (Closed)
Patch Set: Fix compile failures Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/appcache/appcache_url_request_job.cc
diff --git a/content/browser/appcache/appcache_url_request_job.cc b/content/browser/appcache/appcache_url_request_job.cc
index 467f39f6da7adc22e68bb1b2d2bd47241f0e29d2..8a89def4a7ed1aebe8a46ed1f0e77d221e86a631 100644
--- a/content/browser/appcache/appcache_url_request_job.cc
+++ b/content/browser/appcache/appcache_url_request_job.cc
@@ -32,33 +32,54 @@
namespace content {
-AppCacheURLRequestJob::AppCacheURLRequestJob(
- net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- AppCacheStorage* storage,
- AppCacheHost* host,
- bool is_main_resource,
- const OnPrepareToRestartCallback& restart_callback)
- : net::URLRequestJob(request, network_delegate),
- host_(host),
- storage_(storage),
- has_been_started_(false),
- has_been_killed_(false),
- delivery_type_(AWAITING_DELIVERY_ORDERS),
- cache_id_(kAppCacheNoCacheId),
- is_fallback_(false),
- is_main_resource_(is_main_resource),
- cache_entry_not_found_(false),
- on_prepare_to_restart_callback_(restart_callback),
- weak_factory_(this) {
- DCHECK(storage_);
-}
-
AppCacheURLRequestJob::~AppCacheURLRequestJob() {
if (storage_)
storage_->CancelDelegateCallbacks(this);
}
+void AppCacheURLRequestJob::Kill() {
+ if (!has_been_killed_) {
+ has_been_killed_ = true;
+ reader_.reset();
+ handler_source_reader_.reset();
+ if (storage_) {
+ storage_->CancelDelegateCallbacks(this);
+ storage_ = NULL;
+ }
+ host_ = NULL;
+ info_ = NULL;
+ cache_ = NULL;
+ group_ = NULL;
+ range_response_info_.reset();
+ net::URLRequestJob::Kill();
+ AppCacheJob::weak_factory_.InvalidateWeakPtrs();
+ }
+}
+
+bool AppCacheURLRequestJob::IsStarted() const {
+ return has_been_started_;
+}
+
+bool AppCacheURLRequestJob::IsWaiting() const {
+ return delivery_type_ == AWAITING_DELIVERY_ORDERS;
+}
+
+bool AppCacheURLRequestJob::IsDeliveringAppCacheResponse() const {
+ return delivery_type_ == APPCACHED_DELIVERY;
+}
+
+bool AppCacheURLRequestJob::IsDeliveringNetworkResponse() const {
+ return delivery_type_ == NETWORK_DELIVERY;
+}
+
+bool AppCacheURLRequestJob::IsDeliveringErrorResponse() const {
+ return delivery_type_ == ERROR_DELIVERY;
+}
+
+bool AppCacheURLRequestJob::IsCacheEntryNotFound() const {
+ return cache_entry_not_found_;
+}
+
void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url,
int64_t cache_id,
const AppCacheEntry& entry,
@@ -87,22 +108,47 @@ void AppCacheURLRequestJob::DeliverErrorResponse() {
MaybeBeginDelivery();
}
-base::WeakPtr<AppCacheURLRequestJob> AppCacheURLRequestJob::GetWeakPtr() {
- return weak_factory_.GetWeakPtr();
+const GURL& AppCacheURLRequestJob::GetURL() const {
+ return request()->url();
+}
+
+net::URLRequestJob* AppCacheURLRequestJob::AsURLRequestJob() {
+ return this;
+}
+
+AppCacheURLRequestJob::AppCacheURLRequestJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ AppCacheStorage* storage,
+ AppCacheHost* host,
+ bool is_main_resource,
+ const OnPrepareToRestartCallback& restart_callback)
+ : net::URLRequestJob(request, network_delegate),
+ host_(host),
+ storage_(storage),
+ has_been_started_(false),
+ has_been_killed_(false),
+ delivery_type_(AWAITING_DELIVERY_ORDERS),
+ cache_id_(kAppCacheNoCacheId),
+ is_fallback_(false),
+ is_main_resource_(is_main_resource),
+ cache_entry_not_found_(false),
+ on_prepare_to_restart_callback_(restart_callback) {
+ DCHECK(storage_);
}
void AppCacheURLRequestJob::MaybeBeginDelivery() {
- if (has_been_started() && has_delivery_orders()) {
+ if (IsStarted() && has_delivery_orders()) {
// Start asynchronously so that all error reporting and data
// callbacks happen as they would for network requests.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&AppCacheURLRequestJob::BeginDelivery,
- weak_factory_.GetWeakPtr()));
+ StaticAsWeakPtr(this)));
}
}
void AppCacheURLRequestJob::BeginDelivery() {
- DCHECK(has_delivery_orders() && has_been_started());
+ DCHECK(has_delivery_orders() && IsStarted());
if (has_been_killed())
return;
@@ -236,7 +282,7 @@ void AppCacheURLRequestJob::InvokeExecutableHandler(
handler->HandleRequest(
request(),
base::Bind(&AppCacheURLRequestJob::OnExecutableResponseCallback,
- weak_factory_.GetWeakPtr()));
+ StaticAsWeakPtr(this)));
}
void AppCacheURLRequestJob::OnExecutableResponseCallback(
@@ -280,7 +326,7 @@ void AppCacheURLRequestJob::BeginErrorDelivery(const char* message) {
void AppCacheURLRequestJob::OnResponseInfoLoaded(
AppCacheResponseInfo* response_info,
int64_t response_id) {
- DCHECK(is_delivering_appcache_response());
+ DCHECK(IsDeliveringAppCacheResponse());
if (response_info) {
info_ = response_info;
reader_.reset(
@@ -317,7 +363,7 @@ const net::HttpResponseInfo* AppCacheURLRequestJob::http_info() const {
void AppCacheURLRequestJob::SetupRangeResponse() {
DCHECK(is_range_request() && info_.get() && reader_.get() &&
- is_delivering_appcache_response());
+ IsDeliveringAppCacheResponse());
int resource_size = static_cast<int>(info_->response_data_size());
if (resource_size < 0 || !range_requested_.ComputeBounds(resource_size)) {
range_requested_ = net::HttpByteRange();
@@ -342,7 +388,7 @@ void AppCacheURLRequestJob::SetupRangeResponse() {
}
void AppCacheURLRequestJob::OnReadComplete(int result) {
- DCHECK(is_delivering_appcache_response());
+ DCHECK(IsDeliveringAppCacheResponse());
if (result == 0) {
AppCacheHistograms::CountResponseRetrieval(
true, is_main_resource_, manifest_url_.GetOrigin());
@@ -360,33 +406,14 @@ void AppCacheURLRequestJob::OnReadComplete(int result) {
// net::URLRequestJob overrides ------------------------------------------------
void AppCacheURLRequestJob::Start() {
- DCHECK(!has_been_started());
+ DCHECK(!IsStarted());
has_been_started_ = true;
start_time_tick_ = base::TimeTicks::Now();
MaybeBeginDelivery();
}
-void AppCacheURLRequestJob::Kill() {
- if (!has_been_killed_) {
- has_been_killed_ = true;
- reader_.reset();
- handler_source_reader_.reset();
- if (storage_) {
- storage_->CancelDelegateCallbacks(this);
- storage_ = NULL;
- }
- host_ = NULL;
- info_ = NULL;
- cache_ = NULL;
- group_ = NULL;
- range_response_info_.reset();
- net::URLRequestJob::Kill();
- weak_factory_.InvalidateWeakPtrs();
- }
-}
-
net::LoadState AppCacheURLRequestJob::GetLoadState() const {
- if (!has_been_started())
+ if (!IsStarted())
return net::LOAD_STATE_IDLE;
if (!has_delivery_orders())
return net::LOAD_STATE_WAITING_FOR_APPCACHE;
@@ -418,7 +445,7 @@ void AppCacheURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) {
}
int AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) {
- DCHECK(is_delivering_appcache_response());
+ DCHECK(IsDeliveringAppCacheResponse());
DCHECK_NE(buf_size, 0);
DCHECK(!reader_->IsReadPending());
reader_->ReadData(buf, buf_size,
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.h ('k') | content/browser/appcache/appcache_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698