Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3159)

Unified Diff: net/disk_cache/entry_impl.cc

Issue 4067002: First pass at adding http/backend cache to NetLog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Minor cleanup Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/entry_impl.cc
===================================================================
--- net/disk_cache/entry_impl.cc (revision 68857)
+++ net/disk_cache/entry_impl.cc (working copy)
@@ -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,62 @@
// 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();
eroman 2011/01/05 02:39:06 nit: DictionaryValue*
mmenke 2011/01/05 16:32:25 DOn 2011/01/05 02:39:06, eroman wrote:
+ dict->SetString("key", key_);
+ dict->SetBoolean("created", created_);
+ return dict;
+ }
+
+ private:
+ const std::string key_;
+ const bool created_;
+};
+
+// NetLog parameters for both 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:
+ int index_;
eroman 2011/01/05 02:39:06 nit: can you make these all const ?
mmenke 2011/01/05 16:32:25 Done.
+ int offset_;
+ int buf_len_;
+ bool truncate_;
+};
+
// 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 +88,13 @@
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 +102,8 @@
void SyncCallback::OnFileIOComplete(int bytes_copied) {
entry_->DecrementIoCount();
if (callback_) {
+ if (entry_->net_log().IsLoggingAllEvents())
+ entry_->net_log().EndEventWithErrorCode(end_event_type_, bytes_copied);
eroman 2011/01/05 02:39:06 Would we want to log the actual bytes copied on no
mmenke 2011/01/05 16:32:25 You do, indeed, understand the code. With writes,
entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
callback_->Run(bytes_copied);
}
@@ -308,6 +361,7 @@
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 +387,7 @@
}
Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
+ net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY, NULL);
backend_->OnEntryDestroyEnd();
}
@@ -487,6 +542,44 @@
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_.EndEventWithErrorCode(net::NetLog::TYPE_DISK_CACHE_READ_DATA,
+ 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_.EndEventWithErrorCode(net::NetLog::TYPE_DISK_CACHE_WRITE_DATA,
+ 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 +629,10 @@
}
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 +648,9 @@
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 +723,10 @@
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 +854,7 @@
}
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 +1012,19 @@
}
}
+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 {
eroman 2011/01/05 02:39:06 Is it possible for this to be called before BeginL
mmenke 2011/01/05 16:32:25 No, I don't believe it's possible. The only two f
+ return net_log_;
+}
+
// ------------------------------------------------------------------------
bool EntryImpl::CreateDataBlock(int index, int size) {

Powered by Google App Engine
This is Rietveld 408576698