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

Unified Diff: net/http/http_cache_transaction.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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: net/http/http_cache_transaction.cc
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index e2d46be45350eec82cb3ec0850f1e792f17e98f2..020d9d6a2ce522d485fd56733d4b599388af72e9 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -87,7 +87,6 @@ enum RequestOfflineStatus {
// an offline error, and there was no servable data in cache (even
// stale data).
OFFLINE_STATUS_DATA_UNAVAILABLE_OFFLINE,
-
OFFLINE_STATUS_MAX_ENTRIES
};
@@ -95,19 +94,14 @@ void RecordOfflineStatus(int load_flags, RequestOfflineStatus status) {
// Restrict to main frame to keep statistics close to
// "would have shown them something useful if offline mode was enabled".
if (load_flags & net::LOAD_MAIN_FRAME) {
- UMA_HISTOGRAM_ENUMERATION("HttpCache.OfflineStatus", status,
- OFFLINE_STATUS_MAX_ENTRIES);
+ UMA_HISTOGRAM_ENUMERATION(
+ "HttpCache.OfflineStatus", status, OFFLINE_STATUS_MAX_ENTRIES);
}
}
// TODO(rvargas): Remove once we get the data.
void RecordVaryHeaderHistogram(const net::HttpResponseInfo* response) {
- enum VaryType {
- VARY_NOT_PRESENT,
- VARY_UA,
- VARY_OTHER,
- VARY_MAX
- };
+ enum VaryType { VARY_NOT_PRESENT, VARY_UA, VARY_OTHER, VARY_MAX };
VaryType vary = VARY_NOT_PRESENT;
if (response->vary_data.is_valid()) {
vary = VARY_OTHER;
@@ -129,11 +123,10 @@ struct HeaderNameAndValue {
// If the request includes one of these request headers, then avoid caching
// to avoid getting confused.
static const HeaderNameAndValue kPassThroughHeaders[] = {
- { "if-unmodified-since", NULL }, // causes unexpected 412s
- { "if-match", NULL }, // causes unexpected 412s
- { "if-range", NULL },
- { NULL, NULL }
-};
+ {"if-unmodified-since", NULL}, // causes unexpected 412s
+ {"if-match", NULL}, // causes unexpected 412s
+ {"if-range", NULL},
+ {NULL, NULL}};
struct ValidationHeaderInfo {
const char* request_header_name;
@@ -141,24 +134,22 @@ struct ValidationHeaderInfo {
};
static const ValidationHeaderInfo kValidationHeaders[] = {
- { "if-modified-since", "last-modified" },
- { "if-none-match", "etag" },
+ {"if-modified-since", "last-modified"},
+ {"if-none-match", "etag"},
};
// If the request includes one of these request headers, then avoid reusing
// our cached copy if any.
static const HeaderNameAndValue kForceFetchHeaders[] = {
- { "cache-control", "no-cache" },
- { "pragma", "no-cache" },
- { NULL, NULL }
-};
+ {"cache-control", "no-cache"},
+ {"pragma", "no-cache"},
+ {NULL, NULL}};
// If the request includes one of these request headers, then force our
// cached copy (if any) to be revalidated before reusing it.
static const HeaderNameAndValue kForceValidateHeaders[] = {
- { "cache-control", "max-age=0" },
- { NULL, NULL }
-};
+ {"cache-control", "max-age=0"},
+ {NULL, NULL}};
static bool HeaderMatches(const HttpRequestHeaders& headers,
const HeaderNameAndValue* search) {
@@ -181,9 +172,7 @@ static bool HeaderMatches(const HttpRequestHeaders& headers,
//-----------------------------------------------------------------------------
-HttpCache::Transaction::Transaction(
- RequestPriority priority,
- HttpCache* cache)
+HttpCache::Transaction::Transaction(RequestPriority priority, HttpCache* cache)
: next_state_(STATE_NONE),
request_(NULL),
priority_(priority),
@@ -208,13 +197,13 @@ HttpCache::Transaction::Transaction(
effective_load_flags_(0),
write_len_(0),
weak_factory_(this),
- io_callback_(base::Bind(&Transaction::OnIOComplete,
- weak_factory_.GetWeakPtr())),
+ io_callback_(
+ base::Bind(&Transaction::OnIOComplete, weak_factory_.GetWeakPtr())),
transaction_pattern_(PATTERN_UNDEFINED),
total_received_bytes_(0),
websocket_handshake_stream_base_create_helper_(NULL) {
COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders ==
- arraysize(kValidationHeaders),
+ arraysize(kValidationHeaders),
Invalid_number_of_validation_headers);
}
@@ -241,7 +230,8 @@ HttpCache::Transaction::~Transaction() {
}
}
-int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len,
+int HttpCache::Transaction::WriteMetadata(IOBuffer* buf,
+ int buf_len,
const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_GT(buf_len, 0);
@@ -253,8 +243,8 @@ int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len,
// It could be possible to check if there is something already written and
// avoid writing again (it should be the same, right?), but let's allow the
// caller to "update" the contents with something new.
- return entry_->disk_entry->WriteData(kMetadataIndex, 0, buf, buf_len,
- callback, true);
+ return entry_->disk_entry->WriteData(
+ kMetadataIndex, 0, buf, buf_len, callback, true);
}
bool HttpCache::Transaction::AddTruncatedFlag() {
@@ -385,7 +375,8 @@ bool HttpCache::Transaction::IsReadyToRestartForAuth() {
return network_trans_->IsReadyToRestartForAuth();
}
-int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
+int HttpCache::Transaction::Read(IOBuffer* buf,
+ int buf_len,
const CompletionCallback& callback) {
DCHECK(buf);
DCHECK_GT(buf_len, 0);
@@ -514,7 +505,8 @@ UploadProgress HttpCache::Transaction::GetUploadProgress() const {
}
void HttpCache::Transaction::SetQuicServerInfo(
- QuicServerInfo* quic_server_info) {}
+ QuicServerInfo* quic_server_info) {
+}
bool HttpCache::Transaction::GetLoadTimingInfo(
LoadTimingInfo* load_timing_info) const {
@@ -879,8 +871,8 @@ int HttpCache::Transaction::DoSendRequest() {
send_request_since_ = TimeTicks::Now();
// Create a network transaction.
- int rv = cache_->network_layer_->CreateTransaction(priority_,
- &network_trans_);
+ int rv =
+ cache_->network_layer_->CreateTransaction(priority_, &network_trans_);
if (rv != OK)
return rv;
network_trans_->SetBeforeNetworkStartCallback(before_network_start_callback_);
@@ -919,8 +911,8 @@ int HttpCache::Transaction::DoSendRequestComplete(int result) {
}
} else {
RecordOfflineStatus(effective_load_flags_,
- (result == OK ? OFFLINE_STATUS_NETWORK_SUCCEEDED :
- OFFLINE_STATUS_NETWORK_FAILED));
+ (result == OK ? OFFLINE_STATUS_NETWORK_SUCCEEDED
+ : OFFLINE_STATUS_NETWORK_FAILED));
}
// If we tried to conditionalize the request and failed, we know
@@ -1360,8 +1352,8 @@ int HttpCache::Transaction::DoOverwriteCachedResponse() {
}
target_state_ = STATE_TRUNCATE_CACHED_DATA;
- next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE :
- STATE_CACHE_WRITE_RESPONSE;
+ next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE
+ : STATE_CACHE_WRITE_RESPONSE;
return OK;
}
@@ -1440,15 +1432,15 @@ int HttpCache::Transaction::DoCacheReadResponse() {
read_buf_ = new IOBuffer(io_buf_len_);
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO);
- return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(),
- io_buf_len_, io_callback_);
+ return entry_->disk_entry->ReadData(
+ kResponseInfoIndex, 0, read_buf_.get(), io_buf_len_, io_callback_);
}
int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
if (result != io_buf_len_ ||
- !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_,
- &response_, &truncated_)) {
+ !HttpCache::ParseResponseInfo(
+ read_buf_->data(), io_buf_len_, &response_, &truncated_)) {
return OnCacheReadError(result, true);
}
@@ -1532,7 +1524,8 @@ int HttpCache::Transaction::DoCacheReadMetadata() {
new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO);
- return entry_->disk_entry->ReadData(kMetadataIndex, 0,
+ return entry_->disk_entry->ReadData(kMetadataIndex,
+ 0,
response_.metadata.get(),
response_.metadata->size(),
io_callback_);
@@ -1571,12 +1564,14 @@ int HttpCache::Transaction::DoCacheReadData() {
if (net_log_.IsLogging())
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA);
if (partial_.get()) {
- return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_,
- io_callback_);
+ return partial_->CacheRead(
+ entry_->disk_entry, read_buf_.get(), io_buf_len_, io_callback_);
}
- return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
- read_buf_.get(), io_buf_len_,
+ return entry_->disk_entry->ReadData(kResponseContentIndex,
+ read_offset_,
+ read_buf_.get(),
+ io_buf_len_,
io_callback_);
}
@@ -1702,10 +1697,10 @@ void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log,
const HeaderNameAndValue* search;
int load_flag;
} kSpecialHeaders[] = {
- { kPassThroughHeaders, LOAD_DISABLE_CACHE },
- { kForceFetchHeaders, LOAD_BYPASS_CACHE },
- { kForceValidateHeaders, LOAD_VALIDATE_CACHE },
- };
+ {kPassThroughHeaders, LOAD_DISABLE_CACHE},
+ {kForceFetchHeaders, LOAD_BYPASS_CACHE},
+ {kForceValidateHeaders, LOAD_VALIDATE_CACHE},
+ };
bool range_found = false;
bool external_validation_error = false;
@@ -1725,10 +1720,9 @@ void HttpCache::Transaction::SetRequest(const BoundNetLog& net_log,
for (size_t i = 0; i < arraysize(kValidationHeaders); ++i) {
const ValidationHeaderInfo& info = kValidationHeaders[i];
std::string validation_value;
- if (request_->extra_headers.GetHeader(
- info.request_header_name, &validation_value)) {
- if (!external_validation_.values[i].empty() ||
- validation_value.empty()) {
+ if (request_->extra_headers.GetHeader(info.request_header_name,
+ &validation_value)) {
+ if (!external_validation_.values[i].empty() || validation_value.empty()) {
external_validation_error = true;
}
external_validation_.values[i] = validation_value;
@@ -1912,15 +1906,13 @@ int HttpCache::Transaction::BeginExternallyConditionalizedRequest() {
DCHECK_EQ(UPDATE, mode_);
DCHECK(external_validation_.initialized);
- for (size_t i = 0; i < arraysize(kValidationHeaders); i++) {
+ for (size_t i = 0; i < arraysize(kValidationHeaders); i++) {
if (external_validation_.values[i].empty())
continue;
// Retrieve either the cached response's "etag" or "last-modified" header.
std::string validator;
response_.headers->EnumerateHeader(
- NULL,
- kValidationHeaders[i].related_response_header_name,
- &validator);
+ NULL, kValidationHeaders[i].related_response_header_name, &validator);
if (response_.headers->response_code() != 200 || truncated_ ||
validator.empty() || validator != external_validation_.values[i]) {
@@ -2031,8 +2023,8 @@ bool HttpCache::Transaction::ConditionalizeRequest() {
std::string last_modified_value;
if (!vary_mismatch_) {
- response_.headers->EnumerateHeader(NULL, "last-modified",
- &last_modified_value);
+ response_.headers->EnumerateHeader(
+ NULL, "last-modified", &last_modified_value);
}
if (etag_value.empty() && last_modified_value.empty())
@@ -2045,18 +2037,18 @@ bool HttpCache::Transaction::ConditionalizeRequest() {
}
DCHECK(custom_request_.get());
- bool use_if_range = partial_.get() && !partial_->IsCurrentRangeCached() &&
- !invalid_range_;
+ bool use_if_range =
+ partial_.get() && !partial_->IsCurrentRangeCached() && !invalid_range_;
if (!etag_value.empty()) {
if (use_if_range) {
// We don't want to switch to WRITE mode if we don't have this block of a
// byte-range request because we may have other parts cached.
- custom_request_->extra_headers.SetHeader(
- HttpRequestHeaders::kIfRange, etag_value);
+ custom_request_->extra_headers.SetHeader(HttpRequestHeaders::kIfRange,
+ etag_value);
} else {
- custom_request_->extra_headers.SetHeader(
- HttpRequestHeaders::kIfNoneMatch, etag_value);
+ custom_request_->extra_headers.SetHeader(HttpRequestHeaders::kIfNoneMatch,
+ etag_value);
}
// For byte-range requests, make sure that we use only one way to validate
// the request.
@@ -2066,8 +2058,8 @@ bool HttpCache::Transaction::ConditionalizeRequest() {
if (!last_modified_value.empty()) {
if (use_if_range) {
- custom_request_->extra_headers.SetHeader(
- HttpRequestHeaders::kIfRange, last_modified_value);
+ custom_request_->extra_headers.SetHeader(HttpRequestHeaders::kIfRange,
+ last_modified_value);
} else {
custom_request_->extra_headers.SetHeader(
HttpRequestHeaders::kIfModifiedSince, last_modified_value);
@@ -2230,7 +2222,6 @@ int HttpCache::Transaction::SetupEntryForRead() {
return OK;
}
-
int HttpCache::Transaction::ReadFromNetwork(IOBuffer* data, int data_len) {
read_buf_ = data;
io_buf_len_ = data_len;
@@ -2245,16 +2236,18 @@ int HttpCache::Transaction::ReadFromEntry(IOBuffer* data, int data_len) {
return DoLoop(OK);
}
-int HttpCache::Transaction::WriteToEntry(int index, int offset,
- IOBuffer* data, int data_len,
+int HttpCache::Transaction::WriteToEntry(int index,
+ int offset,
+ IOBuffer* data,
+ int data_len,
const CompletionCallback& callback) {
if (!entry_)
return data_len;
int rv = 0;
if (!partial_.get() || !data_len) {
- rv = entry_->disk_entry->WriteData(index, offset, data, data_len, callback,
- true);
+ rv = entry_->disk_entry->WriteData(
+ index, offset, data, data_len, callback, true);
} else {
rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback);
}
@@ -2296,18 +2289,20 @@ int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) {
data->Done();
io_buf_len_ = data->pickle()->size();
- return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data.get(),
- io_buf_len_, io_callback_, true);
+ return entry_->disk_entry->WriteData(
+ kResponseInfoIndex, 0, data.get(), io_buf_len_, io_callback_, true);
}
int HttpCache::Transaction::AppendResponseDataToEntry(
- IOBuffer* data, int data_len, const CompletionCallback& callback) {
+ IOBuffer* data,
+ int data_len,
+ const CompletionCallback& callback) {
if (!entry_ || !data_len)
return data_len;
int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
- return WriteToEntry(kResponseContentIndex, current_size, data, data_len,
- callback);
+ return WriteToEntry(
+ kResponseContentIndex, current_size, data, data_len, callback);
}
void HttpCache::Transaction::DoneWritingToEntry(bool success) {
@@ -2464,13 +2459,12 @@ void HttpCache::Transaction::RecordHistograms() {
UMA_HISTOGRAM_TIMES("HttpCache.AccessToDone", total_time);
bool did_send_request = !send_request_since_.is_null();
- DCHECK(
- (did_send_request &&
- (transaction_pattern_ == PATTERN_ENTRY_NOT_CACHED ||
- transaction_pattern_ == PATTERN_ENTRY_VALIDATED ||
- transaction_pattern_ == PATTERN_ENTRY_UPDATED ||
- transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE)) ||
- (!did_send_request && transaction_pattern_ == PATTERN_ENTRY_USED));
+ DCHECK((did_send_request &&
+ (transaction_pattern_ == PATTERN_ENTRY_NOT_CACHED ||
+ transaction_pattern_ == PATTERN_ENTRY_VALIDATED ||
+ transaction_pattern_ == PATTERN_ENTRY_UPDATED ||
+ transaction_pattern_ == PATTERN_ENTRY_CANT_CONDITIONALIZE)) ||
+ (!did_send_request && transaction_pattern_ == PATTERN_ENTRY_USED));
if (!did_send_request) {
DCHECK(transaction_pattern_ == PATTERN_ENTRY_USED);
@@ -2479,9 +2473,9 @@ void HttpCache::Transaction::RecordHistograms() {
}
TimeDelta before_send_time = send_request_since_ - first_cache_access_since_;
- int before_send_percent =
- total_time.ToInternalValue() == 0 ? 0
- : before_send_time * 100 / total_time;
+ int before_send_percent = total_time.ToInternalValue() == 0
+ ? 0
+ : before_send_time * 100 / total_time;
DCHECK_LE(0, before_send_percent);
DCHECK_GE(100, before_send_percent);

Powered by Google App Engine
This is Rietveld 408576698