summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 18:53:02 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 18:53:02 +0000
commit9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f (patch)
treea3024687f2041d1f464aeb073d289c1bb7daae74 /net/disk_cache
parentd767b2c624529faef3bf78230f8873e91b244868 (diff)
downloadchromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.zip
chromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.tar.gz
chromium_src-9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f.tar.bz2
Adds memory cache logging, and updates disk cache logging.
Memory and disk cache use the same set of events, with the same parameters (Though the disk cache has a couple events the memory cache does not). Most disk cache events were renamed so as to no longer imply a connection to the disk cache, and all disk cache-related NetLog parameter class definitions were moved to a new file, since they're shared by both entry type. BUG=59382 TEST=none Review URL: http://codereview.chromium.org/6613027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78572 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc2
-rw-r--r--net/disk_cache/backend_unittest.cc2
-rw-r--r--net/disk_cache/disk_cache_test_base.cc4
-rw-r--r--net/disk_cache/entry_impl.cc111
-rw-r--r--net/disk_cache/mem_backend_impl.cc9
-rw-r--r--net/disk_cache/mem_backend_impl.h10
-rw-r--r--net/disk_cache/mem_entry_impl.cc196
-rw-r--r--net/disk_cache/mem_entry_impl.h23
-rw-r--r--net/disk_cache/net_log_parameters.cc100
-rw-r--r--net/disk_cache/net_log_parameters.h99
-rw-r--r--net/disk_cache/sparse_control.cc85
11 files changed, 476 insertions, 165 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index cac4656..16e1a76 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -295,7 +295,7 @@ int CreateCacheBackend(net::CacheType type, const FilePath& path, int max_bytes,
CompletionCallback* callback) {
DCHECK(callback);
if (type == net::MEMORY_CACHE) {
- *backend = MemBackendImpl::CreateBackend(max_bytes);
+ *backend = MemBackendImpl::CreateBackend(max_bytes, net_log);
return *backend ? net::OK : net::ERR_FAILED;
}
DCHECK(thread);
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index aab0ccb..185d29c 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -206,7 +206,7 @@ TEST_F(DiskCacheTest, CreateBackend) {
ASSERT_TRUE(cache);
delete cache;
- cache = disk_cache::MemBackendImpl::CreateBackend(0);
+ cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL);
ASSERT_TRUE(cache);
delete cache;
cache = NULL;
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index 41d1caf..bbcb65d 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -221,11 +221,11 @@ void DiskCacheTestWithCache::TearDown() {
void DiskCacheTestWithCache::InitMemoryCache() {
if (!implementation_) {
- cache_ = disk_cache::MemBackendImpl::CreateBackend(size_);
+ cache_ = disk_cache::MemBackendImpl::CreateBackend(size_, NULL);
return;
}
- mem_cache_ = new disk_cache::MemBackendImpl();
+ mem_cache_ = new disk_cache::MemBackendImpl(NULL);
cache_ = mem_cache_;
ASSERT_TRUE(NULL != cache_);
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 085efd2..2db4988 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -7,13 +7,13 @@
#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"
#include "net/disk_cache/bitmap.h"
#include "net/disk_cache/cache_util.h"
#include "net/disk_cache/histogram_macros.h"
+#include "net/disk_cache/net_log_parameters.h"
#include "net/disk_cache/sparse_control.h"
using base::Time;
@@ -25,82 +25,6 @@ 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 {
@@ -125,7 +49,7 @@ class SyncCallback: public disk_cache::FileIOCallback {
net::CompletionCallback* callback_;
scoped_refptr<net::IOBuffer> buf_;
TimeTicks start_;
- net::NetLog::EventType end_event_type_;
+ const net::NetLog::EventType end_event_type_;
DISALLOW_COPY_AND_ASSIGN(SyncCallback);
};
@@ -136,7 +60,8 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) {
if (entry_->net_log().IsLoggingAllEvents()) {
entry_->net_log().EndEvent(
end_event_type_,
- make_scoped_refptr(new FileIOCompleteParameters(bytes_copied)));
+ make_scoped_refptr(
+ new disk_cache::ReadWriteCompleteParameters(bytes_copied)));
}
entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
callback_->Run(bytes_copied);
@@ -386,17 +311,17 @@ 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,
+ net::NetLog::TYPE_ENTRY_READ_DATA,
make_scoped_refptr(
- new ReadWriteDataParams(index, offset, buf_len, false)));
+ new ReadWriteDataParameters(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)));
+ net::NetLog::TYPE_ENTRY_READ_DATA,
+ make_scoped_refptr(new ReadWriteCompleteParameters(result)));
}
return result;
}
@@ -406,9 +331,9 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
bool truncate) {
if (net_log_.IsLoggingAllEvents()) {
net_log_.BeginEvent(
- net::NetLog::TYPE_DISK_CACHE_WRITE_DATA,
+ net::NetLog::TYPE_ENTRY_WRITE_DATA,
make_scoped_refptr(
- new ReadWriteDataParams(index, offset, buf_len, truncate)));
+ new ReadWriteDataParameters(index, offset, buf_len, truncate)));
}
int result = InternalWriteData(index, offset, buf, buf_len, callback,
@@ -416,8 +341,8 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
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)));
+ net::NetLog::TYPE_ENTRY_WRITE_DATA,
+ make_scoped_refptr(new ReadWriteCompleteParameters(result)));
}
return result;
}
@@ -531,7 +456,7 @@ bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) {
}
void EntryImpl::InternalDoom() {
- net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_DOOM, NULL);
+ net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL);
DCHECK(node_.HasData());
if (!node_.Data()->dirty) {
node_.Data()->dirty = backend_->GetCurrentEntryId();
@@ -692,7 +617,7 @@ void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) {
net_log_ = net::BoundNetLog::Make(
net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY);
net_log_.BeginEvent(
- net::NetLog::TYPE_DISK_CACHE_ENTRY,
+ net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL,
make_scoped_refptr(new EntryCreationParameters(GetKey(), created)));
}
@@ -859,7 +784,7 @@ EntryImpl::~EntryImpl() {
if (doomed_) {
DeleteEntryData(true);
} else {
- net_log_.AddEvent(net::NetLog::TYPE_DISK_CACHE_CLOSE, NULL);
+ net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE, NULL);
bool ret = true;
for (int index = 0; index < kNumStreams; index++) {
if (user_buffers_[index].get()) {
@@ -885,7 +810,7 @@ EntryImpl::~EntryImpl() {
}
Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
- net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL);
+ net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, NULL);
backend_->OnEntryDestroyEnd();
}
@@ -944,7 +869,7 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
SyncCallback* io_callback = NULL;
if (callback) {
io_callback = new SyncCallback(this, buf, callback,
- net::NetLog::TYPE_DISK_CACHE_READ_DATA);
+ net::NetLog::TYPE_ENTRY_READ_DATA);
}
bool completed;
@@ -1038,7 +963,7 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
SyncCallback* io_callback = NULL;
if (callback) {
io_callback = new SyncCallback(this, buf, callback,
- net::NetLog::TYPE_DISK_CACHE_WRITE_DATA);
+ net::NetLog::TYPE_ENTRY_WRITE_DATA);
}
bool completed;
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index 1122bca..c2f0438 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -28,7 +28,8 @@ int LowWaterAdjust(int high_water) {
namespace disk_cache {
-MemBackendImpl::MemBackendImpl() : max_size_(0), current_size_(0) {}
+MemBackendImpl::MemBackendImpl(net::NetLog* net_log)
+ : max_size_(0), current_size_(0), net_log_(net_log) {}
MemBackendImpl::~MemBackendImpl() {
EntryMap::iterator it = entries_.begin();
@@ -40,8 +41,8 @@ MemBackendImpl::~MemBackendImpl() {
}
// Static.
-Backend* MemBackendImpl::CreateBackend(int max_bytes) {
- MemBackendImpl* cache = new MemBackendImpl();
+Backend* MemBackendImpl::CreateBackend(int max_bytes, net::NetLog* net_log) {
+ MemBackendImpl* cache = new MemBackendImpl(net_log);
cache->SetMaxSize(max_bytes);
if (cache->Init())
return cache;
@@ -204,7 +205,7 @@ bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) {
return false;
MemEntryImpl* cache_entry = new MemEntryImpl(this);
- if (!cache_entry->CreateEntry(key)) {
+ if (!cache_entry->CreateEntry(key, net_log_)) {
delete entry;
return false;
}
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index 9b920ac5..01f68d3 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -13,6 +13,10 @@
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/mem_rankings.h"
+namespace net {
+class NetLog;
+} // namespace net
+
namespace disk_cache {
class MemEntryImpl;
@@ -21,7 +25,7 @@ class MemEntryImpl;
// the operations of the cache without writing to disk.
class MemBackendImpl : public Backend {
public:
- MemBackendImpl();
+ explicit MemBackendImpl(net::NetLog* net_log);
~MemBackendImpl();
// Returns an instance of a Backend implemented only in memory. The returned
@@ -29,7 +33,7 @@ class MemBackendImpl : public Backend {
// size the cache can grow to. If zero is passed in as max_bytes, the cache
// will determine the value to use based on the available memory. The returned
// pointer can be NULL if a fatal error is found.
- static Backend* CreateBackend(int max_bytes);
+ static Backend* CreateBackend(int max_bytes, net::NetLog* net_log);
// Performs general initialization for this current instance of the cache.
bool Init();
@@ -104,6 +108,8 @@ class MemBackendImpl : public Backend {
int32 max_size_; // Maximum data size for this instance.
int32 current_size_;
+ net::NetLog* net_log_;
+
DISALLOW_COPY_AND_ASSIGN(MemBackendImpl);
};
diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc
index 2b37f36..9df7306 100644
--- a/net/disk_cache/mem_entry_impl.cc
+++ b/net/disk_cache/mem_entry_impl.cc
@@ -5,9 +5,11 @@
#include "net/disk_cache/mem_entry_impl.h"
#include "base/logging.h"
+#include "base/stringprintf.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/mem_backend_impl.h"
+#include "net/disk_cache/net_log_parameters.h"
using base::Time;
@@ -31,7 +33,15 @@ inline int ToChildOffset(int64 offset) {
return static_cast<int>(offset & (kMaxSparseEntrySize - 1));
}
-} // nemespace
+// Returns a name for a child entry given the base_name of the parent and the
+// child_id. This name is only used for logging purposes.
+// If the entry is called entry_name, child entries will be named something
+// like Range_entry_name:YYY where YYY is the number of the particular child.
+std::string GenerateChildName(const std::string& base_name, int child_id) {
+ return base::StringPrintf("Range_%s:%i", base_name.c_str(), child_id);
+}
+
+} // namespace
namespace disk_cache {
@@ -50,7 +60,12 @@ MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) {
// ------------------------------------------------------------------------
-bool MemEntryImpl::CreateEntry(const std::string& key) {
+bool MemEntryImpl::CreateEntry(const std::string& key, net::NetLog* net_log) {
+ net_log_ = net::BoundNetLog::Make(net_log,
+ net::NetLog::SOURCE_MEMORY_CACHE_ENTRY);
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL,
+ make_scoped_refptr(new EntryCreationParameters(key, true)));
key_ = key;
Time current = Time::Now();
last_modified_ = current;
@@ -61,6 +76,7 @@ bool MemEntryImpl::CreateEntry(const std::string& key) {
}
void MemEntryImpl::InternalDoom() {
+ net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL);
doomed_ = true;
if (!ref_count_) {
if (type() == kParentEntry) {
@@ -152,6 +168,108 @@ int32 MemEntryImpl::GetDataSize(int index) const {
int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
int buf_len, net::CompletionCallback* completion_callback) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_ENTRY_READ_DATA,
+ make_scoped_refptr(
+ new ReadWriteDataParameters(index, offset, buf_len, false)));
+ }
+
+ int result = InternalReadData(index, offset, buf, buf_len);
+
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEvent(
+ net::NetLog::TYPE_ENTRY_READ_DATA,
+ make_scoped_refptr(new ReadWriteCompleteParameters(result)));
+ }
+ return result;
+}
+
+int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, net::CompletionCallback* completion_callback, bool truncate) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_ENTRY_WRITE_DATA,
+ make_scoped_refptr(
+ new ReadWriteDataParameters(index, offset, buf_len, truncate)));
+ }
+
+ int result = InternalWriteData(index, offset, buf, buf_len, truncate);
+
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEvent(
+ net::NetLog::TYPE_ENTRY_WRITE_DATA,
+ make_scoped_refptr(new ReadWriteCompleteParameters(result)));
+ }
+ return result;
+}
+
+int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* completion_callback) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_SPARSE_READ,
+ make_scoped_refptr(
+ new SparseOperationParameters(offset, buf_len)));
+ }
+ int result = InternalReadSparseData(offset, buf, buf_len);
+ if (net_log_.IsLoggingAllEvents())
+ net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ, NULL);
+ return result;
+}
+
+int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* completion_callback) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_WRITE,
+ make_scoped_refptr(
+ new SparseOperationParameters(offset, buf_len)));
+ }
+ int result = InternalWriteSparseData(offset, buf, buf_len);
+ if (net_log_.IsLoggingAllEvents())
+ net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE, NULL);
+ return result;
+}
+
+int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
+ CompletionCallback* callback) {
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_SPARSE_GET_RANGE,
+ make_scoped_refptr(
+ new SparseOperationParameters(offset, len)));
+ }
+ int result = GetAvailableRange(offset, len, start);
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEvent(
+ net::NetLog::TYPE_SPARSE_GET_RANGE,
+ make_scoped_refptr(
+ new GetAvailableRangeResultParameters(*start, result)));
+ }
+ return result;
+}
+
+bool MemEntryImpl::CouldBeSparse() const {
+ DCHECK_EQ(kParentEntry, type());
+ return (children_.get() != NULL);
+}
+
+int MemEntryImpl::ReadyForSparseIO(
+ net::CompletionCallback* completion_callback) {
+ return net::OK;
+}
+
+// ------------------------------------------------------------------------
+
+MemEntryImpl::~MemEntryImpl() {
+ for (int i = 0; i < NUM_STREAMS; i++)
+ backend_->ModifyStorageSize(data_size_[i], 0);
+ backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0);
+ net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, NULL);
+}
+
+int MemEntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf,
+ int buf_len) {
DCHECK(type() == kParentEntry || index == kSparseData);
if (index < 0 || index >= NUM_STREAMS)
@@ -169,12 +287,12 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf,
UpdateRank(false);
- memcpy(buf->data() , &(data_[index])[offset], buf_len);
+ memcpy(buf->data(), &(data_[index])[offset], buf_len);
return buf_len;
}
-int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
- int buf_len, net::CompletionCallback* completion_callback, bool truncate) {
+int MemEntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf,
+ int buf_len, bool truncate) {
DCHECK(type() == kParentEntry || index == kSparseData);
if (index < 0 || index >= NUM_STREAMS)
@@ -215,8 +333,8 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf,
return buf_len;
}
-int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback) {
+int MemEntryImpl::InternalReadSparseData(int64 offset, net::IOBuffer* buf,
+ int buf_len) {
DCHECK(type() == kParentEntry);
if (!InitSparseInfo())
@@ -244,8 +362,19 @@ int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
// we should stop.
if (child_offset < child->child_first_pos_)
break;
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
+ make_scoped_refptr(new SparseReadWriteParameters(
+ child->net_log().source(),
+ io_buf->BytesRemaining())));
+ }
int ret = child->ReadData(kSparseData, child_offset, io_buf,
io_buf->BytesRemaining(), NULL);
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEventWithNetErrorCode(
+ net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret);
+ }
// If we encounter an error in one entry, return immediately.
if (ret < 0)
@@ -262,8 +391,8 @@ int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
return io_buf->BytesConsumed();
}
-int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback) {
+int MemEntryImpl::InternalWriteSparseData(int64 offset, net::IOBuffer* buf,
+ int buf_len) {
DCHECK(type() == kParentEntry);
if (!InitSparseInfo())
@@ -291,12 +420,24 @@ int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
// Keep a record of the last byte position (exclusive) in the child.
int data_size = child->GetDataSize(kSparseData);
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
+ make_scoped_refptr(new SparseReadWriteParameters(
+ child->net_log().source(),
+ write_len)));
+ }
+
// Always writes to the child entry. This operation may overwrite data
// previously written.
// TODO(hclam): if there is data in the entry and this write is not
// continuous we may want to discard this write.
int ret = child->WriteData(kSparseData, child_offset, io_buf, write_len,
NULL, true);
+ if (net_log_.IsLoggingAllEvents()) {
+ net_log_.EndEventWithNetErrorCode(
+ net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret);
+ }
if (ret < 0)
return ret;
else if (ret == 0)
@@ -317,29 +458,6 @@ int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
return io_buf->BytesConsumed();
}
-int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
- CompletionCallback* callback) {
- return GetAvailableRange(offset, len, start);
-}
-
-bool MemEntryImpl::CouldBeSparse() const {
- DCHECK_EQ(kParentEntry, type());
- return (children_.get() != NULL);
-}
-
-int MemEntryImpl::ReadyForSparseIO(
- net::CompletionCallback* completion_callback) {
- return net::OK;
-}
-
-// ------------------------------------------------------------------------
-
-MemEntryImpl::~MemEntryImpl() {
- for (int i = 0; i < NUM_STREAMS; i++)
- backend_->ModifyStorageSize(data_size_[i], 0);
- backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0);
-}
-
int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start) {
DCHECK(type() == kParentEntry);
DCHECK(start);
@@ -429,9 +547,19 @@ bool MemEntryImpl::InitSparseInfo() {
return true;
}
-bool MemEntryImpl::InitChildEntry(MemEntryImpl* parent, int child_id) {
+bool MemEntryImpl::InitChildEntry(MemEntryImpl* parent, int child_id,
+ net::NetLog* net_log) {
DCHECK(!parent_);
DCHECK(!child_id_);
+
+ net_log_ = net::BoundNetLog::Make(net_log,
+ net::NetLog::SOURCE_MEMORY_CACHE_ENTRY);
+ net_log_.BeginEvent(
+ net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL,
+ make_scoped_refptr(new EntryCreationParameters(
+ GenerateChildName(parent->key(), child_id_),
+ true)));
+
parent_ = parent;
child_id_ = child_id;
Time current = Time::Now();
@@ -450,7 +578,7 @@ MemEntryImpl* MemEntryImpl::OpenChild(int64 offset, bool create) {
return i->second;
} else if (create) {
MemEntryImpl* child = new MemEntryImpl(backend_);
- child->InitChildEntry(this, index);
+ child->InitChildEntry(this, index, net_log_.net_log());
(*children_)[index] = child;
return child;
}
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index f4ac4ef..f195b75 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -8,6 +8,7 @@
#include "base/hash_tables.h"
#include "base/scoped_ptr.h"
+#include "net/base/net_log.h"
#include "net/disk_cache/disk_cache.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -54,7 +55,7 @@ class MemEntryImpl : public Entry {
// Performs the initialization of a EntryImpl that will be added to the
// cache.
- bool CreateEntry(const std::string& key);
+ bool CreateEntry(const std::string& key, net::NetLog* net_log);
// Permanently destroys this entry.
void InternalDoom();
@@ -82,6 +83,14 @@ class MemEntryImpl : public Entry {
return parent_ ? kChildEntry : kParentEntry;
}
+ std::string& key() {
+ return key_;
+ }
+
+ net::BoundNetLog& net_log() {
+ return net_log_;
+ }
+
// Entry interface.
virtual void Doom();
virtual void Close();
@@ -113,6 +122,14 @@ class MemEntryImpl : public Entry {
~MemEntryImpl();
+ // Do all the work for corresponding public functions. Implemented as
+ // separate functions to make logging of results simpler.
+ int InternalReadData(int index, int offset, net::IOBuffer* buf, int buf_len);
+ int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ bool truncate);
+ int InternalReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len);
+ int InternalWriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len);
+
// Old Entry interface.
int GetAvailableRange(int64 offset, int len, int64* start);
@@ -129,7 +146,7 @@ class MemEntryImpl : public Entry {
// Performs the initialization of a MemEntryImpl as a child entry.
// |parent| is the pointer to the parent entry. |child_id| is the ID of
// the new child.
- bool InitChildEntry(MemEntryImpl* parent, int child_id);
+ bool InitChildEntry(MemEntryImpl* parent, int child_id, net::NetLog* net_log);
// Returns an entry responsible for |offset|. The returned entry can be a
// child entry or this entry itself if |offset| points to the first range.
@@ -163,6 +180,8 @@ class MemEntryImpl : public Entry {
MemBackendImpl* backend_; // Back pointer to the cache.
bool doomed_; // True if this entry was removed from the cache.
+ net::BoundNetLog net_log_;
+
DISALLOW_COPY_AND_ASSIGN(MemEntryImpl);
};
diff --git a/net/disk_cache/net_log_parameters.cc b/net/disk_cache/net_log_parameters.cc
new file mode 100644
index 0000000..76d79d7
--- /dev/null
+++ b/net/disk_cache/net_log_parameters.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/disk_cache/net_log_parameters.h"
+
+#include "base/logging.h"
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "net/base/net_errors.h"
+
+namespace disk_cache {
+
+EntryCreationParameters::EntryCreationParameters(
+ const std::string& key, bool created)
+ : key_(key), created_(created) {
+}
+
+Value* EntryCreationParameters::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("key", key_);
+ dict->SetBoolean("created", created_);
+ return dict;
+}
+
+ReadWriteDataParameters::ReadWriteDataParameters(
+ int index, int offset, int buf_len, bool truncate)
+ : index_(index), offset_(offset), buf_len_(buf_len), truncate_(truncate) {
+}
+
+Value* ReadWriteDataParameters::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;
+}
+
+
+// NetLog parameters logged when non-sparse reads and writes complete.
+ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied)
+ : bytes_copied_(bytes_copied) {
+}
+
+Value* ReadWriteCompleteParameters::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;
+}
+
+SparseOperationParameters::SparseOperationParameters(
+ int64 offset, int buff_len)
+ : offset_(offset), buff_len_(buff_len) {
+}
+
+Value* SparseOperationParameters::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ // Values can only be created with at most 32-bit integers. Using a string
+ // instead circumvents that restriction.
+ dict->SetString("offset", base::Int64ToString(offset_));
+ dict->SetInteger("buff_len", buff_len_);
+ return dict;
+}
+
+SparseReadWriteParameters::SparseReadWriteParameters(
+ const net::NetLog::Source& source, int child_len)
+ : source_(source), child_len_(child_len) {
+}
+
+Value* SparseReadWriteParameters::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->Set("source_dependency", source_.ToValue());
+ dict->SetInteger("child_len", child_len_);
+ return dict;
+}
+
+GetAvailableRangeResultParameters::GetAvailableRangeResultParameters(
+ int64 start, int result)
+ : start_(start), result_(result) {
+}
+
+Value* GetAvailableRangeResultParameters::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ if (result_ > 0) {
+ dict->SetInteger("length", result_);
+ dict->SetString("start", base::Int64ToString(start_));
+ } else {
+ dict->SetInteger("net_error", result_);
+ }
+ return dict;
+}
+
+} // namespace disk_cache
diff --git a/net/disk_cache/net_log_parameters.h b/net/disk_cache/net_log_parameters.h
new file mode 100644
index 0000000..f708c79
--- /dev/null
+++ b/net/disk_cache/net_log_parameters.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_DISK_CACHE_NET_LOG_PARAMETERS_H_
+#define NET_DISK_CACHE_NET_LOG_PARAMETERS_H_
+#pragma once
+
+#include <string>
+
+#include "net/base/net_log.h"
+
+// This file contains a set of NetLog::EventParameters shared by EntryImpls and
+// MemEntryImpls.
+namespace disk_cache {
+
+// NetLog parameters for the creation of an Entry. Contains the Entry's name
+// and whether it was created or opened.
+class EntryCreationParameters : public net::NetLog::EventParameters {
+ public:
+ EntryCreationParameters(const std::string& key, bool created);
+ virtual Value* ToValue() const;
+
+ private:
+ const std::string key_;
+ const bool created_;
+
+ DISALLOW_COPY_AND_ASSIGN(EntryCreationParameters);
+};
+
+// NetLog parameters for non-sparse reading and writing to an Entry.
+class ReadWriteDataParameters : public net::NetLog::EventParameters {
+ public:
+ // For reads, |truncate| must be false.
+ ReadWriteDataParameters(int index, int offset, int buf_len, bool truncate);
+ virtual Value* ToValue() const;
+
+ private:
+ const int index_;
+ const int offset_;
+ const int buf_len_;
+ const bool truncate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadWriteDataParameters);
+};
+
+// NetLog parameters for when a non-sparse read or write completes.
+class ReadWriteCompleteParameters : 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 ReadWriteCompleteParameters(int bytes_copied);
+ virtual Value* ToValue() const;
+
+ private:
+ const int bytes_copied_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReadWriteCompleteParameters);
+};
+
+// NetLog parameters for when a sparse operation is started.
+class SparseOperationParameters : public net::NetLog::EventParameters {
+ public:
+ SparseOperationParameters(int64 offset, int buff_len);
+ virtual Value* ToValue() const;
+
+ private:
+ const int64 offset_;
+ const int buff_len_;
+};
+
+// NetLog parameters for when a read or write for a sparse entry's child is
+// started.
+class SparseReadWriteParameters : public net::NetLog::EventParameters {
+ public:
+ SparseReadWriteParameters(const net::NetLog::Source& source, int child_len);
+ virtual Value* ToValue() const;
+
+ private:
+ const net::NetLog::Source source_;
+ const int child_len_;
+};
+
+// NetLog parameters for when a call to GetAvailableRange returns.
+class GetAvailableRangeResultParameters : public net::NetLog::EventParameters {
+ public:
+ // |start| is ignored when |result| < 0.
+ GetAvailableRangeResultParameters(int64 start, int result);
+ virtual Value* ToValue() const;
+
+ private:
+ const int64 start_;
+ const int result_;
+};
+
+} // namespace disk_cache
+
+#endif // NET_DISK_CACHE_NET_LOG_CACHE_PARAMETERS_H_
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index bd8908f..887d78d 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -15,6 +15,7 @@
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/file.h"
+#include "net/disk_cache/net_log_parameters.h"
using base::Time;
@@ -35,7 +36,7 @@ const int kMaxEntrySize = 0x100000;
// The size of each data block (tracked by the child allocation bitmap).
const int kBlockSize = 1024;
-// Returns the name of of a child entry given the base_name and signature of the
+// Returns the name of a child entry given the base_name and signature of the
// parent and the child_id.
// If the entry is called entry_name, child entries will be named something
// like Range_entry_name:XXX:YYY where XXX is the entry signature and YYY is the
@@ -138,22 +139,38 @@ 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) {
+// Returns the NetLog event type corresponding to a SparseOperation.
+net::NetLog::EventType GetSparseEventType(
+ disk_cache::SparseControl::SparseOperation operation) {
+ switch (operation) {
+ case disk_cache::SparseControl::kReadOperation:
+ return net::NetLog::TYPE_SPARSE_READ;
+ case disk_cache::SparseControl::kWriteOperation:
+ return net::NetLog::TYPE_SPARSE_WRITE;
+ case disk_cache::SparseControl::kGetRangeOperation:
+ return net::NetLog::TYPE_SPARSE_GET_RANGE;
+ default:
+ NOTREACHED();
+ return net::NetLog::TYPE_CANCELLED;
+ }
+}
+
+// Logs the end event for |operation| on a child entry. Range operations log
+// no events for each child they search through.
+void LogChildOperationEnd(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;
+ event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA;
break;
case disk_cache::SparseControl::kWriteOperation:
- event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE;
+ event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA;
break;
case disk_cache::SparseControl::kGetRangeOperation:
- event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE;
- break;
+ return;
default:
NOTREACHED();
return;
@@ -247,7 +264,11 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
finished_ = false;
abort_ = false;
- entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().BeginEvent(
+ GetSparseEventType(operation_),
+ make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_)));
+ }
DoChildrenIO();
if (!pending_) {
@@ -317,6 +338,8 @@ void SparseControl::DeleteChildren(EntryImpl* entry) {
if (!buffer && !address.is_initialized())
return;
+ entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL);
+
ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_,
entry->GetKey());
// The object will self destruct when finished.
@@ -635,8 +658,20 @@ void SparseControl::InitChildData() {
void SparseControl::DoChildrenIO() {
while (DoChildIO()) continue;
+ // Range operations are finished synchronously, often without setting
+ // |finished_| to true.
+ if (kGetRangeOperation == operation_ &&
+ entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().EndEvent(
+ net::NetLog::TYPE_SPARSE_GET_RANGE,
+ make_scoped_refptr(
+ new GetAvailableRangeResultParameters(offset_, result_)));
+ }
if (finished_) {
- entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL);
+ if (kGetRangeOperation != operation_ &&
+ entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
+ }
if (pending_)
DoUserCallback();
}
@@ -662,10 +697,10 @@ bool SparseControl::DoChildIO() {
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())));
+ net::NetLog::TYPE_SPARSE_READ_CHILD_DATA,
+ make_scoped_refptr(new SparseReadWriteParameters(
+ child_->net_log().source(),
+ child_len_)));
}
rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_,
child_len_, callback);
@@ -673,19 +708,15 @@ bool SparseControl::DoChildIO() {
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())));
+ net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA,
+ make_scoped_refptr(new SparseReadWriteParameters(
+ child_->net_log().source(),
+ child_len_)));
}
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:
@@ -758,7 +789,7 @@ int SparseControl::DoGetAvailableRange() {
}
void SparseControl::DoChildIOCompleted(int result) {
- LogOperationEnd(entry_->net_log(), operation_, result);
+ LogChildOperationEnd(entry_->net_log(), operation_, result);
if (result < 0) {
// We fail the whole operation if we encounter an error.
result_ = result;
@@ -784,8 +815,10 @@ 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);
+ if (entry_->net_log().IsLoggingAllEvents()) {
+ entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL);
+ entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL);
+ }
DoUserCallback();
return DoAbortCallbacks();
}