Commit 1959608c authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Switch AppCacheJob::DeliveryType to class enum.

Switching from enum to class enum removes the implicit conversions to
int.

This CL also switches DeliveryType members from SHOUTY_CASE to
kModernConstCase and de-virtualizes a few AppCacheJob methods with a
simple implementation. These changes are intended to improve the code's
readability.

Change-Id: I35f8e8007f7abce2371c3cc8200c9e756529ba1f
Reviewed-on: https://chromium-review.googlesource.com/c/1263890Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597170}
parent cd1c7208
...@@ -20,26 +20,6 @@ AppCacheJob::~AppCacheJob() { ...@@ -20,26 +20,6 @@ AppCacheJob::~AppCacheJob() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
} }
bool AppCacheJob::IsWaiting() const {
return delivery_type_ == AWAITING_DELIVERY_ORDERS;
}
bool AppCacheJob::IsDeliveringAppCacheResponse() const {
return delivery_type_ == APPCACHED_DELIVERY;
}
bool AppCacheJob::IsDeliveringNetworkResponse() const {
return delivery_type_ == NETWORK_DELIVERY;
}
bool AppCacheJob::IsDeliveringErrorResponse() const {
return delivery_type_ == ERROR_DELIVERY;
}
bool AppCacheJob::IsCacheEntryNotFound() const {
return cache_entry_not_found_;
}
AppCacheURLRequestJob* AppCacheJob::AsURLRequestJob() { AppCacheURLRequestJob* AppCacheJob::AsURLRequestJob() {
return nullptr; return nullptr;
} }
...@@ -49,7 +29,8 @@ AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() { ...@@ -49,7 +29,8 @@ AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() {
} }
AppCacheJob::AppCacheJob() AppCacheJob::AppCacheJob()
: cache_entry_not_found_(false), delivery_type_(AWAITING_DELIVERY_ORDERS) {} : cache_entry_not_found_(false),
delivery_type_(DeliveryType::kAwaitingDeliverCall) {}
void AppCacheJob::InitializeRangeRequestInfo( void AppCacheJob::InitializeRangeRequestInfo(
const net::HttpRequestHeaders& headers) { const net::HttpRequestHeaders& headers) {
......
...@@ -36,32 +36,40 @@ class AppCacheURLRequestJob; ...@@ -36,32 +36,40 @@ class AppCacheURLRequestJob;
// of the AppCache code. // of the AppCache code.
class CONTENT_EXPORT AppCacheJob { class CONTENT_EXPORT AppCacheJob {
public: public:
enum DeliveryType { enum class DeliveryType {
AWAITING_DELIVERY_ORDERS, kAwaitingDeliverCall,
APPCACHED_DELIVERY, kAppCached,
NETWORK_DELIVERY, kNetwork,
ERROR_DELIVERY kError,
}; };
virtual ~AppCacheJob(); virtual ~AppCacheJob();
// Returns true if the job was started. // True if the job was started.
virtual bool IsStarted() const = 0; virtual bool IsStarted() const = 0;
// Returns true if the job is waiting for instructions. // True if the job is waiting for instructions.
virtual bool IsWaiting() const; bool IsWaiting() const {
return delivery_type_ == DeliveryType::kAwaitingDeliverCall;
}
// Returns true if the job is delivering a response from the cache. // True if the job is delivering a response from the cache.
virtual bool IsDeliveringAppCacheResponse() const; bool IsDeliveringAppCacheResponse() const {
return delivery_type_ == DeliveryType::kAppCached;
}
// Returns true if the job is delivering a response from the network. // Returns true if the job is delivering a response from the network.
virtual bool IsDeliveringNetworkResponse() const; bool IsDeliveringNetworkResponse() const {
return delivery_type_ == DeliveryType::kNetwork;
}
// Returns true if the job is delivering an error response. // Returns true if the job is delivering an error response.
virtual bool IsDeliveringErrorResponse() const; bool IsDeliveringErrorResponse() const {
return delivery_type_ == DeliveryType::kError;
}
// Returns true if the cache entry was not found in the cache. // Returns true if the cache entry was not found in the cache.
virtual bool IsCacheEntryNotFound() const; bool IsCacheEntryNotFound() const { return cache_entry_not_found_; }
// Informs the job of what response it should deliver. Only one of these // Informs the job of what response it should deliver. Only one of these
// methods should be called, and only once per job. A job will sit idle and // methods should be called, and only once per job. A job will sit idle and
......
...@@ -22,8 +22,8 @@ AppCacheURLLoaderJob::~AppCacheURLLoaderJob() { ...@@ -22,8 +22,8 @@ AppCacheURLLoaderJob::~AppCacheURLLoaderJob() {
} }
bool AppCacheURLLoaderJob::IsStarted() const { bool AppCacheURLLoaderJob::IsStarted() const {
return delivery_type_ != AWAITING_DELIVERY_ORDERS && return delivery_type_ != DeliveryType::kAwaitingDeliverCall &&
delivery_type_ != NETWORK_DELIVERY; delivery_type_ != DeliveryType::kNetwork;
} }
void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url, void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
...@@ -35,7 +35,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url, ...@@ -35,7 +35,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
return; return;
} }
delivery_type_ = APPCACHED_DELIVERY; delivery_type_ = DeliveryType::kAppCached;
// In tests we only care about the delivery_type_ state. // In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests()) if (AppCacheRequestHandler::IsRunningInTests())
...@@ -62,7 +62,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url, ...@@ -62,7 +62,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
} }
void AppCacheURLLoaderJob::DeliverNetworkResponse() { void AppCacheURLLoaderJob::DeliverNetworkResponse() {
delivery_type_ = NETWORK_DELIVERY; delivery_type_ = DeliveryType::kNetwork;
// In tests we only care about the delivery_type_ state. // In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests()) if (AppCacheRequestHandler::IsRunningInTests())
...@@ -76,7 +76,7 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() { ...@@ -76,7 +76,7 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() {
} }
void AppCacheURLLoaderJob::DeliverErrorResponse() { void AppCacheURLLoaderJob::DeliverErrorResponse() {
delivery_type_ = ERROR_DELIVERY; delivery_type_ = DeliveryType::kError;
// In tests we only care about the delivery_type_ state. // In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests()) if (AppCacheRequestHandler::IsRunningInTests())
...@@ -342,7 +342,7 @@ void AppCacheURLLoaderJob::NotifyCompleted(int error_code) { ...@@ -342,7 +342,7 @@ void AppCacheURLLoaderJob::NotifyCompleted(int error_code) {
} }
client_->OnComplete(status); client_->OnComplete(status);
if (delivery_type_ == APPCACHED_DELIVERY) { if (delivery_type_ == DeliveryType::kAppCached) {
AppCacheHistograms::CountResponseRetrieval( AppCacheHistograms::CountResponseRetrieval(
error_code == 0, is_main_resource_load_, error_code == 0, is_main_resource_load_,
url::Origin::Create(manifest_url_)); url::Origin::Create(manifest_url_));
......
...@@ -65,7 +65,7 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url, ...@@ -65,7 +65,7 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url,
bool is_fallback) { bool is_fallback) {
DCHECK(!has_delivery_orders()); DCHECK(!has_delivery_orders());
DCHECK(entry.has_response_id()); DCHECK(entry.has_response_id());
delivery_type_ = APPCACHED_DELIVERY; delivery_type_ = DeliveryType::kAppCached;
manifest_url_ = manifest_url; manifest_url_ = manifest_url;
cache_id_ = cache_id; cache_id_ = cache_id;
entry_ = entry; entry_ = entry;
...@@ -75,14 +75,14 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url, ...@@ -75,14 +75,14 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url,
void AppCacheURLRequestJob::DeliverNetworkResponse() { void AppCacheURLRequestJob::DeliverNetworkResponse() {
DCHECK(!has_delivery_orders()); DCHECK(!has_delivery_orders());
delivery_type_ = NETWORK_DELIVERY; delivery_type_ = DeliveryType::kNetwork;
storage_ = nullptr; // not needed storage_ = nullptr; // not needed
MaybeBeginDelivery(); MaybeBeginDelivery();
} }
void AppCacheURLRequestJob::DeliverErrorResponse() { void AppCacheURLRequestJob::DeliverErrorResponse() {
DCHECK(!has_delivery_orders()); DCHECK(!has_delivery_orders());
delivery_type_ = ERROR_DELIVERY; delivery_type_ = DeliveryType::kError;
storage_ = nullptr; // not needed storage_ = nullptr; // not needed
MaybeBeginDelivery(); MaybeBeginDelivery();
} }
...@@ -137,7 +137,7 @@ void AppCacheURLRequestJob::BeginDelivery() { ...@@ -137,7 +137,7 @@ void AppCacheURLRequestJob::BeginDelivery() {
return; return;
switch (delivery_type_) { switch (delivery_type_) {
case NETWORK_DELIVERY: case DeliveryType::kNetwork:
// To fallthru to the network, we restart the request which will // To fallthru to the network, we restart the request which will
// cause a new job to be created to retrieve the resource from the // cause a new job to be created to retrieve the resource from the
// network. Our caller is responsible for arranging to not re-intercept // network. Our caller is responsible for arranging to not re-intercept
...@@ -145,14 +145,14 @@ void AppCacheURLRequestJob::BeginDelivery() { ...@@ -145,14 +145,14 @@ void AppCacheURLRequestJob::BeginDelivery() {
NotifyRestartRequired(); NotifyRestartRequired();
break; break;
case ERROR_DELIVERY: case DeliveryType::kError:
request()->net_log().AddEvent( request()->net_log().AddEvent(
net::NetLogEventType::APPCACHE_DELIVERING_ERROR_RESPONSE); net::NetLogEventType::APPCACHE_DELIVERING_ERROR_RESPONSE);
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_FAILED)); net::ERR_FAILED));
break; break;
case APPCACHED_DELIVERY: case DeliveryType::kAppCached:
request()->net_log().AddEvent( request()->net_log().AddEvent(
is_fallback_ is_fallback_
? net::NetLogEventType::APPCACHE_DELIVERING_FALLBACK_RESPONSE ? net::NetLogEventType::APPCACHE_DELIVERING_FALLBACK_RESPONSE
...@@ -170,7 +170,7 @@ void AppCacheURLRequestJob::BeginErrorDelivery(const char* message) { ...@@ -170,7 +170,7 @@ void AppCacheURLRequestJob::BeginErrorDelivery(const char* message) {
if (host_) if (host_)
host_->frontend()->OnLogMessage(host_->host_id(), APPCACHE_LOG_ERROR, host_->frontend()->OnLogMessage(host_->host_id(), APPCACHE_LOG_ERROR,
message); message);
delivery_type_ = ERROR_DELIVERY; delivery_type_ = DeliveryType::kError;
storage_ = nullptr; storage_ = nullptr;
BeginDelivery(); BeginDelivery();
} }
...@@ -249,7 +249,7 @@ net::LoadState AppCacheURLRequestJob::GetLoadState() const { ...@@ -249,7 +249,7 @@ net::LoadState AppCacheURLRequestJob::GetLoadState() const {
return net::LOAD_STATE_IDLE; return net::LOAD_STATE_IDLE;
if (!has_delivery_orders()) if (!has_delivery_orders())
return net::LOAD_STATE_WAITING_FOR_APPCACHE; return net::LOAD_STATE_WAITING_FOR_APPCACHE;
if (delivery_type_ != APPCACHED_DELIVERY) if (delivery_type_ != DeliveryType::kAppCached)
return net::LOAD_STATE_IDLE; return net::LOAD_STATE_IDLE;
if (!info_.get()) if (!info_.get())
return net::LOAD_STATE_WAITING_FOR_APPCACHE; return net::LOAD_STATE_WAITING_FOR_APPCACHE;
......
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