diff options
-rw-r--r-- | net/disk_cache/entry_impl.cc | 21 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.cc | 73 | ||||
-rw-r--r-- | net/disk_cache/net_log_parameters.cc | 161 | ||||
-rw-r--r-- | net/disk_cache/net_log_parameters.h | 144 | ||||
-rw-r--r-- | net/disk_cache/sparse_control.cc | 23 |
5 files changed, 186 insertions, 236 deletions
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 4991375..b79230f 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -61,8 +61,7 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().EndEvent( end_event_type_, - make_scoped_refptr( - new disk_cache::ReadWriteCompleteParameters(bytes_copied))); + disk_cache::CreateNetLogReadWriteCompleteCallback(bytes_copied)); } entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); callback_.Run(bytes_copied); @@ -314,8 +313,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, false))); + CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); } int result = InternalReadData(index, offset, buf, buf_len, callback); @@ -323,7 +321,7 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); + CreateNetLogReadWriteCompleteCallback(result)); } return result; } @@ -334,8 +332,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, truncate))); + CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); } int result = InternalWriteData(index, offset, buf, buf_len, callback, @@ -344,7 +341,7 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); + CreateNetLogReadWriteCompleteCallback(result)); } return result; } @@ -458,7 +455,7 @@ bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) { } void EntryImpl::InternalDoom() { - net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM); DCHECK(node_.HasData()); if (!node_.Data()->dirty) { node_.Data()->dirty = backend_->GetCurrentEntryId(); @@ -724,7 +721,7 @@ void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) { net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); net_log_.BeginEvent( net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, - make_scoped_refptr(new EntryCreationParameters(GetKey(), created))); + CreateNetLogEntryCreationCallback(this, created)); } const net::BoundNetLog& EntryImpl::net_log() const { @@ -934,7 +931,7 @@ EntryImpl::~EntryImpl() { #if defined(NET_BUILD_STRESS_CACHE) SanityCheck(); #endif - net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE, NULL); + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE); bool ret = true; for (int index = 0; index < kNumStreams; index++) { if (user_buffers_[index].get()) { @@ -960,7 +957,7 @@ EntryImpl::~EntryImpl() { } Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); - net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, NULL); + net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL); backend_->OnEntryDestroyEnd(); } diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc index 776759b..0d3b00a 100644 --- a/net/disk_cache/mem_entry_impl.cc +++ b/net/disk_cache/mem_entry_impl.cc @@ -4,8 +4,10 @@ #include "net/disk_cache/mem_entry_impl.h" +#include "base/bind.h" #include "base/logging.h" #include "base/stringprintf.h" +#include "base/values.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/disk_cache/mem_backend_impl.h" @@ -41,6 +43,17 @@ std::string GenerateChildName(const std::string& base_name, int child_id) { return base::StringPrintf("Range_%s:%i", base_name.c_str(), child_id); } +// Returns NetLog parameters for the creation of a child MemEntryImpl. Separate +// function needed because child entries don't suppport GetKey(). +Value* NetLogChildEntryCreationCallback(const disk_cache::MemEntryImpl* parent, + int child_id, + net::NetLog::LogLevel /* log_level */) { + DictionaryValue* dict = new DictionaryValue(); + dict->SetString("key", GenerateChildName(parent->GetKey(), child_id)); + dict->SetBoolean("created", true); + return dict; +} + } // namespace namespace disk_cache { @@ -61,22 +74,25 @@ MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { // ------------------------------------------------------------------------ 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; last_used_ = current; + + net_log_ = net::BoundNetLog::Make(net_log, + net::NetLog::SOURCE_MEMORY_CACHE_ENTRY); + // Must be called after |key_| is set, so GetKey() works. + net_log_.BeginEvent( + net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, + CreateNetLogEntryCreationCallback(this, true)); + Open(); backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); return true; } void MemEntryImpl::InternalDoom() { - net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); + net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM); doomed_ = true; if (!ref_count_) { if (type() == kParentEntry) { @@ -171,8 +187,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, false))); + CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); } int result = InternalReadData(index, offset, buf, buf_len); @@ -180,7 +195,7 @@ int MemEntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_READ_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); + CreateNetLogReadWriteCompleteCallback(result)); } return result; } @@ -190,8 +205,7 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr( - new ReadWriteDataParameters(index, offset, buf_len, truncate))); + CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); } int result = InternalWriteData(index, offset, buf, buf_len, truncate); @@ -199,7 +213,7 @@ int MemEntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.EndEvent( net::NetLog::TYPE_ENTRY_WRITE_DATA, - make_scoped_refptr(new ReadWriteCompleteParameters(result))); + CreateNetLogReadWriteCompleteCallback(result)); } return result; } @@ -209,25 +223,24 @@ int MemEntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_READ, - make_scoped_refptr( - new SparseOperationParameters(offset, buf_len))); + CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalReadSparseData(offset, buf, buf_len); if (net_log_.IsLoggingAllEvents()) - net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ, NULL); + net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ); return result; } int MemEntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, const CompletionCallback& callback) { if (net_log_.IsLoggingAllEvents()) { - net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_WRITE, - make_scoped_refptr( - new SparseOperationParameters(offset, buf_len))); + net_log_.BeginEvent( + net::NetLog::TYPE_SPARSE_WRITE, + CreateNetLogSparseOperationCallback(offset, buf_len)); } int result = InternalWriteSparseData(offset, buf, buf_len); if (net_log_.IsLoggingAllEvents()) - net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE, NULL); + net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE); return result; } @@ -236,15 +249,13 @@ int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, if (net_log_.IsLoggingAllEvents()) { net_log_.BeginEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, - make_scoped_refptr( - new SparseOperationParameters(offset, len))); + CreateNetLogSparseOperationCallback(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))); + CreateNetLogGetAvailableRangeResultCallback(*start, result)); } return result; } @@ -264,7 +275,7 @@ 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); + net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL); } int MemEntryImpl::InternalReadData(int index, int offset, IOBuffer* buf, @@ -364,9 +375,8 @@ int MemEntryImpl::InternalReadSparseData(int64 offset, IOBuffer* buf, 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()))); + CreateNetLogSparseReadWriteCallback(child->net_log().source(), + io_buf->BytesRemaining())); } int ret = child->ReadData(kSparseData, child_offset, io_buf, io_buf->BytesRemaining(), CompletionCallback()); @@ -422,9 +432,8 @@ int MemEntryImpl::InternalWriteSparseData(int64 offset, IOBuffer* buf, 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))); + CreateNetLogSparseReadWriteCallback(child->net_log().source(), + write_len)); } // Always writes to the child entry. This operation may overwrite data @@ -555,9 +564,7 @@ bool MemEntryImpl::InitChildEntry(MemEntryImpl* parent, int child_id, 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))); + base::Bind(&NetLogChildEntryCreationCallback, parent, child_id_)); parent_ = parent; child_id_ = child_id; diff --git a/net/disk_cache/net_log_parameters.cc b/net/disk_cache/net_log_parameters.cc index 3a309f9..dcf18d6 100644 --- a/net/disk_cache/net_log_parameters.cc +++ b/net/disk_cache/net_log_parameters.cc @@ -4,122 +4,125 @@ #include "net/disk_cache/net_log_parameters.h" +#include "base/bind.h" #include "base/logging.h" #include "base/string_number_conversions.h" #include "base/values.h" #include "net/base/net_errors.h" +#include "net/disk_cache/disk_cache.h" -namespace disk_cache { +namespace { -EntryCreationParameters::EntryCreationParameters( - const std::string& key, - bool created) - : key_(key), - created_(created) { +Value* NetLogEntryCreationCallback(const disk_cache::Entry* entry, + bool created, + net::NetLog::LogLevel /* log_level */) { + DictionaryValue* dict = new DictionaryValue(); + dict->SetString("key", entry->GetKey()); + dict->SetBoolean("created", created); + return dict; } -Value* EntryCreationParameters::ToValue() const { +Value* NetLogReadWriteDataCallback(int index, + int offset, + int buf_len, + bool truncate, + net::NetLog::LogLevel /* log_level */) { DictionaryValue* dict = new DictionaryValue(); - dict->SetString("key", key_); - dict->SetBoolean("created", created_); + dict->SetInteger("index", index); + dict->SetInteger("offset", offset); + dict->SetInteger("buf_len", buf_len); + if (truncate) + dict->SetBoolean("truncate", truncate); return dict; } -EntryCreationParameters::~EntryCreationParameters() {} - -ReadWriteDataParameters::ReadWriteDataParameters( - int index, - int offset, - int buf_len, - bool truncate) - : index_(index), - offset_(offset), - buf_len_(buf_len), - truncate_(truncate) { +Value* NetLogReadWriteCompleteCallback(int bytes_copied, + net::NetLog::LogLevel /* log_level */) { + 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; } -Value* ReadWriteDataParameters::ToValue() const { +Value* NetLogSparseOperationCallback(int64 offset, + int buff_len, + net::NetLog::LogLevel /* log_level */) { DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger("index", index_); - dict->SetInteger("offset", offset_); - dict->SetInteger("buf_len", buf_len_); - if (truncate_) - dict->SetBoolean("truncate", truncate_); + // 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; } -ReadWriteDataParameters::~ReadWriteDataParameters() {} - -// NetLog parameters logged when non-sparse reads and writes complete. -ReadWriteCompleteParameters::ReadWriteCompleteParameters(int bytes_copied) - : bytes_copied_(bytes_copied) { +Value* NetLogSparseReadWriteCallback(const net::NetLog::Source& source, + int child_len, + net::NetLog::LogLevel /* log_level */) { + DictionaryValue* dict = new DictionaryValue(); + source.AddToEventParameters(dict); + dict->SetInteger("child_len", child_len); + return dict; } -Value* ReadWriteCompleteParameters::ToValue() const { - DCHECK_NE(bytes_copied_, net::ERR_IO_PENDING); +Value* NetLogGetAvailableRangeResultCallback( + int64 start, + int result, + net::NetLog::LogLevel /* log_level */) { DictionaryValue* dict = new DictionaryValue(); - if (bytes_copied_ < 0) { - dict->SetInteger("net_error", bytes_copied_); + if (result > 0) { + dict->SetInteger("length", result); + dict->SetString("start", base::Int64ToString(start)); } else { - dict->SetInteger("bytes_copied", bytes_copied_); + dict->SetInteger("net_error", result); } return dict; } -ReadWriteCompleteParameters::~ReadWriteCompleteParameters() {} +} // namespace -SparseOperationParameters::SparseOperationParameters( - int64 offset, - int buff_len) - : offset_(offset), - buff_len_(buff_len) { -} +namespace disk_cache { -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; +net::NetLog::ParametersCallback CreateNetLogEntryCreationCallback( + const Entry* entry, + bool created) { + DCHECK(entry); + return base::Bind(&NetLogEntryCreationCallback, entry, created); } -SparseOperationParameters::~SparseOperationParameters() {} - -SparseReadWriteParameters::SparseReadWriteParameters( - const net::NetLog::Source& source, - int child_len) - : source_(source), - child_len_(child_len) { +net::NetLog::ParametersCallback CreateNetLogReadWriteDataCallback( + int index, + int offset, + int buf_len, + bool truncate) { + return base::Bind(&NetLogReadWriteDataCallback, + index, offset, buf_len, truncate); } -Value* SparseReadWriteParameters::ToValue() const { - DictionaryValue* dict = new DictionaryValue(); - dict->Set("source_dependency", source_.ToValue()); - dict->SetInteger("child_len", child_len_); - return dict; +net::NetLog::ParametersCallback CreateNetLogReadWriteCompleteCallback( + int bytes_copied) { + return base::Bind(&NetLogReadWriteCompleteCallback, bytes_copied); } -SparseReadWriteParameters::~SparseReadWriteParameters() {} - -GetAvailableRangeResultParameters::GetAvailableRangeResultParameters( - int64 start, - int result) - : start_(start), - result_(result) { +net::NetLog::ParametersCallback CreateNetLogSparseOperationCallback( + int64 offset, + int buff_len) { + return base::Bind(&NetLogSparseOperationCallback, offset, buff_len); } -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; +net::NetLog::ParametersCallback CreateNetLogSparseReadWriteCallback( + const net::NetLog::Source& source, + int child_len) { + return base::Bind(&NetLogSparseReadWriteCallback, source, child_len); } -GetAvailableRangeResultParameters::~GetAvailableRangeResultParameters() {} +net::NetLog::ParametersCallback CreateNetLogGetAvailableRangeResultCallback( + int64 start, + int result) { + return base::Bind(&NetLogGetAvailableRangeResultCallback, start, result); +} } // namespace disk_cache diff --git a/net/disk_cache/net_log_parameters.h b/net/disk_cache/net_log_parameters.h index 4e6b8fe..4e34a0e 100644 --- a/net/disk_cache/net_log_parameters.h +++ b/net/disk_cache/net_log_parameters.h @@ -10,107 +10,53 @@ #include "net/base/net_log.h" -// This file contains a set of NetLog::EventParameters shared by EntryImpls and -// MemEntryImpls. +// This file contains a set of functions to create NetLog::ParametersCallbacks +// 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~EntryCreationParameters(); - - 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~ReadWriteDataParameters(); - - 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~ReadWriteCompleteParameters(); - - 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~SparseOperationParameters(); - - 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~SparseReadWriteParameters(); - - 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 base::Value* ToValue() const OVERRIDE; - - protected: - virtual ~GetAvailableRangeResultParameters(); - - private: - const int64 start_; - const int result_; -}; +class Entry; + +// Creates a NetLog callback that returns parameters for the creation of an +// Entry. Contains the Entry's key and whether it was created or opened. +// |entry| can't be NULL, must support GetKey(), and must outlive the returned +// callback. +net::NetLog::ParametersCallback CreateNetLogEntryCreationCallback( + const Entry* entry, + bool created); + +// Creates a NetLog callback that returns parameters for start of a non-sparse +// read or write of an Entry. For reads, |truncate| must be false. +net::NetLog::ParametersCallback CreateNetLogReadWriteDataCallback( + int index, + int offset, + int buf_len, + bool truncate); + +// Creates a NetLog callback that returns parameters for when a non-sparse +// read or write completes. For reads, |truncate| must be false. +// |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. +net::NetLog::ParametersCallback CreateNetLogReadWriteCompleteCallback( + int bytes_copied); + +// Creates a NetLog callback that returns parameters for when a sparse +// operation is started. +net::NetLog::ParametersCallback CreateNetLogSparseOperationCallback( + int64 offset, + int buff_len); + +// Creates a NetLog callback that returns parameters for when a read or write +// for a sparse entry's child is started. +net::NetLog::ParametersCallback CreateNetLogSparseReadWriteCallback( + const net::NetLog::Source& source, + int child_len); + +// Creates a NetLog callback that returns parameters for when a call to +// GetAvailableRange returns. +net::NetLog::ParametersCallback CreateNetLogGetAvailableRangeResultCallback( + int64 start, + int result); } // namespace disk_cache diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc index 4ce0f48..d19b10e 100644 --- a/net/disk_cache/sparse_control.cc +++ b/net/disk_cache/sparse_control.cc @@ -265,7 +265,7 @@ int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf, if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().BeginEvent( GetSparseEventType(operation_), - make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_))); + CreateNetLogSparseOperationCallback(offset_, buf_len_)); } DoChildrenIO(); @@ -337,7 +337,7 @@ void SparseControl::DeleteChildren(EntryImpl* entry) { if (!buffer && !address.is_initialized()) return; - entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL); + entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN); DCHECK(entry && entry->backend_); ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, @@ -674,13 +674,12 @@ void SparseControl::DoChildrenIO() { entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().EndEvent( net::NetLog::TYPE_SPARSE_GET_RANGE, - make_scoped_refptr( - new GetAvailableRangeResultParameters(offset_, result_))); + CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); } if (finished_) { if (kGetRangeOperation != operation_ && entry_->net_log().IsLoggingAllEvents()) { - entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); + entry_->net_log().EndEvent(GetSparseEventType(operation_)); } if (pending_) DoUserCallback(); // Don't touch this object after this point. @@ -712,9 +711,8 @@ bool SparseControl::DoChildIO() { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, - make_scoped_refptr(new SparseReadWriteParameters( - child_->net_log().source(), - child_len_))); + CreateNetLogSparseReadWriteCallback(child_->net_log().source(), + child_len_)); } rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, child_len_, callback); @@ -723,9 +721,8 @@ bool SparseControl::DoChildIO() { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().BeginEvent( net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, - make_scoped_refptr(new SparseReadWriteParameters( - child_->net_log().source(), - child_len_))); + CreateNetLogSparseReadWriteCallback(child_->net_log().source(), + child_len_)); } rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, child_len_, callback, false); @@ -830,8 +827,8 @@ void SparseControl::OnChildIOCompleted(int result) { // the bytes to read or write, but the user cancelled the operation. abort_ = false; if (entry_->net_log().IsLoggingAllEvents()) { - entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); - entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); + entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); + entry_->net_log().EndEvent(GetSparseEventType(operation_)); } // We have an indirect reference to this object for every callback so if // there is only one callback, we may delete this object before reaching |