Index: net/http/http_cache_transaction.cc |
=================================================================== |
--- net/http/http_cache_transaction.cc (revision 147723) |
+++ 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" |
@@ -99,7 +100,8 @@ |
//----------------------------------------------------------------------------- |
-HttpCache::Transaction::Transaction(HttpCache* cache) |
+HttpCache::Transaction::Transaction(HttpCache* cache, |
+ HttpTransactionDelegate* delegate) |
: next_state_(STATE_NONE), |
request_(NULL), |
cache_(cache->AsWeakPtr()), |
@@ -124,7 +126,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); |
@@ -652,11 +655,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; |
@@ -717,7 +722,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); |
rvargas (doing something else)
2012/07/23 22:22:36
It would be interesting to track the network activ
tburkard
2012/07/24 01:03:12
(nothing to do here).
On 2012/07/23 22:22:36, rva
|
if (rv != OK) |
return rv; |
@@ -845,6 +850,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); |
} |
@@ -852,6 +858,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) { |
@@ -895,6 +902,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); |
} |
@@ -902,6 +910,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; |
@@ -930,10 +939,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; |
@@ -948,12 +959,14 @@ |
cache_pending_ = true; |
next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
+ ReportCacheActionStart(); |
rvargas (doing something else)
2012/07/23 22:22:36
We should treat this one some other way. This is n
tburkard
2012/07/24 01:03:12
Why is the distinction important? What is the dif
rvargas (doing something else)
2012/07/24 03:10:38
No matter what we change at the disk cache layer,
tburkard
2012/07/24 22:23:26
Done.
|
DCHECK(entry_lock_waiting_since_.is_null()); |
entry_lock_waiting_since_ = base::TimeTicks::Now(); |
return cache_->AddTransactionToEntry(new_entry_, this); |
} |
int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
+ ReportCacheActionFinish(); |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
result); |
@@ -1135,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; |
@@ -1157,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 |
@@ -1205,11 +1225,13 @@ |
read_buf_ = new IOBuffer(io_buf_len_); |
net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
+ ReportCacheActionStart(); |
rvargas (doing something else)
2012/07/23 22:22:36
This is where we start getting confusing results.
tburkard
2012/07/24 01:03:12
That doesn't matter for the purpose of what I'm tr
rvargas (doing something else)
2012/07/24 03:10:38
I think it matters.
If we only care about a singl
tburkard
2012/07/24 22:23:26
Per discussion on the phone, we are in agreement o
|
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_, |
@@ -1254,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); |
} |
@@ -1270,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); |
@@ -1292,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); |
@@ -1326,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_); |
@@ -1336,6 +1368,7 @@ |
} |
int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
+ ReportCacheActionFinish(); |
if (net_log_.IsLoggingAllEvents()) { |
net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, |
result); |
@@ -1361,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_) |
@@ -2110,4 +2149,14 @@ |
DoLoop(result); |
} |
+void HttpCache::Transaction::ReportCacheActionStart() { |
+ if (delegate_) |
+ delegate_->OnCacheActionStart(); |
+} |
+ |
+void HttpCache::Transaction::ReportCacheActionFinish() { |
+ if (delegate_) |
+ delegate_->OnCacheActionFinish(); |
+} |
+ |
} // namespace net |