summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 17:26:13 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 17:26:13 +0000
commitd60c79650e1be14bb75b25362b2eadd0c76b48ba (patch)
tree13c7de9cd16935bd495a963ae04df2778d12fa04
parentc0918c5df71848044da5e6268270fe2d640ab0bc (diff)
downloadchromium_src-d60c79650e1be14bb75b25362b2eadd0c76b48ba.zip
chromium_src-d60c79650e1be14bb75b25362b2eadd0c76b48ba.tar.gz
chromium_src-d60c79650e1be14bb75b25362b2eadd0c76b48ba.tar.bz2
First pass at adding http/backend cache events to the NetLog.
Adds sources and events for ActiveCacheEntry and EntryImpl objects, as well as adding cache read/write events to HttpCacheTransactions. Most new read/write events are only logged when NetLog logging mode is set to log all events. Also, net-internals now merges begin and end events that have parameters, as long as only one of them has parameters. I think this increases readability, at the cost of making it a little more difficult to follow timings with just the "st" values. BUG=59382 TEST=none yet, other than updates to existing tests. Review URL: http://codereview.chromium.org/4067002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70618 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/net/connection_tester.cc1
-rw-r--r--chrome/browser/net/passive_log_collector.cc26
-rw-r--r--chrome/browser/net/passive_log_collector.h17
-rw-r--r--chrome/browser/resources/net_internals/logviewpainter.js75
-rw-r--r--chrome/browser/resources/net_internals/main.css4
-rw-r--r--chrome/browser/resources/net_internals/sourceentry.js3
-rw-r--r--chrome/service/net/service_url_request_context.cc1
-rw-r--r--chrome/test/plugin/plugin_test.cpp1
-rw-r--r--chrome_frame/metrics_service.cc1
-rw-r--r--chrome_frame/test/test_server_test.cc1
-rw-r--r--net/base/capturing_net_log.cc16
-rw-r--r--net/base/capturing_net_log.h7
-rw-r--r--net/base/net_log.cc14
-rw-r--r--net/base/net_log.h9
-rw-r--r--net/base/net_log_event_type_list.h73
-rw-r--r--net/base/net_log_source_type_list.h3
-rw-r--r--net/disk_cache/backend_impl.cc29
-rw-r--r--net/disk_cache/backend_impl.h14
-rw-r--r--net/disk_cache/backend_unittest.cc22
-rw-r--r--net/disk_cache/disk_cache.h4
-rw-r--r--net/disk_cache/disk_cache_perftest.cc4
-rw-r--r--net/disk_cache/disk_cache_test_base.cc6
-rw-r--r--net/disk_cache/disk_cache_test_util.cc2
-rw-r--r--net/disk_cache/entry_impl.cc165
-rw-r--r--net/disk_cache/entry_impl.h18
-rw-r--r--net/disk_cache/sparse_control.cc52
-rw-r--r--net/disk_cache/stress_cache.cc2
-rw-r--r--net/http/http_cache.cc22
-rw-r--r--net/http/http_cache.h11
-rw-r--r--net/http/http_cache_transaction.cc60
-rw-r--r--net/http/http_cache_transaction.h2
-rw-r--r--net/http/http_cache_unittest.cc72
-rw-r--r--net/http/http_network_session.h4
-rw-r--r--net/proxy/proxy_script_fetcher_impl_unittest.cc1
-rw-r--r--net/spdy/spdy_test_util.h1
-rw-r--r--net/tools/crash_cache/crash_cache.cc8
-rw-r--r--net/tools/dump_cache/upgrade.cc4
-rw-r--r--net/url_request/url_request_unittest.h1
-rw-r--r--net/url_request/view_cache_helper_unittest.cc2
-rw-r--r--webkit/appcache/appcache_disk_cache.cc2
40 files changed, 618 insertions, 142 deletions
diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc
index 18960eb..f23d619 100644
--- a/chrome/browser/net/connection_tester.cc
+++ b/chrome/browser/net/connection_tester.cc
@@ -71,6 +71,7 @@ class ExperimentURLRequestContext : public URLRequestContext {
dnsrr_resolver_, NULL /* dns_cert_checker */,
NULL /* ssl_host_info_factory */, proxy_service_,
ssl_config_service_, http_auth_handler_factory_, NULL, NULL),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
cookie_store_ = new net::CookieMonster(NULL, NULL);
diff --git a/chrome/browser/net/passive_log_collector.cc b/chrome/browser/net/passive_log_collector.cc
index 0d41479..21e2935 100644
--- a/chrome/browser/net/passive_log_collector.cc
+++ b/chrome/browser/net/passive_log_collector.cc
@@ -70,6 +70,7 @@ PassiveLogCollector::PassiveLogCollector()
trackers_[net::NetLog::SOURCE_HOST_RESOLVER_IMPL_REQUEST] =
&dns_request_tracker_;
trackers_[net::NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB] = &dns_job_tracker_;
+ trackers_[net::NetLog::SOURCE_DISK_CACHE_ENTRY] = &disk_cache_entry_tracker_;
// Make sure our mapping is up-to-date.
for (size_t i = 0; i < arraysize(trackers_); ++i)
DCHECK(trackers_[i]) << "Unhandled SourceType: " << i;
@@ -560,3 +561,28 @@ PassiveLogCollector::DNSJobTracker::DoAddEntry(const ChromeNetLog::Entry& entry,
return ACTION_NONE;
}
}
+
+//----------------------------------------------------------------------------
+// DiskCacheEntryTracker
+//----------------------------------------------------------------------------
+
+const size_t PassiveLogCollector::DiskCacheEntryTracker::kMaxNumSources = 100;
+const size_t PassiveLogCollector::DiskCacheEntryTracker::kMaxGraveyardSize = 25;
+
+PassiveLogCollector::DiskCacheEntryTracker::DiskCacheEntryTracker()
+ : SourceTracker(kMaxNumSources, kMaxGraveyardSize, NULL) {
+}
+
+PassiveLogCollector::SourceTracker::Action
+PassiveLogCollector::DiskCacheEntryTracker::DoAddEntry(
+ const ChromeNetLog::Entry& entry, SourceInfo* out_info) {
+ AddEntryToSourceInfo(entry, out_info);
+
+ // If the request has ended, move it to the graveyard.
+ if (entry.type == net::NetLog::TYPE_DISK_CACHE_ENTRY &&
+ entry.phase == net::NetLog::PHASE_END) {
+ return ACTION_MOVE_TO_GRAVEYARD;
+ }
+
+ return ACTION_NONE;
+}
diff --git a/chrome/browser/net/passive_log_collector.h b/chrome/browser/net/passive_log_collector.h
index 114e439..a415d59 100644
--- a/chrome/browser/net/passive_log_collector.h
+++ b/chrome/browser/net/passive_log_collector.h
@@ -304,6 +304,22 @@ class PassiveLogCollector : public ChromeNetLog::ThreadSafeObserver {
DISALLOW_COPY_AND_ASSIGN(DNSJobTracker);
};
+ // Tracks the log entries for the last seen SOURCE_DISK_CACHE_ENTRY.
+ class DiskCacheEntryTracker : public SourceTracker {
+ public:
+ static const size_t kMaxNumSources;
+ static const size_t kMaxGraveyardSize;
+
+ DiskCacheEntryTracker();
+
+ protected:
+ virtual Action DoAddEntry(const ChromeNetLog::Entry& entry,
+ SourceInfo* out_info);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DiskCacheEntryTracker);
+ };
+
PassiveLogCollector();
~PassiveLogCollector();
@@ -340,6 +356,7 @@ class PassiveLogCollector : public ChromeNetLog::ThreadSafeObserver {
SpdySessionTracker spdy_session_tracker_;
DNSRequestTracker dns_request_tracker_;
DNSJobTracker dns_job_tracker_;
+ DiskCacheEntryTracker disk_cache_entry_tracker_;
// This array maps each NetLog::SourceType to one of the tracker instances
// defined above. Use of this array avoid duplicating the list of trackers
diff --git a/chrome/browser/resources/net_internals/logviewpainter.js b/chrome/browser/resources/net_internals/logviewpainter.js
index 82686c6..28df383 100644
--- a/chrome/browser/resources/net_internals/logviewpainter.js
+++ b/chrome/browser/resources/net_internals/logviewpainter.js
@@ -49,10 +49,9 @@ function addSourceEntry_(node, sourceEntry) {
function canCollapseBeginWithEnd(beginEntry) {
return beginEntry &&
beginEntry.isBegin() &&
- !beginEntry.orig.params &&
beginEntry.end &&
beginEntry.end.index == beginEntry.index + 1 &&
- !beginEntry.end.orig.params &&
+ (!beginEntry.orig.params || !beginEntry.end.orig.params) &&
beginEntry.orig.wasPassivelyCaptured ==
beginEntry.end.orig.wasPassivelyCaptured;
}
@@ -70,43 +69,43 @@ PrintSourceEntriesAsText = function(sourceEntries, doSecurityStripping) {
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
- // Avoid printing the END for a BEGIN that was immediately before.
- if (entry.isEnd() && canCollapseBeginWithEnd(entry.begin))
- continue;
-
- tablePrinter.addRow();
-
- // Annotate this entry with "(P)" if it was passively captured.
- tablePrinter.addCell(entry.orig.wasPassivelyCaptured ? '(P) ' : '');
-
- tablePrinter.addCell('t=');
- var date = g_browser.convertTimeTicksToDate(entry.orig.time) ;
- var tCell = tablePrinter.addCell(date.getTime());
- tCell.alignRight = true;
- tablePrinter.addCell(' [st=');
- var stCell = tablePrinter.addCell(date.getTime() - startTime);
- stCell.alignRight = true;
- tablePrinter.addCell('] ');
-
- var indentationStr = makeRepeatedString(' ', entry.getDepth() * 3);
- var mainCell =
- tablePrinter.addCell(indentationStr + getTextForEvent(entry));
- tablePrinter.addCell(' ');
-
- // Get the elapsed time.
- if (entry.isBegin()) {
- tablePrinter.addCell('[dt=');
- var dt = '?';
- // Definite time.
- if (entry.end) {
- dt = entry.end.orig.time - entry.orig.time;
- }
- var dtCell = tablePrinter.addCell(dt);
- dtCell.alignRight = true;
+ // Avoid printing the END for a BEGIN that was immediately before, unless
+ // both have extra parameters.
+ if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) {
+ tablePrinter.addRow();
+
+ // Annotate this entry with "(P)" if it was passively captured.
+ tablePrinter.addCell(entry.orig.wasPassivelyCaptured ? '(P) ' : '');
+
+ tablePrinter.addCell('t=');
+ var date = g_browser.convertTimeTicksToDate(entry.orig.time) ;
+ var tCell = tablePrinter.addCell(date.getTime());
+ tCell.alignRight = true;
+ tablePrinter.addCell(' [st=');
+ var stCell = tablePrinter.addCell(date.getTime() - startTime);
+ stCell.alignRight = true;
+ tablePrinter.addCell('] ');
+
+ var indentationStr = makeRepeatedString(' ', entry.getDepth() * 3);
+ var mainCell =
+ tablePrinter.addCell(indentationStr + getTextForEvent(entry));
+ tablePrinter.addCell(' ');
+
+ // Get the elapsed time.
+ if (entry.isBegin()) {
+ tablePrinter.addCell('[dt=');
+ var dt = '?';
+ // Definite time.
+ if (entry.end) {
+ dt = entry.end.orig.time - entry.orig.time;
+ }
+ var dtCell = tablePrinter.addCell(dt);
+ dtCell.alignRight = true;
- tablePrinter.addCell(']');
- } else {
- mainCell.allowOverflow = true;
+ tablePrinter.addCell(']');
+ } else {
+ mainCell.allowOverflow = true;
+ }
}
// Output the extra parameters.
diff --git a/chrome/browser/resources/net_internals/main.css b/chrome/browser/resources/net_internals/main.css
index be3abee..8c6982c 100644
--- a/chrome/browser/resources/net_internals/main.css
+++ b/chrome/browser/resources/net_internals/main.css
@@ -92,6 +92,10 @@ body {
color: #308080;
}
+#eventsListTableBody .source_DISK_CACHE_ENTRY {
+ color: gray;
+}
+
#eventsListTableBody .source_SOCKET {
color: purple;
}
diff --git a/chrome/browser/resources/net_internals/sourceentry.js b/chrome/browser/resources/net_internals/sourceentry.js
index 4a4df6e..6c02c03 100644
--- a/chrome/browser/resources/net_internals/sourceentry.js
+++ b/chrome/browser/resources/net_internals/sourceentry.js
@@ -232,6 +232,9 @@ SourceEntry.prototype.getDescription = function() {
case LogSourceType.HOST_RESOLVER_IMPL_JOB:
description = e.params.host;
break;
+ case LogSourceType.DISK_CACHE_ENTRY:
+ description = e.params.key;
+ break;
case LogSourceType.SPDY_SESSION:
if (e.params.host)
description = e.params.host + ' (' + e.params.proxy + ')';
diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc
index 7f589e0..46d3b7c 100644
--- a/chrome/service/net/service_url_request_context.cc
+++ b/chrome/service/net/service_url_request_context.cc
@@ -135,6 +135,7 @@ ServiceURLRequestContext::ServiceURLRequestContext(
http_auth_handler_factory_,
NULL /* network_delegate */,
NULL /* net_log */),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
cookie_store_ = new net::CookieMonster(NULL, NULL);
diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp
index 9aa885f..177ad5f 100644
--- a/chrome/test/plugin/plugin_test.cpp
+++ b/chrome/test/plugin/plugin_test.cpp
@@ -303,6 +303,7 @@ class PluginInstallerDownloadTest
http_auth_handler_factory_,
network_delegate_,
NULL),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
}
diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc
index 3311853..e94b069 100644
--- a/chrome_frame/metrics_service.cc
+++ b/chrome_frame/metrics_service.cc
@@ -190,6 +190,7 @@ class ChromeFrameUploadRequestContext : public URLRequestContext {
http_auth_handler_factory_,
network_delegate_,
NULL),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
}
diff --git a/chrome_frame/test/test_server_test.cc b/chrome_frame/test/test_server_test.cc
index 0bb9ba2..9040e22 100644
--- a/chrome_frame/test/test_server_test.cc
+++ b/chrome_frame/test/test_server_test.cc
@@ -81,6 +81,7 @@ class URLRequestTestContext : public URLRequestContext {
http_auth_handler_factory_,
NULL /* network_delegate */,
NULL /* net_log */),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
cookie_store_ = new net::CookieMonster(NULL, NULL);
diff --git a/net/base/capturing_net_log.cc b/net/base/capturing_net_log.cc
index fccd5ae..c6d34240 100644
--- a/net/base/capturing_net_log.cc
+++ b/net/base/capturing_net_log.cc
@@ -18,7 +18,9 @@ CapturingNetLog::Entry::Entry(EventType type,
CapturingNetLog::Entry::~Entry() {}
CapturingNetLog::CapturingNetLog(size_t max_num_entries)
- : last_id_(-1), max_num_entries_(max_num_entries) {
+ : last_id_(-1),
+ max_num_entries_(max_num_entries),
+ log_level_(LOG_ALL_BUT_BYTES) {
}
CapturingNetLog::~CapturingNetLog() {}
@@ -39,7 +41,8 @@ uint32 CapturingNetLog::NextID() {
}
NetLog::LogLevel CapturingNetLog::GetLogLevel() const {
- return LOG_ALL_BUT_BYTES;
+ AutoLock lock(lock_);
+ return log_level_;
}
void CapturingNetLog::GetEntries(EntryList* entry_list) const {
@@ -52,6 +55,11 @@ void CapturingNetLog::Clear() {
entries_.clear();
}
+void CapturingNetLog::SetLogLevel(NetLog::LogLevel log_level) {
+ AutoLock lock(lock_);
+ log_level_ = log_level;
+}
+
CapturingBoundNetLog::CapturingBoundNetLog(const NetLog::Source& source,
CapturingNetLog* net_log)
: source_(source), capturing_net_log_(net_log) {
@@ -71,4 +79,8 @@ void CapturingBoundNetLog::Clear() {
capturing_net_log_->Clear();
}
+void CapturingBoundNetLog::SetLogLevel(NetLog::LogLevel log_level) {
+ capturing_net_log_->SetLogLevel(log_level);
+}
+
} // namespace net
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
index 9254725..193d641 100644
--- a/net/base/capturing_net_log.h
+++ b/net/base/capturing_net_log.h
@@ -61,6 +61,8 @@ class CapturingNetLog : public NetLog {
void Clear();
+ void SetLogLevel(NetLog::LogLevel log_level);
+
private:
// Needs to be "mutable" so can use it in GetEntries().
mutable Lock lock_;
@@ -71,6 +73,8 @@ class CapturingNetLog : public NetLog {
size_t max_num_entries_;
EntryList entries_;
+ NetLog::LogLevel log_level_;
+
DISALLOW_COPY_AND_ASSIGN(CapturingNetLog);
};
@@ -97,6 +101,9 @@ class CapturingBoundNetLog {
void Clear();
+ // Sets the log level of the underlying CapturingNetLog.
+ void SetLogLevel(NetLog::LogLevel log_level);
+
private:
NetLog::Source source_;
scoped_ptr<CapturingNetLog> capturing_net_log_;
diff --git a/net/base/net_log.cc b/net/base/net_log.cc
index c9e7319..0f1bac4 100644
--- a/net/base/net_log.cc
+++ b/net/base/net_log.cc
@@ -3,11 +3,13 @@
// found in the LICENSE file.
#include "net/base/net_log.h"
+
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "net/base/net_errors.h"
namespace net {
@@ -157,6 +159,18 @@ void BoundNetLog::EndEvent(
AddEntry(event_type, NetLog::PHASE_END, params);
}
+void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type,
+ int net_error) const {
+ DCHECK_NE(net_error, net::ERR_IO_PENDING);
+ if (net_error >= 0) {
+ EndEvent(event_type, NULL);
+ } else {
+ EndEvent(
+ event_type,
+ make_scoped_refptr(new NetLogIntegerParameter("net_error", net_error)));
+ }
+}
+
// static
BoundNetLog BoundNetLog::Make(NetLog* net_log,
NetLog::SourceType source_type) {
diff --git a/net/base/net_log.h b/net/base/net_log.h
index b8f903d..1d37129 100644
--- a/net/base/net_log.h
+++ b/net/base/net_log.h
@@ -34,6 +34,8 @@ namespace net {
// TODO(eroman): Remove the 'const' qualitifer from the BoundNetLog methods.
// TODO(eroman): Start a new Source each time net::URLRequest redirects
// (simpler to reason about each as a separate entity).
+// TODO(mmenke): Replace EndEvent calls with EndEventWithNetErrorCode, where
+// appropriate.
class NetLog {
public:
@@ -193,6 +195,13 @@ class BoundNetLog {
void EndEvent(NetLog::EventType event_type,
const scoped_refptr<NetLog::EventParameters>& params) const;
+ // Just like EndEvent, except |net_error| is a net error code. If it's
+ // negative, a parameter called "net_error" with a value of |net_error| is
+ // associated with the event. Otherwise, the end event has no parameters.
+ // |net_error| must not be ERR_IO_PENDING, as it's not a true error.
+ void EndEventWithNetErrorCode(NetLog::EventType event_type,
+ int net_error) const;
+
NetLog::LogLevel GetLogLevel() const;
// Returns true if the log level is LOG_ALL.
diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h
index f1bc4f8..0f1eecf 100644
--- a/net/base/net_log_event_type_list.h
+++ b/net/base/net_log_event_type_list.h
@@ -501,22 +501,85 @@ EVENT_TYPE(URL_REQUEST_REDIRECTED)
// HttpCache
// ------------------------------------------------------------------------
+// Measures the time while getting a reference to the back end.
+EVENT_TYPE(HTTP_CACHE_GET_BACKEND)
+
// Measures the time while opening a disk cache entry.
EVENT_TYPE(HTTP_CACHE_OPEN_ENTRY)
// Measures the time while creating a disk cache entry.
EVENT_TYPE(HTTP_CACHE_CREATE_ENTRY)
+// Measures the time it takes to add a HttpCache::Transaction to an http cache
+// entry's list of active Transactions.
+EVENT_TYPE(HTTP_CACHE_ADD_TO_ENTRY)
+
// Measures the time while deleting a disk cache entry.
EVENT_TYPE(HTTP_CACHE_DOOM_ENTRY)
-// Measures the time while reading the response info from a disk cache entry.
+// Measures the time while reading/writing a disk cache entry's response headers
+// or metadata.
EVENT_TYPE(HTTP_CACHE_READ_INFO)
+EVENT_TYPE(HTTP_CACHE_WRITE_INFO)
+
+// Measures the time while reading/writing a disk cache entry's body.
+EVENT_TYPE(HTTP_CACHE_READ_DATA)
+EVENT_TYPE(HTTP_CACHE_WRITE_DATA)
+
+// ------------------------------------------------------------------------
+// Disk Cache
+// ------------------------------------------------------------------------
+
+// The creation/destruction of a disk_cache::EntryImpl object. The "creation"
+// is considered to be the point at which an Entry is first considered to be
+// good and associated with a key.
+//
+// For the BEGIN phase, the following parameters are attached:
+// {
+// "created": <true if the Entry was created, rather than being opened>;
+// "key": <The Entry's key>;
+// }
+EVENT_TYPE(DISK_CACHE_ENTRY)
+
+// Logs the time required to read/write data from/to a cache entry.
+//
+// For the BEGIN phase, the following parameters are attached:
+// {
+// "index": <Index being read/written>;
+// "offset": <Offset being read/written>;
+// "buf_len": <Length of buffer being read to/written from>;
+// "truncate": <If present for a write, the truncate flag is set to true.
+// Not present in reads or writes where it is false>
+// }
+//
+// For the END phase, the following parameters are attached:
+// {
+// "bytes_copied": <Number of bytes copied. Not present on error>;
+// "net_error": <Network error code. Only present on error>;
+// }
+EVENT_TYPE(DISK_CACHE_READ_DATA)
+EVENT_TYPE(DISK_CACHE_WRITE_DATA)
+
+// Logged when SparseControl starts/stops handling IO for an Entry.
+EVENT_TYPE(SPARSE_CONTROL)
+
+// Logged when SparseControl starts/stops reading/writing a child Entry's data
+//
+// For the BEGIN phase, the following parameters are attached:
+// {
+// "source_dependency": <Source id of the child entry>
+// }
+EVENT_TYPE(SPARSE_CONTROL_READ)
+EVENT_TYPE(SPARSE_CONTROL_WRITE)
+
+// Indicates the time taken by a sparse control to get a range.
+EVENT_TYPE(SPARSE_CONTROL_GET_RANGE)
+
+// Logged when an entry is closed.
+EVENT_TYPE(DISK_CACHE_CLOSE)
-// Measures the time that an HttpCache::Transaction is stalled waiting for
-// the cache entry to become available (for example if we are waiting for
-// exclusive access to an existing entry).
-EVENT_TYPE(HTTP_CACHE_WAITING)
+// Logged when an entry is doomed.
+EVENT_TYPE(DISK_CACHE_DOOM)
// ------------------------------------------------------------------------
// HttpNetworkTransaction
diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h
index 231ecd2..ba34955 100644
--- a/net/base/net_log_source_type_list.h
+++ b/net/base/net_log_source_type_list.h
@@ -15,5 +15,6 @@ SOURCE_TYPE(SOCKET, 5)
SOURCE_TYPE(SPDY_SESSION, 6)
SOURCE_TYPE(HOST_RESOLVER_IMPL_REQUEST, 7)
SOURCE_TYPE(HOST_RESOLVER_IMPL_JOB, 8)
+SOURCE_TYPE(DISK_CACHE_ENTRY, 9)
-SOURCE_TYPE(COUNT, 9) // Always keep this as the last entry.
+SOURCE_TYPE(COUNT, 10) // Always keep this as the last entry.
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 58a6e9e..223c970 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -194,11 +194,12 @@ class CacheCreator {
public:
CacheCreator(const FilePath& path, bool force, int max_bytes,
net::CacheType type, uint32 flags,
- base::MessageLoopProxy* thread, disk_cache::Backend** backend,
+ base::MessageLoopProxy* thread, net::NetLog* net_log,
+ disk_cache::Backend** backend,
net::CompletionCallback* callback)
: path_(path), force_(force), retry_(false), max_bytes_(max_bytes),
type_(type), flags_(flags), thread_(thread), backend_(backend),
- callback_(callback), cache_(NULL),
+ callback_(callback), cache_(NULL), net_log_(net_log),
ALLOW_THIS_IN_INITIALIZER_LIST(
my_callback_(this, &CacheCreator::OnIOComplete)) {
}
@@ -223,13 +224,14 @@ class CacheCreator {
disk_cache::Backend** backend_;
net::CompletionCallback* callback_;
disk_cache::BackendImpl* cache_;
+ net::NetLog* net_log_;
net::CompletionCallbackImpl<CacheCreator> my_callback_;
DISALLOW_COPY_AND_ASSIGN(CacheCreator);
};
int CacheCreator::Run() {
- cache_ = new disk_cache::BackendImpl(path_, thread_);
+ cache_ = new disk_cache::BackendImpl(path_, thread_, net_log_);
cache_->SetMaxSize(max_bytes_);
cache_->SetType(type_);
cache_->SetFlags(flags_);
@@ -295,7 +297,8 @@ namespace disk_cache {
int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
bool force, base::MessageLoopProxy* thread,
- Backend** backend, CompletionCallback* callback) {
+ net::NetLog* net_log, Backend** backend,
+ CompletionCallback* callback) {
DCHECK(callback);
if (type == net::MEMORY_CACHE) {
*backend = MemBackendImpl::CreateBackend(max_bytes);
@@ -304,7 +307,7 @@ int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
DCHECK(thread);
return BackendImpl::CreateBackend(path, force, max_bytes, type, kNone, thread,
- backend, callback);
+ net_log, backend, callback);
}
// Returns the preferred maximum number of bytes for the cache given the
@@ -351,11 +354,12 @@ int PreferedCacheSize(int64 available) {
int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
int max_bytes, net::CacheType type,
uint32 flags, base::MessageLoopProxy* thread,
- Backend** backend,
+ net::NetLog* net_log, Backend** backend,
CompletionCallback* callback) {
DCHECK(callback);
CacheCreator* creator = new CacheCreator(full_path, force, max_bytes, type,
- flags, thread, backend, callback);
+ flags, thread, net_log, backend,
+ callback);
// This object will self-destroy when finished.
return creator->Run();
}
@@ -366,7 +370,8 @@ int BackendImpl::Init(CompletionCallback* callback) {
}
BackendImpl::BackendImpl(const FilePath& path,
- base::MessageLoopProxy* cache_thread)
+ base::MessageLoopProxy* cache_thread,
+ net::NetLog* net_log)
: ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)),
path_(path),
block_files_(path),
@@ -383,6 +388,7 @@ BackendImpl::BackendImpl(const FilePath& path,
new_eviction_(false),
first_timer_(true),
throttle_requests_(false),
+ net_log_(net_log),
done_(true, false),
ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
@@ -390,7 +396,8 @@ BackendImpl::BackendImpl(const FilePath& path,
BackendImpl::BackendImpl(const FilePath& path,
uint32 mask,
- base::MessageLoopProxy* cache_thread)
+ base::MessageLoopProxy* cache_thread,
+ net::NetLog* net_log)
: ALLOW_THIS_IN_INITIALIZER_LIST(background_queue_(this, cache_thread)),
path_(path),
block_files_(path),
@@ -407,6 +414,7 @@ BackendImpl::BackendImpl(const FilePath& path,
new_eviction_(false),
first_timer_(true),
throttle_requests_(false),
+ net_log_(net_log),
done_(true, false),
ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
@@ -848,6 +856,8 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) {
return NULL;
}
+ cache_entry->BeginLogging(net_log_, true);
+
// We are not failing the operation; let's add this to the map.
open_entries_[entry_address.value()] = cache_entry;
@@ -1537,6 +1547,7 @@ int BackendImpl::NewEntry(Addr address, EntryImpl** entry, bool* dirty) {
open_entries_[address.value()] = cache_entry;
}
+ cache_entry->BeginLogging(net_log_, false);
cache_entry.swap(entry);
return 0;
}
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 5637fbd..b481525 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -19,6 +19,10 @@
#include "net/disk_cache/stats.h"
#include "net/disk_cache/trace.h"
+namespace net {
+class NetLog;
+} // namespace net
+
namespace disk_cache {
enum BackendFlags {
@@ -38,10 +42,11 @@ enum BackendFlags {
class BackendImpl : public Backend {
friend class Eviction;
public:
- BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread);
+ BackendImpl(const FilePath& path, base::MessageLoopProxy* cache_thread,
+ net::NetLog* net_log);
// mask can be used to limit the usable size of the hash table, for testing.
BackendImpl(const FilePath& path, uint32 mask,
- base::MessageLoopProxy* cache_thread);
+ base::MessageLoopProxy* cache_thread, net::NetLog* net_log);
~BackendImpl();
// Returns a new backend with the desired flags. See the declaration of
@@ -49,7 +54,8 @@ class BackendImpl : public Backend {
static int CreateBackend(const FilePath& full_path, bool force,
int max_bytes, net::CacheType type,
uint32 flags, base::MessageLoopProxy* thread,
- Backend** backend, CompletionCallback* callback);
+ net::NetLog* net_log, Backend** backend,
+ CompletionCallback* callback);
// Performs general initialization for this current instance of the cache.
int Init(CompletionCallback* callback);
@@ -357,6 +363,8 @@ class BackendImpl : public Backend {
bool first_timer_; // True if the timer has not been called.
bool throttle_requests_;
+ net::NetLog* net_log_;
+
Stats stats_; // Usage statistcs.
base::RepeatingTimer<BackendImpl> timer_; // Usage timer.
base::WaitableEvent done_; // Signals the end of background work.
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 9077996..eaa00eb 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -195,7 +195,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
disk_cache::Backend* cache = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -208,14 +208,14 @@ TEST_F(DiskCacheTest, CreateBackend) {
// Now test the public API.
rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
cache_thread.message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
cache = NULL;
rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false,
- NULL, &cache, &cb);
+ NULL, NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -260,7 +260,8 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
+ base::MessageLoopProxy::CreateForCurrentThread(), NULL,
+ &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::EntryImpl* entry;
@@ -311,7 +312,7 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
disk_cache::Entry* entry;
@@ -348,7 +349,7 @@ TEST_F(DiskCacheTest, TruncatedIndex) {
disk_cache::Backend* backend = NULL;
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, 0, net::DISK_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), &backend, &cb);
+ cache_thread.message_loop_proxy(), NULL, &backend, &cb);
ASSERT_NE(net::OK, cb.GetResult(rv));
ASSERT_TRUE(backend == NULL);
@@ -1278,7 +1279,7 @@ TEST_F(DiskCacheTest, DeleteOld) {
disk_cache::Backend* cache;
int rv = disk_cache::BackendImpl::CreateBackend(
path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
MessageLoopHelper helper;
@@ -1651,7 +1652,8 @@ TEST_F(DiskCacheTest, Backend_UsageStats) {
ASSERT_TRUE(DeleteCache(path));
scoped_ptr<disk_cache::BackendImpl> cache;
cache.reset(new disk_cache::BackendImpl(
- path, base::MessageLoopProxy::CreateForCurrentThread()));
+ path, base::MessageLoopProxy::CreateForCurrentThread(),
+ NULL));
ASSERT_TRUE(NULL != cache.get());
cache->SetUnitTestMode();
ASSERT_EQ(net::OK, cache->SyncInit());
@@ -1769,11 +1771,11 @@ TEST_F(DiskCacheTest, MultipleInstances) {
int rv = disk_cache::BackendImpl::CreateBackend(
store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), &cache[0], &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache[0], &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
rv = disk_cache::BackendImpl::CreateBackend(
store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
- cache_thread.message_loop_proxy(), &cache[1], &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache[1], &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 59efe06..18dd447 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -25,6 +25,7 @@ class MessageLoopProxy;
namespace net {
class IOBuffer;
+class NetLog;
}
namespace disk_cache {
@@ -50,7 +51,8 @@ typedef net::CompletionCallback CompletionCallback;
// completes (the callback is notified).
int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
bool force, base::MessageLoopProxy* thread,
- Backend** backend, CompletionCallback* callback);
+ net::NetLog* net_log, Backend** backend,
+ CompletionCallback* callback);
// The root interface for a disk cache instance.
class Backend {
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 241fc04..14f15c6 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -169,7 +169,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
disk_cache::Backend* cache;
int rv = disk_cache::CreateCacheBackend(
net::DISK_CACHE, test_cache.path(), 0, false,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -198,7 +198,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 0,
false, cache_thread.message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
ret = TimeRead(num_entries, cache, entries, true);
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index cffe3fa..6c9b91c 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -75,7 +75,7 @@ void DiskCacheTestWithCache::InitDiskCache() {
TestCompletionCallback cb;
int rv = disk_cache::BackendImpl::CreateBackend(
path, force_creation_, size_, type_,
- disk_cache::kNoRandom, thread, &cache_, &cb);
+ disk_cache::kNoRandom, thread, NULL, &cache_, &cb);
ASSERT_EQ(net::OK, cb.GetResult(rv));
}
@@ -84,9 +84,9 @@ void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) {
use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() :
cache_thread_.message_loop_proxy();
if (mask_)
- cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread);
+ cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread, NULL);
else
- cache_impl_ = new disk_cache::BackendImpl(path, thread);
+ cache_impl_ = new disk_cache::BackendImpl(path, thread, NULL);
cache_ = cache_impl_;
ASSERT_TRUE(NULL != cache_);
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc
index 76690e6..ed16db0 100644
--- a/net/disk_cache/disk_cache_test_util.cc
+++ b/net/disk_cache/disk_cache_test_util.cc
@@ -94,7 +94,7 @@ bool CopyTestCache(const std::string& name) {
bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) {
scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(
- path, base::MessageLoopProxy::CreateForCurrentThread()));
+ path, base::MessageLoopProxy::CreateForCurrentThread(), NULL));
if (!cache.get())
return false;
if (new_eviction)
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index e5e6482..3cb895f 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -7,6 +7,7 @@
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
+#include "base/values.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/backend_impl.h"
@@ -24,14 +25,93 @@ namespace {
// Index for the file used to store the key, if any (files_[kKeyFileIndex]).
const int kKeyFileIndex = 3;
+// NetLog parameters for the creation of an EntryImpl. Contains an entry's name
+// and whether it was created or opened.
+class EntryCreationParameters : public net::NetLog::EventParameters {
+ public:
+ EntryCreationParameters(const std::string& key, bool created)
+ : key_(key), created_(created) {
+ }
+
+ Value* ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("key", key_);
+ dict->SetBoolean("created", created_);
+ return dict;
+ }
+
+ private:
+ const std::string key_;
+ const bool created_;
+
+ DISALLOW_COPY_AND_ASSIGN(EntryCreationParameters);
+};
+
+// NetLog parameters for non-sparse reading and writing to an EntryImpl.
+class ReadWriteDataParams : public net::NetLog::EventParameters {
+ public:
+ // For reads, |truncate| must be false.
+ ReadWriteDataParams(int index, int offset, int buf_len, bool truncate)
+ : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) {
+ }
+
+ Value* ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("index", index_);
+ dict->SetInteger("offset", offset_);
+ dict->SetInteger("buf_len", buf_len_);
+ if (truncate_)
+ dict->SetBoolean("truncate", truncate_);
+ return dict;
+ }
+
+ private:
+ const int index_;
+ const int offset_;
+ const int buf_len_;
+ const bool truncate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadWriteDataParams);
+};
+
+// NetLog parameters logged when non-sparse reads and writes complete.
+class FileIOCompleteParameters : public net::NetLog::EventParameters {
+ public:
+ // |bytes_copied| is either the number of bytes copied or a network error
+ // code. |bytes_copied| must not be ERR_IO_PENDING, as it's not a valid
+ // result for an operation.
+ explicit FileIOCompleteParameters(int bytes_copied)
+ : bytes_copied_(bytes_copied) {
+ }
+
+ Value* ToValue() const {
+ DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING);
+ DictionaryValue* dict = new DictionaryValue();
+ if (bytes_copied_ < 0) {
+ dict->SetInteger("net_error", bytes_copied_);
+ } else {
+ dict->SetInteger("bytes_copied", bytes_copied_);
+ }
+ return dict;
+ }
+
+ private:
+ const int bytes_copied_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileIOCompleteParameters);
+};
+
// This class implements FileIOCallback to buffer the callback from a file IO
// operation from the actual net class.
class SyncCallback: public disk_cache::FileIOCallback {
public:
+ // |end_event_type| is the event type to log on completion. Logs nothing on
+ // discard, or when the NetLog is not set to log all events.
SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer,
- net::CompletionCallback* callback )
+ net::CompletionCallback* callback,
+ net::NetLog::EventType end_event_type)
: entry_(entry), callback_(callback), buf_(buffer),
- start_(TimeTicks::Now()) {
+ start_(TimeTicks::Now()), end_event_type_(end_event_type) {
entry->AddRef();
entry->IncrementIoCount();
}
@@ -39,11 +119,13 @@ class SyncCallback: public disk_cache::FileIOCallback {
virtual void OnFileIOComplete(int bytes_copied);
void Discard();
+
private:
disk_cache::EntryImpl* entry_;
net::CompletionCallback* callback_;
scoped_refptr<net::IOBuffer> buf_;
TimeTicks start_;
+ net::NetLog::EventType end_event_type_;
DISALLOW_COPY_AND_ASSIGN(SyncCallback);
};
@@ -51,6 +133,11 @@ class SyncCallback: public disk_cache::FileIOCallback {
void SyncCallback::OnFileIOComplete(int bytes_copied) {
entry_->DecrementIoCount();
if (callback_) {
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().EndEvent(
+ end_event_type_,
+ make_scoped_refptr(new FileIOCompleteParameters(bytes_copied)));
+ }
entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
callback_->Run(bytes_copied);
}
@@ -308,6 +395,7 @@ EntryImpl::~EntryImpl() {
if (doomed_) {
DeleteEntryData(true);
} else {
+ net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL);
bool ret = true;
for (int index = 0; index < kNumStreams; index++) {
if (user_buffers_[index].get()) {
@@ -333,6 +421,7 @@ EntryImpl::~EntryImpl() {
}
Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
+ net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL);
backend_->OnEntryDestroyEnd();
}
@@ -487,6 +576,46 @@ void EntryImpl::DoomImpl() {
int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
int buf_len, CompletionCallback* callback) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_DISK_CACHE_READ_DATA,
+ make_scoped_refptr(
+ new ReadWriteDataParams(index, offset, buf_len, false)));
+ }
+
+ int result = InternalReadData(index, offset, buf, buf_len, callback);
+
+ if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEvent(
+ net::NetLog::TYPE_DISK_CACHE_READ_DATA,
+ make_scoped_refptr(new FileIOCompleteParameters(result)));
+ }
+ return result;
+}
+
+int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback,
+ bool truncate) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_DISK_CACHE_WRITE_DATA,
+ make_scoped_refptr(
+ new ReadWriteDataParams(index, offset, buf_len, truncate)));
+ }
+
+ int result = InternalWriteData(index, offset, buf, buf_len, callback,
+ truncate);
+
+ if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEvent(
+ net::NetLog::TYPE_DISK_CACHE_WRITE_DATA,
+ make_scoped_refptr(new FileIOCompleteParameters(result)));
+ }
+ return result;
+}
+
+int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback) {
DCHECK(node_.Data()->dirty || read_only_);
DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
if (index < 0 || index >= kNumStreams)
@@ -536,8 +665,10 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
}
SyncCallback* io_callback = NULL;
- if (callback)
- io_callback = new SyncCallback(this, buf, callback);
+ if (callback) {
+ io_callback = new SyncCallback(this, buf, callback,
+ net::NetLog::TYPE_DISK_CACHE_READ_DATA);
+ }
bool completed;
if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) {
@@ -553,9 +684,9 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
}
-int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
- int buf_len, CompletionCallback* callback,
- bool truncate) {
+int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback,
+ bool truncate) {
DCHECK(node_.Data()->dirty || read_only_);
DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
if (index < 0 || index >= kNumStreams)
@@ -628,8 +759,10 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
return 0;
SyncCallback* io_callback = NULL;
- if (callback)
- io_callback = new SyncCallback(this, buf, callback);
+ if (callback) {
+ io_callback = new SyncCallback(this, buf, callback,
+ net::NetLog::TYPE_DISK_CACHE_WRITE_DATA);
+ }
bool completed;
if (!file->Write(buf->data(), buf_len, file_offset, io_callback,
@@ -757,6 +890,7 @@ bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) {
}
void EntryImpl::InternalDoom() {
+ net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_DOOM, NULL);
DCHECK(node_.HasData());
if (!node_.Data()->dirty) {
node_.Data()->dirty = backend_->GetCurrentEntryId();
@@ -914,6 +1048,19 @@ void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) {
}
}
+void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) {
+ DCHECK(!net_log_.net_log());
+ net_log_ = net::BoundNetLog::Make(
+ net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY);
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_DISK_CACHE_ENTRY,
+ make_scoped_refptr(new EntryCreationParameters(GetKey(), created)));
+}
+
+const net::BoundNetLog& EntryImpl::net_log() const {
+ return net_log_;
+}
+
// ------------------------------------------------------------------------
bool EntryImpl::CreateDataBlock(int index, int size) {
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index e27f23a..d24e861 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/scoped_ptr.h"
+#include "net/base/net_log.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/storage_block.h"
#include "net/disk_cache/storage_block-inl.h"
@@ -129,6 +130,14 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
// Generates a histogram for the time spent working on this operation.
void ReportIOTime(Operation op, const base::TimeTicks& start);
+ // Logs a begin event and enables logging for the EntryImpl. Will also cause
+ // an end event to be logged on destruction. The EntryImpl must have its key
+ // initialized before this is called. |created| is true if the Entry was
+ // created rather than opened.
+ void BeginLogging(net::NetLog* net_log, bool created);
+
+ const net::BoundNetLog& net_log() const;
+
private:
enum {
kNumStreams = 3
@@ -137,6 +146,13 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
~EntryImpl();
+ // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as
+ // separate functions to make logging of results simpler.
+ int InternalReadData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback);
+ int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ CompletionCallback* callback, bool truncate);
+
// Initializes the storage for an internal or external data block.
bool CreateDataBlock(int index, int size);
@@ -220,6 +236,8 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
bool read_only_; // True if not yet writing.
scoped_ptr<SparseControl> sparse_; // Support for sparse entries.
+ net::BoundNetLog net_log_;
+
DISALLOW_COPY_AND_ASSIGN(EntryImpl);
};
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index 32f44ab..c200b82 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -138,6 +138,29 @@ void ChildrenDeleter::DeleteChildren() {
this, &ChildrenDeleter::DeleteChildren));
}
+// Logs the end event for |operation|, if all events are being logged.
+void LogOperationEnd(const net::BoundNetLog& net_log,
+ disk_cache::SparseControl::SparseOperation operation,
+ int result) {
+ if (net_log.IsLoggingAllEvents()) {
+ net::NetLog::EventType event_type;
+ switch (operation) {
+ case disk_cache::SparseControl::kReadOperation:
+ event_type = net::NetLog::TYPE_SPARSE_CONTROL_READ;
+ break;
+ case disk_cache::SparseControl::kWriteOperation:
+ event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE;
+ break;
+ case disk_cache::SparseControl::kGetRangeOperation:
+ event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE;
+ break;
+ default:
+ NOTREACHED();
+ }
+ net_log.EndEventWithNetErrorCode(event_type, result);
+ }
+}
+
} // namespace.
namespace disk_cache {
@@ -223,6 +246,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
finished_ = false;
abort_ = false;
+ entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
DoChildrenIO();
if (!pending_) {
@@ -610,8 +634,11 @@ void SparseControl::InitChildData() {
void SparseControl::DoChildrenIO() {
while (DoChildIO()) continue;
- if (pending_ && finished_)
- DoUserCallback();
+ if (finished_) {
+ entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
+ if (pending_)
+ DoUserCallback();
+ }
}
bool SparseControl::DoChildIO() {
@@ -632,14 +659,32 @@ bool SparseControl::DoChildIO() {
int rv = 0;
switch (operation_) {
case kReadOperation:
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().BeginEvent(
+ net::NetLog::TYPE_SPARSE_CONTROL_READ,
+ make_scoped_refptr(new net::NetLogSourceParameter(
+ "source_dependency",
+ child_->net_log().source())));
+ }
rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
child_len_, callback);
break;
case kWriteOperation:
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().BeginEvent(
+ net::NetLog::TYPE_SPARSE_CONTROL_WRITE,
+ make_scoped_refptr(new net::NetLogSourceParameter(
+ "source_dependency",
+ child_->net_log().source())));
+ }
rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_,
child_len_, callback, false);
break;
case kGetRangeOperation:
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE,
+ NULL);
+ }
rv = DoGetAvailableRange();
break;
default:
@@ -712,6 +757,7 @@ int SparseControl::DoGetAvailableRange() {
}
void SparseControl::DoChildIOCompleted(int result) {
+ LogOperationEnd(entry_->net_log(), operation_, result);
if (result < 0) {
// We fail the whole operation if we encounter an error.
result_ = result;
@@ -737,6 +783,8 @@ void SparseControl::OnChildIOCompleted(int result) {
// We'll return the current result of the operation, which may be less than
// the bytes to read or write, but the user cancelled the operation.
abort_ = false;
+ entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL);
+ entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
DoUserCallback();
return DoAbortCallbacks();
}
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index 41a98c9..ee2db24 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -104,7 +104,7 @@ void StressTheCache(int iteration) {
int rv = disk_cache::BackendImpl::CreateBackend(
path, false, cache_size, net::DISK_CACHE,
disk_cache::kNoLoadProtection | disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), &cache, &cb);
+ cache_thread.message_loop_proxy(), NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK) {
printf("Unable to initialize cache.\n");
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 51cc55f..5710491 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -55,17 +55,18 @@ HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) {
return new DefaultBackend(MEMORY_CACHE, FilePath(), max_bytes, NULL);
}
-int HttpCache::DefaultBackend::CreateBackend(disk_cache::Backend** backend,
+int HttpCache::DefaultBackend::CreateBackend(NetLog* net_log,
+ disk_cache::Backend** backend,
CompletionCallback* callback) {
DCHECK_GE(max_bytes_, 0);
return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true,
- thread_, backend, callback);
+ thread_, net_log, backend, callback);
}
//-----------------------------------------------------------------------------
-HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* e)
- : disk_entry(e),
+HttpCache::ActiveEntry::ActiveEntry(disk_cache::Entry* entry)
+ : disk_entry(entry),
writer(NULL),
will_process_pending_queue(false),
doomed(false) {
@@ -288,7 +289,8 @@ HttpCache::HttpCache(HostResolver* host_resolver,
HttpNetworkDelegate* network_delegate,
NetLog* net_log,
BackendFactory* backend_factory)
- : backend_factory_(backend_factory),
+ : net_log_(net_log),
+ backend_factory_(backend_factory),
building_backend_(false),
mode_(NORMAL),
ssl_host_info_factory_(new SSLHostInfoFactoryAdaptor(
@@ -303,7 +305,8 @@ HttpCache::HttpCache(HostResolver* host_resolver,
HttpCache::HttpCache(HttpNetworkSession* session,
BackendFactory* backend_factory)
- : backend_factory_(backend_factory),
+ : net_log_(session->net_log()),
+ backend_factory_(backend_factory),
building_backend_(false),
mode_(NORMAL),
network_layer_(HttpNetworkLayer::CreateFactory(session)),
@@ -311,8 +314,10 @@ HttpCache::HttpCache(HttpNetworkSession* session,
}
HttpCache::HttpCache(HttpTransactionFactory* network_layer,
+ NetLog* net_log,
BackendFactory* backend_factory)
- : backend_factory_(backend_factory),
+ : net_log_(net_log),
+ backend_factory_(backend_factory),
building_backend_(false),
mode_(NORMAL),
network_layer_(network_layer),
@@ -464,7 +469,8 @@ int HttpCache::CreateBackend(disk_cache::Backend** backend,
BackendCallback* my_callback = new BackendCallback(this, pending_op);
pending_op->callback = my_callback;
- int rv = backend_factory_->CreateBackend(&pending_op->backend, my_callback);
+ int rv = backend_factory_->CreateBackend(net_log_, &pending_op->backend,
+ my_callback);
if (rv != ERR_IO_PENDING) {
pending_op->writer->ClearCallback();
my_callback->Run(rv);
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index 8ff6442..0641ca4 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -87,7 +87,8 @@ class HttpCache : public HttpTransactionFactory,
// notification arrives.
// The implementation must not access the factory object after invoking the
// |callback| because the object can be deleted from within the callback.
- virtual int CreateBackend(disk_cache::Backend** backend,
+ virtual int CreateBackend(NetLog* net_log,
+ disk_cache::Backend** backend,
CompletionCallback* callback) = 0;
};
@@ -105,7 +106,8 @@ class HttpCache : public HttpTransactionFactory,
static BackendFactory* InMemory(int max_bytes);
// BackendFactory implementation.
- virtual int CreateBackend(disk_cache::Backend** backend,
+ virtual int CreateBackend(NetLog* net_log,
+ disk_cache::Backend** backend,
CompletionCallback* callback);
private:
@@ -140,6 +142,7 @@ class HttpCache : public HttpTransactionFactory,
// by the HttpCache and will be destroyed using |delete| when the HttpCache is
// destroyed.
HttpCache(HttpTransactionFactory* network_layer,
+ NetLog* net_log,
BackendFactory* backend_factory);
HttpTransactionFactory* network_layer() { return network_layer_.get(); }
@@ -215,7 +218,7 @@ class HttpCache : public HttpTransactionFactory,
bool will_process_pending_queue;
bool doomed;
- explicit ActiveEntry(disk_cache::Entry*);
+ explicit ActiveEntry(disk_cache::Entry* entry);
~ActiveEntry();
};
@@ -344,6 +347,8 @@ class HttpCache : public HttpTransactionFactory,
// Variables ----------------------------------------------------------------
+ NetLog* net_log_;
+
// Used when lazily constructing the disk_cache_.
scoped_ptr<BackendFactory> backend_factory_;
bool building_backend_;
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index d795c83..b506edc 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -398,6 +398,10 @@ LoadState HttpCache::Transaction::GetWriterLoadState() const {
return LOAD_STATE_WAITING_FOR_CACHE;
}
+const BoundNetLog& HttpCache::Transaction::net_log() const {
+ return net_log_;
+}
+
//-----------------------------------------------------------------------------
void HttpCache::Transaction::DoCallback(int rv) {
@@ -579,13 +583,14 @@ int HttpCache::Transaction::DoLoop(int result) {
int HttpCache::Transaction::DoGetBackend() {
cache_pending_ = true;
next_state_ = STATE_GET_BACKEND_COMPLETE;
- net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, NULL);
return cache_->GetBackendForTransaction(this);
}
int HttpCache::Transaction::DoGetBackendComplete(int result) {
DCHECK(result == OK || result == ERR_FAILED);
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND,
+ result);
cache_pending_ = false;
if (!ShouldPassThrough()) {
@@ -757,7 +762,7 @@ int HttpCache::Transaction::DoOpenEntryComplete(int result) {
// 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.
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result);
cache_pending_ = false;
if (result == OK) {
next_state_ = STATE_ADD_TO_ENTRY;
@@ -800,7 +805,8 @@ int HttpCache::Transaction::DoCreateEntryComplete(int result) {
// 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.
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY,
+ result);
cache_pending_ = false;
next_state_ = STATE_ADD_TO_ENTRY;
@@ -831,7 +837,7 @@ int HttpCache::Transaction::DoDoomEntry() {
}
int HttpCache::Transaction::DoDoomEntryComplete(int result) {
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result);
next_state_ = STATE_CREATE_ENTRY;
cache_pending_ = false;
if (result == ERR_CACHE_RACE)
@@ -844,14 +850,15 @@ int HttpCache::Transaction::DoAddToEntry() {
DCHECK(new_entry_);
cache_pending_ = true;
next_state_ = STATE_ADD_TO_ENTRY_COMPLETE;
- net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, NULL);
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) {
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY,
+ result);
const base::TimeDelta entry_lock_wait =
base::TimeTicks::Now() - entry_lock_waiting_since_;
@@ -1002,12 +1009,19 @@ int HttpCache::Transaction::DoTruncateCachedData() {
cache_callback_->AddRef(); // Balanced in DoTruncateCachedDataComplete.
if (!entry_)
return OK;
+ if (net_log_.IsLoggingAllEvents())
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL);
// Truncate the stream.
return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_);
}
int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) {
+ if (net_log_.IsLoggingAllEvents() && entry_) {
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA,
+ result);
+ }
+
// Balance the AddRef from DoTruncateCachedData.
cache_callback_->Release();
next_state_ = STATE_TRUNCATE_CACHED_METADATA;
@@ -1020,10 +1034,17 @@ int HttpCache::Transaction::DoTruncateCachedMetadata() {
if (!entry_)
return OK;
+ if (net_log_.IsLoggingAllEvents())
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_);
}
int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) {
+ if (net_log_.IsLoggingAllEvents() && entry_) {
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO,
+ result);
+ }
+
// Balance the AddRef from DoTruncateCachedMetadata.
cache_callback_->Release();
@@ -1073,7 +1094,7 @@ int HttpCache::Transaction::DoCacheReadResponse() {
int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse.
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
+ 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_)) {
@@ -1113,10 +1134,14 @@ int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
}
int HttpCache::Transaction::DoCacheWriteResponse() {
+ if (net_log_.IsLoggingAllEvents() && entry_)
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
return WriteResponseInfoToEntry(false);
}
int HttpCache::Transaction::DoCacheWriteTruncatedResponse() {
+ if (net_log_.IsLoggingAllEvents() && entry_)
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
return WriteResponseInfoToEntry(true);
}
@@ -1125,6 +1150,10 @@ int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) {
target_state_ = STATE_NONE;
if (!entry_)
return OK;
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO,
+ result);
+ }
// Balance the AddRef from WriteResponseInfoToEntry.
write_headers_callback_->Release();
@@ -1152,7 +1181,7 @@ int HttpCache::Transaction::DoCacheReadMetadata() {
int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
cache_callback_->Release(); // Balance the AddRef from DoCacheReadMetadata.
- net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
if (result != response_.metadata->size()) {
DLOG(ERROR) << "ReadData failed: " << result;
return ERR_CACHE_READ_FAILURE;
@@ -1183,6 +1212,9 @@ int HttpCache::Transaction::DoCacheReadData() {
DCHECK(entry_);
next_state_ = STATE_CACHE_READ_DATA_COMPLETE;
cache_callback_->AddRef(); // Balanced in DoCacheReadDataComplete.
+
+ if (net_log_.IsLoggingAllEvents())
+ net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA, NULL);
if (partial_.get()) {
return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_,
cache_callback_);
@@ -1194,6 +1226,10 @@ int HttpCache::Transaction::DoCacheReadData() {
int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
cache_callback_->Release(); // Balance the AddRef from DoCacheReadData.
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA,
+ result);
+ }
if (!cache_)
return ERR_UNEXPECTED;
@@ -1213,12 +1249,18 @@ int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
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, NULL);
cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete.
return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_);
}
int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
+ if (net_log_.IsLoggingAllEvents() && entry_) {
+ net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA,
+ result);
+ }
// Balance the AddRef from DoCacheWriteData.
cache_callback_->Release();
if (!cache_)
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index 6b46750..316c15b 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -110,6 +110,8 @@ class HttpCache::Transaction : public HttpTransaction {
CompletionCallback* io_callback() { return &io_callback_; }
+ const BoundNetLog& net_log() const;
+
private:
static const size_t kNumValidationHeaders = 2;
// Helper struct to pair a header name with its value, for
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index a40a5b8..bf8cb6b 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -536,7 +536,8 @@ class MockDiskCache : public disk_cache::Backend {
class MockBackendFactory : public net::HttpCache::BackendFactory {
public:
- virtual int CreateBackend(disk_cache::Backend** backend,
+ virtual int CreateBackend(net::NetLog* /* net_log */,
+ disk_cache::Backend** backend,
net::CompletionCallback* callback) {
*backend = new MockDiskCache();
return net::OK;
@@ -546,11 +547,11 @@ class MockBackendFactory : public net::HttpCache::BackendFactory {
class MockHttpCache {
public:
MockHttpCache()
- : http_cache_(new MockNetworkLayer(), new MockBackendFactory()) {
+ : http_cache_(new MockNetworkLayer(), NULL, new MockBackendFactory()) {
}
explicit MockHttpCache(net::HttpCache::BackendFactory* disk_cache_factory)
- : http_cache_(new MockNetworkLayer(), disk_cache_factory) {
+ : http_cache_(new MockNetworkLayer(), NULL, disk_cache_factory) {
}
net::HttpCache* http_cache() { return &http_cache_; }
@@ -610,7 +611,8 @@ class MockHttpCache {
}
// Helper function to synchronously create a backend entry.
- bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry) {
+ bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry,
+ net::NetLog* /* net_log */) {
TestCompletionCallback cb;
int rv = disk_cache()->CreateEntry(key, entry, &cb);
return (cb.GetResult(rv) == net::OK);
@@ -630,7 +632,8 @@ class MockDiskCacheNoCB : public MockDiskCache {
class MockBackendNoCbFactory : public net::HttpCache::BackendFactory {
public:
- virtual int CreateBackend(disk_cache::Backend** backend,
+ virtual int CreateBackend(net::NetLog* /* net_log */,
+ disk_cache::Backend** backend,
net::CompletionCallback* callback) {
*backend = new MockDiskCacheNoCB();
return net::OK;
@@ -643,7 +646,8 @@ class MockBlockingBackendFactory : public net::HttpCache::BackendFactory {
MockBlockingBackendFactory()
: backend_(NULL), callback_(NULL), block_(true), fail_(false) {}
- virtual int CreateBackend(disk_cache::Backend** backend,
+ virtual int CreateBackend(net::NetLog* /* net_log */,
+ disk_cache::Backend** backend,
net::CompletionCallback* callback) {
if (!block_) {
if (!fail_)
@@ -1037,6 +1041,7 @@ TEST(HttpCache, SimpleGETNoDiskCache) {
cache.disk_cache()->set_fail_requests();
net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
+ log.SetLogLevel(net::NetLog::LOG_BASIC);
// Read from the network, and don't use the cache.
RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction,
@@ -1049,9 +1054,9 @@ TEST(HttpCache, SimpleGETNoDiskCache) {
EXPECT_EQ(6u, entries.size());
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsBeginEvent(
entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
@@ -1143,6 +1148,9 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
+ // This prevents a number of write events from being logged.
+ log.SetLogLevel(net::NetLog::LOG_BASIC);
+
// write to the cache
RunTransactionTestWithLog(cache.http_cache(), kSimpleGET_Transaction,
log.bound());
@@ -1153,9 +1161,9 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
EXPECT_EQ(8u, entries.size());
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsBeginEvent(
entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
@@ -1165,9 +1173,9 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
EXPECT_TRUE(net::LogContainsEndEvent(
entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 6, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 7, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
// force this transaction to read from the cache
MockTransaction transaction(kSimpleGET_Transaction);
@@ -1182,17 +1190,17 @@ TEST(HttpCache, SimpleGET_LoadOnlyFromCache_Hit) {
EXPECT_EQ(8u, entries.size());
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsBeginEvent(
entries, 2, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
entries, 3, net::NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY));
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 4, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 4, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 5, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 5, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
EXPECT_TRUE(net::LogContainsBeginEvent(
entries, 6, net::NetLog::TYPE_HTTP_CACHE_READ_INFO));
EXPECT_TRUE(net::LogContainsEndEvent(
@@ -1273,6 +1281,9 @@ TEST(HttpCache, SimpleGET_LoadBypassCache) {
net::CapturingBoundNetLog log(net::CapturingNetLog::kUnbounded);
+ // This prevents a number of write events from being logged.
+ log.SetLogLevel(net::NetLog::LOG_BASIC);
+
RunTransactionTestWithLog(cache.http_cache(), transaction, log.bound());
// Check that the NetLog was filled as expected.
@@ -1281,9 +1292,9 @@ TEST(HttpCache, SimpleGET_LoadBypassCache) {
EXPECT_EQ(8u, entries.size());
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 0, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 0, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 1, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 1, net::NetLog::TYPE_HTTP_CACHE_GET_BACKEND));
EXPECT_TRUE(net::LogContainsBeginEvent(
entries, 2, net::NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
@@ -1293,9 +1304,9 @@ TEST(HttpCache, SimpleGET_LoadBypassCache) {
EXPECT_TRUE(net::LogContainsEndEvent(
entries, 5, net::NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY));
EXPECT_TRUE(net::LogContainsBeginEvent(
- entries, 6, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 6, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
EXPECT_TRUE(net::LogContainsEndEvent(
- entries, 7, net::NetLog::TYPE_HTTP_CACHE_WAITING));
+ entries, 7, net::NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY));
EXPECT_EQ(2, cache.network_layer()->transaction_count());
EXPECT_EQ(0, cache.disk_cache()->open_count());
@@ -3302,7 +3313,8 @@ TEST(HttpCache, GET_Previous206_NotSparse) {
// Create a disk cache entry that stores 206 headers while not being sparse.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kSimpleGET_Transaction.url, &entry,
+ NULL));
std::string raw_headers(kRangeGET_TransactionOK.status);
raw_headers.append("\n");
@@ -3345,7 +3357,8 @@ TEST(HttpCache, RangeGET_Previous206_NotSparse_2) {
// Create a disk cache entry that stores 206 headers while not being sparse.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry,
+ NULL));
std::string raw_headers(kRangeGET_TransactionOK.status);
raw_headers.append("\n");
@@ -3943,7 +3956,8 @@ TEST(HttpCache, RangeGET_OK_LoadOnlyFromCache) {
TEST(HttpCache, WriteResponseInfo_Truncated) {
MockHttpCache cache;
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry("http://www.google.com", &entry,
+ NULL));
std::string headers("HTTP/1.1 200 OK");
headers = net::HttpUtil::AssembleRawHeaders(headers.data(), headers.size());
@@ -4142,7 +4156,8 @@ TEST(HttpCache, GET_IncompleteResource) {
// Create a disk cache entry that stores an incomplete resource.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry,
+ NULL));
std::string raw_headers("HTTP/1.1 200 OK\n"
"Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n"
@@ -4202,7 +4217,8 @@ TEST(HttpCache, GET_IncompleteResource2) {
// Create a disk cache entry that stores an incomplete resource.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry,
+ NULL));
// Content-length will be intentionally bad.
@@ -4261,7 +4277,8 @@ TEST(HttpCache, GET_CancelIncompleteResource) {
// Create a disk cache entry that stores an incomplete resource.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry,
+ NULL));
std::string raw_headers("HTTP/1.1 200 OK\n"
"Last-Modified: Sat, 18 Apr 2009 01:10:43 GMT\n"
@@ -4326,7 +4343,8 @@ TEST(HttpCache, RangeGET_IncompleteResource) {
// Create a disk cache entry that stores an incomplete resource.
disk_cache::Entry* entry;
- ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry));
+ ASSERT_TRUE(cache.CreateBackendEntry(kRangeGET_TransactionOK.url, &entry,
+ NULL));
// Content-length will be intentionally bogus.
std::string raw_headers("HTTP/1.1 200 OK\n"
diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h
index 5a3b96c..b36d7f7 100644
--- a/net/http/http_network_session.h
+++ b/net/http/http_network_session.h
@@ -130,6 +130,10 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>,
return &http_stream_factory_;
}
+ NetLog* net_log() {
+ return net_log_;
+ }
+
// Creates a Value summary of the state of the socket pools. The caller is
// responsible for deleting the returned value.
Value* SocketPoolInfoToValue() const {
diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc
index ec0fb58..043f71e 100644
--- a/net/proxy/proxy_script_fetcher_impl_unittest.cc
+++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc
@@ -47,6 +47,7 @@ class RequestContext : public URLRequestContext {
net::HttpNetworkLayer::CreateFactory(host_resolver_, cert_verifier_,
NULL, NULL, NULL, proxy_service_, ssl_config_service_, NULL, NULL,
NULL),
+ NULL,
net::HttpCache::DefaultBackend::InMemory(0));
}
diff --git a/net/spdy/spdy_test_util.h b/net/spdy/spdy_test_util.h
index aeabe6a..1b052fa 100644
--- a/net/spdy/spdy_test_util.h
+++ b/net/spdy/spdy_test_util.h
@@ -419,6 +419,7 @@ class SpdyURLRequestContext : public URLRequestContext {
http_auth_handler_factory_,
network_delegate_,
NULL),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
}
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index 44672ed..40c6a41 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -135,7 +135,7 @@ int SimpleInsert(const FilePath& path, RankCrashes action,
disk_cache::Backend* cache;
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
cache_thread->message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
@@ -176,7 +176,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
// Use a simple LRU for eviction.
int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false,
cache_thread->message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
@@ -219,7 +219,7 @@ int HeadRemove(const FilePath& path, RankCrashes action,
// Use a simple LRU for eviction.
int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false,
cache_thread->message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
@@ -256,7 +256,7 @@ int LoadOperations(const FilePath& path, RankCrashes action,
// Work with a tiny index table (16 entries).
disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
- path, 0xf, cache_thread->message_loop_proxy());
+ path, 0xf, cache_thread->message_loop_proxy(), NULL);
if (!cache || !cache->SetMaxSize(0x100000))
return GENERIC;
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index 30fbc8c6..fae924c 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -326,7 +326,7 @@ bool MasterSM::DoInit() {
FilePath::FromWStringHack(path_), 0,
false,
cache_thread_.message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK) {
printf("Unable to initialize new files\n");
return false;
@@ -607,7 +607,7 @@ SlaveSM::SlaveSM(const std::wstring& path, HANDLE channel)
FilePath::FromWStringHack(path), 0,
false,
cache_thread_.message_loop_proxy(),
- &cache, &cb);
+ NULL, &cache, &cb);
if (cb.GetResult(rv) != net::OK) {
printf("Unable to open cache files\n");
return;
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index b13d268..c336b41 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -173,6 +173,7 @@ class TestURLRequestContext : public URLRequestContext {
http_auth_handler_factory_,
network_delegate_,
NULL),
+ NULL /* net_log */,
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
cookie_store_ = new net::CookieMonster(NULL, NULL);
diff --git a/net/url_request/view_cache_helper_unittest.cc b/net/url_request/view_cache_helper_unittest.cc
index 5338ee5..3903c2b 100644
--- a/net/url_request/view_cache_helper_unittest.cc
+++ b/net/url_request/view_cache_helper_unittest.cc
@@ -25,7 +25,7 @@ class TestURLRequestContext : public URLRequestContext {
};
TestURLRequestContext::TestURLRequestContext()
- : cache_(reinterpret_cast<net::HttpTransactionFactory*>(NULL),
+ : cache_(reinterpret_cast<net::HttpTransactionFactory*>(NULL), NULL,
net::HttpCache::DefaultBackend::InMemory(0)) {
http_transaction_factory_ = &cache_;
}
diff --git a/webkit/appcache/appcache_disk_cache.cc b/webkit/appcache/appcache_disk_cache.cc
index dbba211..9aa0280 100644
--- a/webkit/appcache/appcache_disk_cache.cc
+++ b/webkit/appcache/appcache_disk_cache.cc
@@ -108,7 +108,7 @@ int AppCacheDiskCache::Init(net::CacheType cache_type,
this, &AppCacheDiskCache::OnCreateBackendComplete);
int rv = disk_cache::CreateCacheBackend(
- cache_type, cache_directory, cache_size, force, cache_thread,
+ cache_type, cache_directory, cache_size, force, cache_thread, NULL,
&(create_backend_callback_->backend_ptr_), create_backend_callback_);
if (rv == net::ERR_IO_PENDING)
init_callback_ = callback;