Skip to content

Commit

Permalink
NetLogEventParameter to Callback refactoring 2.
Browse files Browse the repository at this point in the history
Get rid of all uses of NetLogEventParameters in net/disk_cache.

R=eroman@chromium.org
BUG=126243

Review URL: https://chromiumcodereview.appspot.com/10543114

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141697 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mmenke@chromium.org committed Jun 12, 2012
1 parent 750f7d2 commit 8cab8a8
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 236 deletions.
21 changes: 9 additions & 12 deletions net/disk_cache/entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -314,16 +313,15 @@ 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);

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;
}
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
}

Expand Down
73 changes: 40 additions & 33 deletions net/disk_cache/mem_entry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -171,16 +187,15 @@ 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);

if (net_log_.IsLoggingAllEvents()) {
net_log_.EndEvent(
net::NetLog::TYPE_ENTRY_READ_DATA,
make_scoped_refptr(new ReadWriteCompleteParameters(result)));
CreateNetLogReadWriteCompleteCallback(result));
}
return result;
}
Expand All @@ -190,16 +205,15 @@ 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);

if (net_log_.IsLoggingAllEvents()) {
net_log_.EndEvent(
net::NetLog::TYPE_ENTRY_WRITE_DATA,
make_scoped_refptr(new ReadWriteCompleteParameters(result)));
CreateNetLogReadWriteCompleteCallback(result));
}
return result;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 8cab8a8

Please sign in to comment.