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() {
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() {
return nullptr;
}
......@@ -49,7 +29,8 @@ AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() {
}
AppCacheJob::AppCacheJob()
: cache_entry_not_found_(false), delivery_type_(AWAITING_DELIVERY_ORDERS) {}
: cache_entry_not_found_(false),
delivery_type_(DeliveryType::kAwaitingDeliverCall) {}
void AppCacheJob::InitializeRangeRequestInfo(
const net::HttpRequestHeaders& headers) {
......
......@@ -36,32 +36,40 @@ class AppCacheURLRequestJob;
// of the AppCache code.
class CONTENT_EXPORT AppCacheJob {
public:
enum DeliveryType {
AWAITING_DELIVERY_ORDERS,
APPCACHED_DELIVERY,
NETWORK_DELIVERY,
ERROR_DELIVERY
enum class DeliveryType {
kAwaitingDeliverCall,
kAppCached,
kNetwork,
kError,
};
virtual ~AppCacheJob();
// Returns true if the job was started.
// True if the job was started.
virtual bool IsStarted() const = 0;
// Returns true if the job is waiting for instructions.
virtual bool IsWaiting() const;
// True if the job is waiting for instructions.
bool IsWaiting() const {
return delivery_type_ == DeliveryType::kAwaitingDeliverCall;
}
// Returns true if the job is delivering a response from the cache.
virtual bool IsDeliveringAppCacheResponse() const;
// True if the job is delivering a response from the cache.
bool IsDeliveringAppCacheResponse() const {
return delivery_type_ == DeliveryType::kAppCached;
}
// 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.
virtual bool IsDeliveringErrorResponse() const;
bool IsDeliveringErrorResponse() const {
return delivery_type_ == DeliveryType::kError;
}
// 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
// methods should be called, and only once per job. A job will sit idle and
......
......@@ -22,8 +22,8 @@ AppCacheURLLoaderJob::~AppCacheURLLoaderJob() {
}
bool AppCacheURLLoaderJob::IsStarted() const {
return delivery_type_ != AWAITING_DELIVERY_ORDERS &&
delivery_type_ != NETWORK_DELIVERY;
return delivery_type_ != DeliveryType::kAwaitingDeliverCall &&
delivery_type_ != DeliveryType::kNetwork;
}
void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
......@@ -35,7 +35,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
return;
}
delivery_type_ = APPCACHED_DELIVERY;
delivery_type_ = DeliveryType::kAppCached;
// In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests())
......@@ -62,7 +62,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url,
}
void AppCacheURLLoaderJob::DeliverNetworkResponse() {
delivery_type_ = NETWORK_DELIVERY;
delivery_type_ = DeliveryType::kNetwork;
// In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests())
......@@ -76,7 +76,7 @@ void AppCacheURLLoaderJob::DeliverNetworkResponse() {
}
void AppCacheURLLoaderJob::DeliverErrorResponse() {
delivery_type_ = ERROR_DELIVERY;
delivery_type_ = DeliveryType::kError;
// In tests we only care about the delivery_type_ state.
if (AppCacheRequestHandler::IsRunningInTests())
......@@ -342,7 +342,7 @@ void AppCacheURLLoaderJob::NotifyCompleted(int error_code) {
}
client_->OnComplete(status);
if (delivery_type_ == APPCACHED_DELIVERY) {
if (delivery_type_ == DeliveryType::kAppCached) {
AppCacheHistograms::CountResponseRetrieval(
error_code == 0, is_main_resource_load_,
url::Origin::Create(manifest_url_));
......
......@@ -65,7 +65,7 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url,
bool is_fallback) {
DCHECK(!has_delivery_orders());
DCHECK(entry.has_response_id());
delivery_type_ = APPCACHED_DELIVERY;
delivery_type_ = DeliveryType::kAppCached;
manifest_url_ = manifest_url;
cache_id_ = cache_id;
entry_ = entry;
......@@ -75,14 +75,14 @@ void AppCacheURLRequestJob::DeliverAppCachedResponse(const GURL& manifest_url,
void AppCacheURLRequestJob::DeliverNetworkResponse() {
DCHECK(!has_delivery_orders());
delivery_type_ = NETWORK_DELIVERY;
delivery_type_ = DeliveryType::kNetwork;
storage_ = nullptr; // not needed
MaybeBeginDelivery();
}
void AppCacheURLRequestJob::DeliverErrorResponse() {
DCHECK(!has_delivery_orders());
delivery_type_ = ERROR_DELIVERY;
delivery_type_ = DeliveryType::kError;
storage_ = nullptr; // not needed
MaybeBeginDelivery();
}
......@@ -137,7 +137,7 @@ void AppCacheURLRequestJob::BeginDelivery() {
return;
switch (delivery_type_) {
case NETWORK_DELIVERY:
case DeliveryType::kNetwork:
// To fallthru to the network, we restart the request which will
// cause a new job to be created to retrieve the resource from the
// network. Our caller is responsible for arranging to not re-intercept
......@@ -145,14 +145,14 @@ void AppCacheURLRequestJob::BeginDelivery() {
NotifyRestartRequired();
break;
case ERROR_DELIVERY:
case DeliveryType::kError:
request()->net_log().AddEvent(
net::NetLogEventType::APPCACHE_DELIVERING_ERROR_RESPONSE);
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
net::ERR_FAILED));
break;
case APPCACHED_DELIVERY:
case DeliveryType::kAppCached:
request()->net_log().AddEvent(
is_fallback_
? net::NetLogEventType::APPCACHE_DELIVERING_FALLBACK_RESPONSE
......@@ -170,7 +170,7 @@ void AppCacheURLRequestJob::BeginErrorDelivery(const char* message) {
if (host_)
host_->frontend()->OnLogMessage(host_->host_id(), APPCACHE_LOG_ERROR,
message);
delivery_type_ = ERROR_DELIVERY;
delivery_type_ = DeliveryType::kError;
storage_ = nullptr;
BeginDelivery();
}
......@@ -249,7 +249,7 @@ net::LoadState AppCacheURLRequestJob::GetLoadState() const {
return net::LOAD_STATE_IDLE;
if (!has_delivery_orders())
return net::LOAD_STATE_WAITING_FOR_APPCACHE;
if (delivery_type_ != APPCACHED_DELIVERY)
if (delivery_type_ != DeliveryType::kAppCached)
return net::LOAD_STATE_IDLE;
if (!info_.get())
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