diff options
author | ahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-05 06:46:26 +0000 |
---|---|---|
committer | ahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-05 06:46:26 +0000 |
commit | ac5e81005177ac0118b6f289f91e7919a642bc29 (patch) | |
tree | 3a08199af7aff8be0c27eaef04ae52c29a88024c | |
parent | ef5672efb64bbfa3e942a43ef9784f580313b062 (diff) | |
download | chromium_src-ac5e81005177ac0118b6f289f91e7919a642bc29.zip chromium_src-ac5e81005177ac0118b6f289f91e7919a642bc29.tar.gz chromium_src-ac5e81005177ac0118b6f289f91e7919a642bc29.tar.bz2 |
Added net logging to BaseFile.
This enables net logging for BaseFile if any customer of BaseFile choose to take advantage of it -- none yet do.
This is the second of 4 CLs that will enable net logging for downloads.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/9223019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120510 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/net/passive_log_collector.cc | 39 | ||||
-rw-r--r-- | chrome/browser/net/passive_log_collector.h | 16 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/events_view.css | 4 | ||||
-rw-r--r-- | chrome/browser/resources/net_internals/source_entry.js | 35 | ||||
-rw-r--r-- | content/browser/download/base_file.cc | 93 | ||||
-rw-r--r-- | content/browser/download/base_file.h | 10 | ||||
-rw-r--r-- | content/browser/download/base_file_unittest.cc | 51 | ||||
-rw-r--r-- | content/browser/download/download_file_impl.cc | 21 | ||||
-rw-r--r-- | content/browser/download/download_net_log_parameters.cc | 58 | ||||
-rw-r--r-- | content/browser/download/download_net_log_parameters.h | 59 | ||||
-rw-r--r-- | content/browser/download/save_file.cc | 5 | ||||
-rw-r--r-- | content/content_browser.gypi | 2 | ||||
-rw-r--r-- | net/base/net_log_event_type_list.h | 49 | ||||
-rw-r--r-- | net/base/net_log_source_type_list.h | 5 |
14 files changed, 389 insertions, 58 deletions
diff --git a/chrome/browser/net/passive_log_collector.cc b/chrome/browser/net/passive_log_collector.cc index 5006bdb..641e11a 100644 --- a/chrome/browser/net/passive_log_collector.cc +++ b/chrome/browser/net/passive_log_collector.cc @@ -87,6 +87,8 @@ PassiveLogCollector::PassiveLogCollector() &cert_verifier_job_tracker_; trackers_[net::NetLog::SOURCE_HTTP_PIPELINED_CONNECTION] = &http_pipelined_connection_tracker_; + trackers_[net::NetLog::SOURCE_DOWNLOAD] = + &download_tracker_; trackers_[net::NetLog::SOURCE_FILESTREAM] = &file_stream_tracker_; // Make sure our mapping is up-to-date. @@ -848,18 +850,41 @@ PassiveLogCollector::HttpPipelinedConnectionTracker::DoAddEntry( } //---------------------------------------------------------------------------- +// DownloadTracker +//---------------------------------------------------------------------------- + +const size_t PassiveLogCollector::DownloadTracker::kMaxNumSources = 200; + +const size_t PassiveLogCollector::DownloadTracker::kMaxGraveyardSize = 50; + +PassiveLogCollector::DownloadTracker::DownloadTracker() + : SourceTracker(kMaxNumSources, kMaxGraveyardSize, NULL) { +} + +PassiveLogCollector::SourceTracker::Action +PassiveLogCollector::DownloadTracker::DoAddEntry( + const ChromeNetLog::Entry& entry, + SourceInfo* out_info) { + if (entry.type == net::NetLog::TYPE_DOWNLOAD_FILE_WRITTEN) + return ACTION_NONE; // Don't passively log these (too many). + AddEntryToSourceInfo(entry, out_info); + if (entry.type == net::NetLog::TYPE_DOWNLOAD_FILE_OPENED && + entry.phase == net::NetLog::PHASE_END) { + return ACTION_MOVE_TO_GRAVEYARD; + } + return ACTION_NONE; +} + +//---------------------------------------------------------------------------- // FileStreamTracker //---------------------------------------------------------------------------- -const size_t -PassiveLogCollector::FileStreamTracker::kMaxNumSources = 100; +const size_t PassiveLogCollector::FileStreamTracker::kMaxNumSources = 100; -const size_t -PassiveLogCollector::FileStreamTracker::kMaxGraveyardSize = 25; +const size_t PassiveLogCollector::FileStreamTracker::kMaxGraveyardSize = 25; -PassiveLogCollector:: - FileStreamTracker::FileStreamTracker() - : SourceTracker(kMaxNumSources, kMaxGraveyardSize, NULL) { +PassiveLogCollector::FileStreamTracker::FileStreamTracker() + : SourceTracker(kMaxNumSources, kMaxGraveyardSize, NULL) { } PassiveLogCollector::SourceTracker::Action diff --git a/chrome/browser/net/passive_log_collector.h b/chrome/browser/net/passive_log_collector.h index c3b8da5..701c5c3 100644 --- a/chrome/browser/net/passive_log_collector.h +++ b/chrome/browser/net/passive_log_collector.h @@ -446,6 +446,21 @@ class PassiveLogCollector : public ChromeNetLog::ThreadSafeObserverImpl { DISALLOW_COPY_AND_ASSIGN(HttpPipelinedConnectionTracker); }; + // Tracks the log entries for the last seen SOURCE_DOWNLOAD. + class DownloadTracker : public SourceTracker { + public: + static const size_t kMaxNumSources; + static const size_t kMaxGraveyardSize; + + DownloadTracker(); + + private: + virtual Action DoAddEntry(const ChromeNetLog::Entry& entry, + SourceInfo* out_info) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(DownloadTracker); + }; + // Tracks the log entries for the last seen SOURCE_FILESTREAM. class FileStreamTracker : public SourceTracker { public: @@ -507,6 +522,7 @@ class PassiveLogCollector : public ChromeNetLog::ThreadSafeObserverImpl { UDPSocketTracker udp_socket_tracker_; CertVerifierJobTracker cert_verifier_job_tracker_; HttpPipelinedConnectionTracker http_pipelined_connection_tracker_; + DownloadTracker download_tracker_; FileStreamTracker file_stream_tracker_; // This array maps each NetLog::SourceType to one of the tracker instances diff --git a/chrome/browser/resources/net_internals/events_view.css b/chrome/browser/resources/net_internals/events_view.css index 58c32ea..4047a82 100644 --- a/chrome/browser/resources/net_internals/events_view.css +++ b/chrome/browser/resources/net_internals/events_view.css @@ -97,6 +97,10 @@ color: green; } +#events-view-source-list-tbody .source_DOWNLOAD { + color: #707000; +} + #events-view-source-list-tbody .source_FILESTREAM { color: #700070; } diff --git a/chrome/browser/resources/net_internals/source_entry.js b/chrome/browser/resources/net_internals/source_entry.js index c24f27b..d1f4214 100644 --- a/chrome/browser/resources/net_internals/source_entry.js +++ b/chrome/browser/resources/net_internals/source_entry.js @@ -132,6 +132,16 @@ var SourceEntry = (function() { case LogSourceType.DNS_TRANSACTION: this.description_ = e.params.hostname; break; + case LogSourceType.DOWNLOAD: + switch (e.type) { + case LogEventType.DOWNLOAD_FILE_RENAMED: + this.description_ = e.params.new_filename; + break; + case LogEventType.DOWNLOAD_FILE_OPENED: + this.description_ = e.params.file_name; + break; + } + break; case LogSourceType.FILESTREAM: this.description_ = e.params.file_name; break; @@ -164,6 +174,17 @@ var SourceEntry = (function() { if (e != undefined) return e; } + if (this.entries_[0].source.type == LogSourceType.DOWNLOAD) { + // If any rename occurred, use the last name + e = this.findLastLogEntryStartByType_( + LogEventType.DOWNLOAD_FILE_RENAMED); + if (e != undefined) + return e; + // Otherwise, if the file was opened, use that name + e = this.findLogEntryByType_(LogEventType.DOWNLOAD_FILE_OPENED); + if (e != undefined) + return e; + } if (this.entries_.length >= 2) { if (this.entries_[0].type == LogEventType.REQUEST_ALIVE || this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB || @@ -187,6 +208,20 @@ var SourceEntry = (function() { return undefined; }, + /** + * Returns the last entry with the specified type, or undefined if not + * found. + */ + findLastLogEntryStartByType_: function(type) { + for (var i = this.entries_.length - 1; i >= 0; --i) { + if (this.entries_[i].type == type) { + if (this.entries_[i].phase == LogEventPhase.PHASE_BEGIN) + return this.entries_[i]; + } + } + return undefined; + }, + getLogEntries: function() { return this.entries_; }, diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc index a9da47f..74e9b95 100644 --- a/content/browser/download/base_file.cc +++ b/content/browser/download/base_file.cc @@ -11,6 +11,7 @@ #include "base/stringprintf.h" #include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" +#include "content/browser/download/download_net_log_parameters.h" #include "content/browser/download/download_stats.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" @@ -31,12 +32,17 @@ using content::BrowserThread; namespace { -#define LOG_ERROR(o, e) LogError(__FILE__, __LINE__, __FUNCTION__, o, e) +#define LOG_ERROR(o, e) \ + LogError(__FILE__, __LINE__, __FUNCTION__, bound_net_log_, o, e) // Logs the value and passes error on through, converting to a |net::Error|. // Returns |ERR_UNEXPECTED| if the value is not in the enum. -net::Error LogError(const char* file, int line, const char* func, - const char* operation, int error) { +net::Error LogError(const char* file, + int line, + const char* func, + const net::BoundNetLog& bound_net_log, + const char* operation, + int error) { const char* err_string = ""; net::Error net_error = net::OK; @@ -63,6 +69,11 @@ net::Error LogError(const char* file, int line, const char* func, VLOG(1) << " " << func << "(): " << operation << "() returned error " << error << " (" << err_string << ")"; + bound_net_log.AddEvent( + net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, + make_scoped_refptr( + new download_net_logs::FileErrorParameters(operation, net_error))); + return net_error; } @@ -196,7 +207,8 @@ BaseFile::BaseFile(const FilePath& full_path, int64 received_bytes, bool calculate_hash, const std::string& hash_state, - const linked_ptr<net::FileStream>& file_stream) + const linked_ptr<net::FileStream>& file_stream, + const net::BoundNetLog& bound_net_log) : full_path_(full_path), source_url_(source_url), referrer_url_(referrer_url), @@ -205,11 +217,14 @@ BaseFile::BaseFile(const FilePath& full_path, start_tick_(base::TimeTicks::Now()), power_save_blocker_(PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep), calculate_hash_(calculate_hash), - detached_(false) { + detached_(false), + bound_net_log_(bound_net_log) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); memcpy(sha256_hash_, kEmptySha256Hash, kSha256HashLen); - if (file_stream_.get()) + if (file_stream_.get()) { + file_stream_->SetBoundNetLogSource(bound_net_log_); file_stream_->EnableErrorStatistics(); + } if (calculate_hash_) { secure_hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); @@ -253,9 +268,17 @@ net::Error BaseFile::AppendDataToFile(const char* data, size_t data_len) { // NOTE(benwells): The above DCHECK won't be present in release builds, // so we log any occurences to see how common this error is in the wild. - if (detached_) + if (detached_) { download_stats::RecordDownloadCount( download_stats::APPEND_TO_DETACHED_FILE_COUNT); + } + + if (bound_net_log_.IsLoggingAllEvents()) { + bound_net_log_.AddEvent( + net::NetLog::TYPE_DOWNLOAD_FILE_WRITTEN, + make_scoped_refptr(new net::NetLogIntegerParameter( + "byte_count", data_len))); + } if (!file_stream_.get()) return LOG_ERROR("get", net::ERR_INVALID_HANDLE); @@ -292,9 +315,8 @@ net::Error BaseFile::AppendDataToFile(const char* data, size_t data_len) { bytes_so_far_ += write_size; } - // TODO(ahendrickson) -- Uncomment these when the functions are available. - download_stats::RecordDownloadWriteSize(data_len); - download_stats::RecordDownloadWriteLoopCount(write_count); + download_stats::RecordDownloadWriteSize(data_len); + download_stats::RecordDownloadWriteLoopCount(write_count); if (calculate_hash_) secure_hash_->Update(data, data_len); @@ -309,6 +331,12 @@ net::Error BaseFile::Rename(const FilePath& new_path) { // it will be overwritten by closing the file. bool saved_in_progress = in_progress(); + bound_net_log_.AddEvent( + net::NetLog::TYPE_DOWNLOAD_FILE_RENAMED, + make_scoped_refptr( + new download_net_logs::FileRenamedParameters( + full_path_.AsUTF8Unsafe(), new_path.AsUTF8Unsafe()))); + // If the new path is same as the old one, there is no need to perform the // following renaming logic. if (new_path == full_path_) { @@ -376,16 +404,22 @@ net::Error BaseFile::Rename(const FilePath& new_path) { void BaseFile::Detach() { detached_ = true; + bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DETACHED, NULL); } void BaseFile::Cancel() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(!detached_); + bound_net_log_.AddEvent(net::NetLog::TYPE_CANCELLED, NULL); + Close(); - if (!full_path_.empty()) + if (!full_path_.empty()) { + bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_DELETED, NULL); + file_util::Delete(full_path_, false); + } } void BaseFile::Finish() { @@ -449,7 +483,8 @@ void BaseFile::AnnotateWithSourceInformation() { } void BaseFile::CreateFileStream() { - file_stream_.reset(new net::FileStream(NULL)); + file_stream_.reset(new net::FileStream(bound_net_log_.net_log())); + file_stream_->SetBoundNetLogSource(bound_net_log_); } net::Error BaseFile::Open() { @@ -457,6 +492,12 @@ net::Error BaseFile::Open() { DCHECK(!detached_); DCHECK(!full_path_.empty()); + bound_net_log_.BeginEvent( + net::NetLog::TYPE_DOWNLOAD_FILE_OPENED, + make_scoped_refptr( + new download_net_logs::FileOpenedParameters( + full_path_.AsUTF8Unsafe(), bytes_so_far_))); + // Create a new file stream if it is not provided. if (!file_stream_.get()) { CreateFileStream(); @@ -464,28 +505,30 @@ net::Error BaseFile::Open() { int open_result = file_stream_->Open( full_path_, base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE); - if (open_result != net::OK) { - file_stream_.reset(); - return LOG_ERROR("Open", open_result); - } + if (open_result != net::OK) + return ClearStream(LOG_ERROR("Open", open_result)); // We may be re-opening the file after rename. Always make sure we're // writing at the end of the file. int64 seek_result = file_stream_->Seek(net::FROM_END, 0); - if (seek_result < 0) { - file_stream_.reset(); - return LOG_ERROR("Seek", seek_result); - } + if (seek_result < 0) + return ClearStream(LOG_ERROR("Seek", seek_result)); + } else { + file_stream_->SetBoundNetLogSource(bound_net_log_); } #if defined(OS_WIN) AnnotateWithSourceInformation(); #endif + return net::OK; } void BaseFile::Close() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + + bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_FILE_CLOSED, NULL); + if (file_stream_.get()) { #if defined(OS_CHROMEOS) // Currently we don't really care about the return value, since if it fails @@ -493,10 +536,18 @@ void BaseFile::Close() { file_stream_->Flush(); #endif file_stream_->Close(); - file_stream_.reset(); + ClearStream(net::OK); } } +net::Error BaseFile::ClearStream(net::Error net_error) { + // This should only be called when we have a stream. + DCHECK(file_stream_.get() != NULL); + file_stream_.reset(); + bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED, NULL); + return net_error; +} + std::string BaseFile::DebugString() const { return base::StringPrintf("{ source_url_ = \"%s\"" " full_path_ = \"%" PRFilePath "\"" diff --git a/content/browser/download/base_file.h b/content/browser/download/base_file.h index 702bdbc..00a83e6 100644 --- a/content/browser/download/base_file.h +++ b/content/browser/download/base_file.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -18,6 +18,7 @@ #include "googleurl/src/gurl.h" #include "net/base/file_stream.h" #include "net/base/net_errors.h" +#include "net/base/net_log.h" namespace crypto { class SecureHash; @@ -36,7 +37,8 @@ class CONTENT_EXPORT BaseFile { int64 received_bytes, bool calculate_hash, const std::string& hash_state, - const linked_ptr<net::FileStream>& file_stream); + const linked_ptr<net::FileStream>& file_stream, + const net::BoundNetLog& bound_net_log); virtual ~BaseFile(); // Returns net::OK on success, or a network error code on failure. @@ -103,6 +105,8 @@ class CONTENT_EXPORT BaseFile { // Resets the current state of the hash to the contents of |hash_state_bytes|. virtual bool SetHashState(const std::string& hash_state_bytes); + net::Error ClearStream(net::Error error); + static const size_t kSha256HashLen = 32; static const unsigned char kEmptySha256Hash[kSha256HashLen]; @@ -137,6 +141,8 @@ class CONTENT_EXPORT BaseFile { // won't delete it on destruction. bool detached_; + net::BoundNetLog bound_net_log_; + DISALLOW_COPY_AND_ASSIGN(BaseFile); }; diff --git a/content/browser/download/base_file_unittest.cc b/content/browser/download/base_file_unittest.cc index 646ef00..2ed3b9d 100644 --- a/content/browser/download/base_file_unittest.cc +++ b/content/browser/download/base_file_unittest.cc @@ -51,8 +51,14 @@ class BaseFileTest : public testing::Test { virtual void SetUp() { ResetHash(); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - base_file_.reset( - new BaseFile(FilePath(), GURL(), GURL(), 0, false, "", file_stream_)); + base_file_.reset(new BaseFile(FilePath(), + GURL(), + GURL(), + 0, + false, + "", + file_stream_, + net::BoundNetLog())); } virtual void TearDown() { @@ -96,8 +102,14 @@ class BaseFileTest : public testing::Test { } void MakeFileWithHash() { - base_file_.reset( - new BaseFile(FilePath(), GURL(), GURL(), 0, true, "", file_stream_)); + base_file_.reset(new BaseFile(FilePath(), + GURL(), + GURL(), + 0, + true, + "", + file_stream_, + net::BoundNetLog())); } bool OpenMockFileStream() { @@ -148,7 +160,14 @@ class BaseFileTest : public testing::Test { static FilePath CreateTestFile() { FilePath file_name; linked_ptr<net::FileStream> dummy_file_stream; - BaseFile file(FilePath(), GURL(), GURL(), 0, false, "", dummy_file_stream); + BaseFile file(FilePath(), + GURL(), + GURL(), + 0, + false, + "", + dummy_file_stream, + net::BoundNetLog()); EXPECT_EQ(net::OK, file.Initialize()); file_name = file.full_path(); @@ -166,8 +185,14 @@ class BaseFileTest : public testing::Test { static void CreateFileWithName(const FilePath& file_name) { EXPECT_NE(FilePath::StringType(), file_name.value()); linked_ptr<net::FileStream> dummy_file_stream; - BaseFile duplicate_file( - file_name, GURL(), GURL(), 0, false, "", dummy_file_stream); + BaseFile duplicate_file(file_name, + GURL(), + GURL(), + 0, + false, + "", + dummy_file_stream, + net::BoundNetLog()); EXPECT_EQ(net::OK, duplicate_file.Initialize()); // Write something into it. duplicate_file.AppendDataToFile(kTestData4, kTestDataLength4); @@ -387,7 +412,8 @@ TEST_F(BaseFileTest, MultipleWritesInterruptedWithHash) { base_file_->bytes_so_far(), true, hash_state, - second_stream); + second_stream, + net::BoundNetLog()); ASSERT_EQ(net::OK, second_file.Initialize()); std::string data(kTestData3); EXPECT_EQ(net::OK, second_file.AppendDataToFile(data.data(), data.size())); @@ -448,7 +474,8 @@ TEST_F(BaseFileTest, MultipleWritesWithError) { 0, false, "", - mock_file_stream_)); + mock_file_stream_, + net::BoundNetLog())); EXPECT_EQ(net::OK, base_file_->Initialize()); ASSERT_EQ(net::OK, AppendDataToFile(kTestData1)); ASSERT_EQ(net::OK, AppendDataToFile(kTestData2)); @@ -492,7 +519,8 @@ TEST_F(BaseFileTest, AppendToBaseFile) { kTestDataLength4, false, "", - file_stream_)); + file_stream_, + net::BoundNetLog())); EXPECT_EQ(net::OK, base_file_->Initialize()); @@ -522,7 +550,8 @@ TEST_F(BaseFileTest, ReadonlyBaseFile) { 0, false, "", - file_stream_)); + file_stream_, + net::BoundNetLog())); expect_in_progress_ = false; diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc index 8c4155df..40ba759 100644 --- a/content/browser/download/download_file_impl.cc +++ b/content/browser/download/download_file_impl.cc @@ -20,16 +20,17 @@ DownloadFileImpl::DownloadFileImpl( DownloadRequestHandleInterface* request_handle, DownloadManager* download_manager, bool calculate_hash) - : file_(info->save_info.file_path, - info->url(), - info->referrer_url, - info->received_bytes, - calculate_hash, - info->save_info.hash_state, - info->save_info.file_stream), - id_(info->download_id), - request_handle_(request_handle), - download_manager_(download_manager) { + : file_(info->save_info.file_path, + info->url(), + info->referrer_url, + info->received_bytes, + calculate_hash, + info->save_info.hash_state, + info->save_info.file_stream, + net::BoundNetLog()), + id_(info->download_id), + request_handle_(request_handle), + download_manager_(download_manager) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); } diff --git a/content/browser/download/download_net_log_parameters.cc b/content/browser/download/download_net_log_parameters.cc new file mode 100644 index 0000000..33a17f6 --- /dev/null +++ b/content/browser/download/download_net_log_parameters.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2012 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 "content/browser/download/download_net_log_parameters.h" + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/string_number_conversions.h" +#include "base/values.h" +#include "content/browser/download/interrupt_reasons.h" +#include "net/base/net_errors.h" + +namespace download_net_logs { + +FileOpenedParameters::FileOpenedParameters(const std::string& file_name, + int64 start_offset) + : file_name_(file_name), start_offset_(start_offset) { +} + +Value* FileOpenedParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + + dict->SetString("file_name", file_name_); + dict->SetString("start_offset", base::Int64ToString(start_offset_)); + + return dict; +} + +FileRenamedParameters::FileRenamedParameters( + const std::string& old_filename, const std::string& new_filename) + : old_filename_(old_filename), new_filename_(new_filename) { +} + +Value* FileRenamedParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + + dict->SetString("old_filename", old_filename_); + dict->SetString("new_filename", new_filename_); + + return dict; +} + +FileErrorParameters::FileErrorParameters(const std::string& operation, + net::Error net_error) + : operation_(operation), net_error_(net_error) { +} + +Value* FileErrorParameters::ToValue() const { + DictionaryValue* dict = new DictionaryValue(); + + dict->SetString("operation", operation_); + dict->SetInteger("net_error", net_error_); + + return dict; +} + +} // namespace download_net_logs diff --git a/content/browser/download/download_net_log_parameters.h b/content/browser/download/download_net_log_parameters.h new file mode 100644 index 0000000..031cea0 --- /dev/null +++ b/content/browser/download/download_net_log_parameters.h @@ -0,0 +1,59 @@ +// Copyright (c) 2012 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 CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_NET_LOG_PARAMETERS_H_ +#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_NET_LOG_PARAMETERS_H_ +#pragma once + +#include <string> + +#include "net/base/net_errors.h" +#include "net/base/net_log.h" + +namespace download_net_logs { + +// NetLog parameters when a DownloadFile is opened. +class FileOpenedParameters : public net::NetLog::EventParameters { + public: + FileOpenedParameters(const std::string& file_name, + int64 start_offset); + virtual base::Value* ToValue() const OVERRIDE; + + private: + const std::string file_name_; + const int64 start_offset_; + + DISALLOW_COPY_AND_ASSIGN(FileOpenedParameters); +}; + +// NetLog parameters when a DownloadFile is renamed. +class FileRenamedParameters : public net::NetLog::EventParameters { + public: + FileRenamedParameters( + const std::string& old_filename, const std::string& new_filename); + virtual base::Value* ToValue() const OVERRIDE; + + private: + const std::string old_filename_; + const std::string new_filename_; + + DISALLOW_COPY_AND_ASSIGN(FileRenamedParameters); +}; + +// NetLog parameters when a File has an error. +class FileErrorParameters : public net::NetLog::EventParameters { + public: + FileErrorParameters(const std::string& operation, net::Error net_error); + virtual base::Value* ToValue() const OVERRIDE; + + private: + const std::string operation_; + const net::Error net_error_; + + DISALLOW_COPY_AND_ASSIGN(FileErrorParameters); +}; + +} // namespace download_net_logs + +#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_NET_LOG_PARAMETERS_H_ diff --git a/content/browser/download/save_file.cc b/content/browser/download/save_file.cc index d15aaa1..b4474d1 100644 --- a/content/browser/download/save_file.cc +++ b/content/browser/download/save_file.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,7 +17,8 @@ SaveFile::SaveFile(const SaveFileCreateInfo* info, bool calculate_hash) 0, calculate_hash, "", - linked_ptr<net::FileStream>()), + linked_ptr<net::FileStream>(), + net::BoundNetLog()), info_(info) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 91cb040..c3ec694 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -205,6 +205,8 @@ 'browser/download/download_item_impl.h', 'browser/download/download_manager_impl.cc', 'browser/download/download_manager_impl.h', + 'browser/download/download_net_log_parameters.cc', + 'browser/download/download_net_log_parameters.h', 'browser/download/download_persistent_store_info.cc', 'browser/download/download_persistent_store_info.h', 'browser/download/download_request_handle.cc', diff --git a/net/base/net_log_event_type_list.h b/net/base/net_log_event_type_list.h index a53635f..0bba60f 100644 --- a/net/base/net_log_event_type_list.h +++ b/net/base/net_log_event_type_list.h @@ -1451,6 +1451,49 @@ EVENT_TYPE(HTTP_PIPELINED_CONNECTION_RECEIVED_HEADERS) EVENT_TYPE(HTTP_PIPELINED_CONNECTION_STREAM_CLOSED) // ------------------------------------------------------------------------ +// DownloadFile events. +// ------------------------------------------------------------------------ + +// This event is created when a download file is opened, and lasts until +// the file is closed. +// The BEGIN event has the following parameters: +// { +// "file_name": <The name of the file>, +// "start_offset": <The position at which to start writing>, +// } +EVENT_TYPE(DOWNLOAD_FILE_OPENED) + +// This event is created when a download file is written to. +// { +// "byte_count": <Number of bytes written in this call>, +// } +EVENT_TYPE(DOWNLOAD_FILE_WRITTEN) + +// This event is created when a download file is renamed. +// { +// "old_filename": <Old filename>, +// "new_filename": <New filename>, +// } +EVENT_TYPE(DOWNLOAD_FILE_RENAMED) + +// This event is created when a download file is closed. This event is allowed +// to occur even if the file is not open. +EVENT_TYPE(DOWNLOAD_FILE_CLOSED) + +// This event is created when a download file is detached. +EVENT_TYPE(DOWNLOAD_FILE_DETACHED) + +// This event is created when a download file is deleted. +EVENT_TYPE(DOWNLOAD_FILE_DELETED) + +// This event is created when a download file operation has an error. +// { +// "operation": <open, write, close, etc>, +// "net_error": <net::Error code>, +// } +EVENT_TYPE(DOWNLOAD_FILE_ERROR) + +// ------------------------------------------------------------------------ // FileStream events. // ------------------------------------------------------------------------ @@ -1484,8 +1527,8 @@ EVENT_TYPE(FILE_STREAM_CLOSE) // This event is created when a file stream operation has an error. // { -// "operation": open, write, close, etc. -// "os_error": OS-dependent error code. -// "net_error": net::Error code. +// "operation": <open, write, close, etc>, +// "os_error": <OS-dependent error code>, +// "net_error": <net::Error code>, // } EVENT_TYPE(FILE_STREAM_ERROR) diff --git a/net/base/net_log_source_type_list.h b/net/base/net_log_source_type_list.h index e879485..233f3a2 100644 --- a/net/base/net_log_source_type_list.h +++ b/net/base/net_log_source_type_list.h @@ -26,7 +26,8 @@ SOURCE_TYPE(ASYNC_HOST_RESOLVER_REQUEST, 15) SOURCE_TYPE(UDP_SOCKET, 16) SOURCE_TYPE(CERT_VERIFIER_JOB, 17) SOURCE_TYPE(HTTP_PIPELINED_CONNECTION, 18) -SOURCE_TYPE(FILESTREAM, 19) +SOURCE_TYPE(DOWNLOAD, 19) +SOURCE_TYPE(FILESTREAM, 20) -SOURCE_TYPE(COUNT, 20) // Always keep this as the last entry. +SOURCE_TYPE(COUNT, 21) // Always keep this as the last entry. |