Chromium Code Reviews| Index: content/browser/download/download_item_impl.cc |
| diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc |
| index aeea3c9debb4d828bc4afc0aeecd042b793a0285..4b24eb3672cad2ed50d74f31036327796c82f99e 100644 |
| --- a/content/browser/download/download_item_impl.cc |
| +++ b/content/browser/download/download_item_impl.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. |
| @@ -160,7 +160,8 @@ void DownloadItemImpl::Delegate::Detach() { |
| // Constructor for reading from the history service. |
| DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
| DownloadId download_id, |
| - const DownloadPersistentStoreInfo& info) |
| + const DownloadPersistentStoreInfo& info, |
| + net::NetLog* net_log) |
| : download_id_(download_id), |
| full_path_(info.path), |
| url_chain_(1, info.url), |
| @@ -185,13 +186,16 @@ DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
| all_data_saved_(false), |
| opened_(info.opened), |
| open_enabled_(true), |
| - delegate_delayed_complete_(false) { |
| + delegate_delayed_complete_(false), |
| + bound_net_log_(net::BoundNetLog::Make(net_log, |
| + net::NetLog::SOURCE_DOWNLOAD)) { |
| delegate_->Attach(); |
| if (IsInProgress()) |
| state_ = CANCELLED; |
| if (IsComplete()) |
| all_data_saved_ = true; |
| - Init(false /* not actively downloading */); |
| + Init(false /* not actively downloading */, |
| + download_net_logs::SRC_HISTORY_IMPORT); |
| } |
| // Constructing for a regular download: |
| @@ -233,9 +237,11 @@ DownloadItemImpl::DownloadItemImpl( |
| all_data_saved_(false), |
| opened_(false), |
| open_enabled_(true), |
| - delegate_delayed_complete_(false) { |
| + delegate_delayed_complete_(false), |
| + bound_net_log_(net::BoundNetLog()) { |
|
Randy Smith (Not in Mondays)
2012/02/06 22:34:59
Put a TODO comment in here explaining why we're no
ahendrickson
2012/02/07 00:16:19
Done.
Randy Smith (Not in Mondays)
2012/02/07 15:09:45
I don't feel like that comment explains why; do yo
ahendrickson
2012/02/07 17:18:35
Changed the comment.
|
| delegate_->Attach(); |
| - Init(true /* actively downloading */); |
| + Init(true /* actively downloading */, |
| + download_net_logs::SRC_NEW_DOWNLOAD); |
| } |
| // Constructing for the "Save Page As..." feature: |
| @@ -243,7 +249,8 @@ DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
| const FilePath& path, |
| const GURL& url, |
| bool is_otr, |
| - DownloadId download_id) |
| + DownloadId download_id, |
| + net::NetLog* net_log) |
| : request_handle_(new NullDownloadRequestHandle()), |
| download_id_(download_id), |
| full_path_(path), |
| @@ -268,9 +275,12 @@ DownloadItemImpl::DownloadItemImpl(Delegate* delegate, |
| all_data_saved_(false), |
| opened_(false), |
| open_enabled_(true), |
| - delegate_delayed_complete_(false) { |
| + delegate_delayed_complete_(false), |
| + bound_net_log_(net::BoundNetLog::Make(net_log, |
| + net::NetLog::SOURCE_DOWNLOAD)) { |
| delegate_->Attach(); |
| - Init(true /* actively downloading */); |
| + Init(true /* actively downloading */, |
| + download_net_logs::SRC_SAVE_PAGE_AS); |
| } |
| DownloadItemImpl::~DownloadItemImpl() { |
| @@ -363,6 +373,12 @@ void DownloadItemImpl::DangerousDownloadValidated() { |
| content::DOWNLOAD_DANGER_TYPE_MAX); |
| safety_state_ = DANGEROUS_BUT_VALIDATED; |
| + |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemCheckedParameters(safety_state_))); |
| + |
| UpdateObservers(); |
| delegate_->MaybeCompleteDownload(this); |
| @@ -394,6 +410,13 @@ void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, |
| // revert to 'unknown size mode'. |
| if (received_bytes_ > total_bytes_) |
| total_bytes_ = 0; |
| + |
| + if (bound_net_log_.IsLoggingAllEvents()) { |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemUpdatedParameters(received_bytes_))); |
| + } |
| } |
| // Updates from the download thread may have been posted while this download |
| @@ -503,8 +526,42 @@ void DownloadItemImpl::TransitionTo(DownloadState new_state) { |
| if (state_ == new_state) |
| return; |
| + DownloadState old_state = state_; |
| state_ = new_state; |
| + |
| + switch (state_) { |
| + case COMPLETE: |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemFinishedParameters(received_bytes_, |
| + hash_))); |
| + break; |
| + case INTERRUPTED: |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemInterruptedParameters(last_reason_, |
| + received_bytes_, |
| + hash_state_))); |
| + break; |
| + case CANCELLED: |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemCanceledParameters(received_bytes_, |
| + hash_state_))); |
| + break; |
| + default: |
| + break; |
| + } |
| + |
| UpdateObservers(); |
| + |
| + bool is_done = (state_ != IN_PROGRESS); |
| + bool was_done = (old_state != IN_PROGRESS); |
| + if (is_done && !was_done) |
| + bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); |
| } |
| void DownloadItemImpl::UpdateSafetyState() { |
| @@ -512,6 +569,12 @@ void DownloadItemImpl::UpdateSafetyState() { |
| DownloadItem::DANGEROUS : DownloadItem::SAFE; |
| if (updated_value != safety_state_) { |
| safety_state_ = updated_value; |
| + |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemCheckedParameters(safety_state_))); |
| + |
| UpdateObservers(); |
| } |
| } |
| @@ -624,6 +687,13 @@ void DownloadItemImpl::Rename(const FilePath& full_path) { |
| << " full_path = \"" << full_path.value() << "\"" |
| << " " << DebugString(true); |
| DCHECK(!full_path.empty()); |
| + |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemRenamedParameters( |
| + full_path_.AsUTF8Unsafe(), full_path.AsUTF8Unsafe()))); |
| + |
| full_path_ = full_path; |
| } |
| @@ -811,13 +881,43 @@ void DownloadItemImpl::OffThreadCancel(DownloadFileManager* file_manager) { |
| file_manager, download_id_)); |
| } |
| -void DownloadItemImpl::Init(bool active) { |
| +void DownloadItemImpl::Init(bool active, |
| + download_net_logs::DownloadType download_type) { |
| // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| UpdateTarget(); |
| if (active) |
| download_stats::RecordDownloadCount(download_stats::START_COUNT); |
| + |
| + // full_path_ works for History and Save As versions. |
| + std::string file_name = full_path_.AsUTF8Unsafe(); |
| + if (file_name.empty()) |
| + file_name = suggested_filename_; // From 'download' attribute of anchor. |
| + if (file_name.empty()) |
| + file_name = GetURL().ExtractFileName(); // URL file name. |
| + |
| + bound_net_log_.BeginEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, |
| + make_scoped_refptr(new download_net_logs::ItemActivatedParameters( |
| + download_type, |
| + download_id_.local(), |
| + GetOriginalUrl().spec(), |
| + GetURL().spec(), |
| + file_name, |
| + safety_state_, |
| + received_bytes_))); |
| + |
| + // If this is not an active download, end the ACTIVE event now. |
| + if (!active) { |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemInHistoryParameters(db_handle_))); |
| + |
| + bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, NULL); |
| + } |
| + |
| VLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
| } |
| @@ -947,7 +1047,16 @@ int32 DownloadItemImpl::GetId() const { return download_id_.local(); } |
| DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; } |
| base::Time DownloadItemImpl::GetStartTime() const { return start_time_; } |
| base::Time DownloadItemImpl::GetEndTime() const { return end_time_; } |
| -void DownloadItemImpl::SetDbHandle(int64 handle) { db_handle_ = handle; } |
| + |
| +void DownloadItemImpl::SetDbHandle(int64 handle) { |
| + db_handle_ = handle; |
| + |
| + bound_net_log_.AddEvent( |
| + net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, |
| + make_scoped_refptr( |
| + new download_net_logs::ItemInHistoryParameters(db_handle_))); |
| +} |
| + |
| int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; } |
| bool DownloadItemImpl::IsPaused() const { return is_paused_; } |
| bool DownloadItemImpl::GetOpenWhenComplete() const { |