diff options
author | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:53:02 +0000 |
---|---|---|
committer | mmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-17 18:53:02 +0000 |
commit | 9eb8cdff6c4e93d2609ee9a12cbd6b3dfa8b7d7f (patch) | |
tree | a3024687f2041d1f464aeb073d289c1bb7daae74 /net/disk_cache/entry_impl.cc | |
parent | d767b2c624529faef3bf78230f8873e91b244868 (diff) | |
download | chromium_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/entry_impl.cc')
-rw-r--r-- | net/disk_cache/entry_impl.cc | 111 |
1 files changed, 18 insertions, 93 deletions
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; |