Index: net/http/http_cache_transaction.cc |
=================================================================== |
--- net/http/http_cache_transaction.cc (revision 147972) |
+++ net/http/http_cache_transaction.cc (working copy) |
@@ -32,6 +32,7 @@ |
#include "net/http/http_request_info.h" |
#include "net/http/http_response_headers.h" |
#include "net/http/http_transaction.h" |
+#include "net/http/http_transaction_delegate.h" |
#include "net/http/http_util.h" |
#include "net/http/partial_data.h" |
@@ -101,7 +102,8 @@ |
//----------------------------------------------------------------------------- |
-HttpCache::Transaction::Transaction(HttpCache* cache) |
+HttpCache::Transaction::Transaction(HttpCache* cache, |
+ HttpTransactionDelegate* delegate) |
: next_state_(STATE_NONE), |
request_(NULL), |
cache_(cache->AsWeakPtr()), |
@@ -126,7 +128,8 @@ |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( |
base::Bind(&Transaction::OnIOComplete, |
- weak_factory_.GetWeakPtr()))) { |
+ weak_factory_.GetWeakPtr()))), |
+ delegate_(delegate) { |
COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
arraysize(kValidationHeaders), |
Invalid_number_of_validation_headers); |
@@ -654,11 +657,13 @@ |
cache_pending_ = true; |
next_state_ = STATE_GET_BACKEND_COMPLETE; |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); |
+ ReportCacheActionStart(); |
return cache_->GetBackendForTransaction(this); |
} |
int HttpCache::Transaction::DoGetBackendComplete(int result) { |
DCHECK(result == OK || result == ERR_FAILED); |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, |
result); |
cache_pending_ = false; |
@@ -719,7 +724,7 @@ |
DCHECK(!network_trans_.get()); |
// Create a network transaction. |
- int rv = cache_->network_layer_->CreateTransaction(&network_trans_); |
+ int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL); |
if (rv != OK) |
return rv; |
@@ -847,6 +852,7 @@ |
next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
cache_pending_ = true; |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
+ ReportCacheActionStart(); |
return cache_->OpenEntry(cache_key_, &new_entry_, this); |
} |
@@ -854,6 +860,7 @@ |
// It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
// OK, otherwise the cache will end up with an active entry without any |
// transaction attached. |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); |
cache_pending_ = false; |
if (result == OK) { |
@@ -897,6 +904,7 @@ |
next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
cache_pending_ = true; |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
+ ReportCacheActionStart(); |
return cache_->CreateEntry(cache_key_, &new_entry_, this); |
} |
@@ -904,6 +912,7 @@ |
// It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
// OK, otherwise the cache will end up with an active entry without any |
// transaction attached. |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, |
result); |
cache_pending_ = false; |
@@ -932,10 +941,12 @@ |
next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
cache_pending_ = true; |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); |
+ ReportCacheActionStart(); |
return cache_->DoomEntry(cache_key_, this); |
} |
int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); |
next_state_ = STATE_CREATE_ENTRY; |
cache_pending_ = false; |
@@ -1137,15 +1148,18 @@ |
return OK; |
if (net_log_.IsLoggingAllEvents()) |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
- |
+ ReportCacheActionStart(); |
// Truncate the stream. |
return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
} |
int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
- if (net_log_.IsLoggingAllEvents() && entry_) { |
- net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
- result); |
+ if (entry_) { |
+ ReportCacheActionFinish(); |
+ if (net_log_.IsLoggingAllEvents()) { |
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
+ result); |
+ } |
} |
next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
@@ -1159,13 +1173,17 @@ |
if (net_log_.IsLoggingAllEvents()) |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
+ ReportCacheActionStart(); |
return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
} |
int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
- if (net_log_.IsLoggingAllEvents() && entry_) { |
- net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
- result); |
+ if (entry_) { |
+ ReportCacheActionFinish(); |
+ if (net_log_.IsLoggingAllEvents()) { |
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
+ result); |
+ } |
} |
// If this response is a redirect, then we can stop writing now. (We don't |
@@ -1207,11 +1225,13 @@ |
read_buf_ = new IOBuffer(io_buf_len_); |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
+ ReportCacheActionStart(); |
return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, |
io_buf_len_, io_callback_); |
} |
int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
if (result != io_buf_len_ || |
!HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
@@ -1256,14 +1276,20 @@ |
} |
int HttpCache::Transaction::DoCacheWriteResponse() { |
- if (net_log_.IsLoggingAllEvents() && entry_) |
- net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
+ if (entry_) { |
+ if (net_log_.IsLoggingAllEvents()) |
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
+ ReportCacheActionStart(); |
+ } |
return WriteResponseInfoToEntry(false); |
} |
int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
- if (net_log_.IsLoggingAllEvents() && entry_) |
- net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
+ if (entry_) { |
+ if (net_log_.IsLoggingAllEvents() && entry_) |
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
+ ReportCacheActionStart(); |
+ } |
return WriteResponseInfoToEntry(true); |
} |
@@ -1272,6 +1298,7 @@ |
target_state_ = STATE_NONE; |
if (!entry_) |
return OK; |
+ ReportCacheActionFinish(); |
if (net_log_.IsLoggingAllEvents()) { |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
result); |
@@ -1294,12 +1321,14 @@ |
new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
+ ReportCacheActionStart(); |
return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, |
response_.metadata->size(), |
io_callback_); |
} |
int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
if (result != response_.metadata->size()) |
return OnCacheReadError(result, false); |
@@ -1328,6 +1357,7 @@ |
if (net_log_.IsLoggingAllEvents()) |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); |
+ ReportCacheActionStart(); |
if (partial_.get()) { |
return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, |
io_callback_); |
@@ -1338,6 +1368,7 @@ |
} |
int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
+ ReportCacheActionFinish(); |
if (net_log_.IsLoggingAllEvents()) { |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, |
result); |
@@ -1363,16 +1394,22 @@ |
int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
write_len_ = num_bytes; |
- if (net_log_.IsLoggingAllEvents() && entry_) |
- net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
+ if (entry_) { |
+ if (net_log_.IsLoggingAllEvents()) |
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
+ ReportCacheActionStart(); |
+ } |
return AppendResponseDataToEntry(read_buf_, num_bytes, io_callback_); |
} |
int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
- if (net_log_.IsLoggingAllEvents() && entry_) { |
- net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
- result); |
+ if (entry_) { |
+ ReportCacheActionFinish(); |
+ if (net_log_.IsLoggingAllEvents()) { |
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, |
+ result); |
+ } |
} |
// Balance the AddRef from DoCacheWriteData. |
if (!cache_) |
@@ -2112,4 +2149,14 @@ |
DoLoop(result); |
} |
+void HttpCache::Transaction::ReportCacheActionStart() { |
+ if (delegate_) |
+ delegate_->OnCacheActionStart(); |
+} |
+ |
+void HttpCache::Transaction::ReportCacheActionFinish() { |
+ if (delegate_) |
+ delegate_->OnCacheActionFinish(); |
+} |
+ |
} // namespace net |