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

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "content/browser/web_contents/web_contents_impl.h" 47 #include "content/browser/web_contents/web_contents_impl.h"
48 #include "content/public/browser/browser_context.h" 48 #include "content/public/browser/browser_context.h"
49 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/content_browser_client.h" 50 #include "content/public/browser/content_browser_client.h"
51 #include "content/public/browser/download_danger_type.h" 51 #include "content/public/browser/download_danger_type.h"
52 #include "content/public/browser/download_interrupt_reasons.h" 52 #include "content/public/browser/download_interrupt_reasons.h"
53 #include "content/public/browser/download_url_parameters.h" 53 #include "content/public/browser/download_url_parameters.h"
54 #include "content/public/browser/storage_partition.h" 54 #include "content/public/browser/storage_partition.h"
55 #include "content/public/common/content_features.h" 55 #include "content/public/common/content_features.h"
56 #include "content/public/common/referrer.h" 56 #include "content/public/common/referrer.h"
57 #include "net/log/net_log_event_type.h"
57 58
58 namespace content { 59 namespace content {
59 60
60 namespace { 61 namespace {
61 62
62 bool DeleteDownloadedFile(const base::FilePath& path) { 63 bool DeleteDownloadedFile(const base::FilePath& path) {
63 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 64 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
64 65
65 // Make sure we only delete files. 66 // Make sure we only delete files.
66 if (base::DirectoryExists(path)) 67 if (base::DirectoryExists(path))
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 is_temporary_(!info.save_info->file_path.empty()), 193 is_temporary_(!info.save_info->file_path.empty()),
193 last_modified_time_(info.last_modified), 194 last_modified_time_(info.last_modified),
194 etag_(info.etag), 195 etag_(info.etag),
195 bound_net_log_(bound_net_log), 196 bound_net_log_(bound_net_log),
196 weak_ptr_factory_(this) { 197 weak_ptr_factory_(this) {
197 delegate_->Attach(); 198 delegate_->Attach();
198 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD); 199 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD);
199 200
200 // Link the event sources. 201 // Link the event sources.
201 bound_net_log_.AddEvent( 202 bound_net_log_.AddEvent(
202 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, 203 net::NetLogEventType::DOWNLOAD_URL_REQUEST,
203 info.request_bound_net_log.source().ToEventParametersCallback()); 204 info.request_bound_net_log.source().ToEventParametersCallback());
204 205
205 info.request_bound_net_log.AddEvent( 206 info.request_bound_net_log.AddEvent(
206 net::NetLog::TYPE_DOWNLOAD_STARTED, 207 net::NetLogEventType::DOWNLOAD_STARTED,
207 bound_net_log_.source().ToEventParametersCallback()); 208 bound_net_log_.source().ToEventParametersCallback());
208 } 209 }
209 210
210 // Constructing for the "Save Page As..." feature: 211 // Constructing for the "Save Page As..." feature:
211 DownloadItemImpl::DownloadItemImpl( 212 DownloadItemImpl::DownloadItemImpl(
212 DownloadItemImplDelegate* delegate, 213 DownloadItemImplDelegate* delegate,
213 uint32_t download_id, 214 uint32_t download_id,
214 const base::FilePath& path, 215 const base::FilePath& path,
215 const GURL& url, 216 const GURL& url,
216 const std::string& mime_type, 217 const std::string& mime_type,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 276
276 if (IsDone() || !IsDangerous()) 277 if (IsDone() || !IsDangerous())
277 return; 278 return;
278 279
279 RecordDangerousDownloadAccept(GetDangerType(), 280 RecordDangerousDownloadAccept(GetDangerType(),
280 GetTargetFilePath()); 281 GetTargetFilePath());
281 282
282 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; 283 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED;
283 284
284 bound_net_log_.AddEvent( 285 bound_net_log_.AddEvent(
285 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 286 net::NetLogEventType::DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
286 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); 287 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
287 288
288 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download 289 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download
289 // may not be in a consistent state or around at all after 290 // may not be in a consistent state or around at all after
290 // invoking observers. http://crbug.com/586610 291 // invoking observers. http://crbug.com/586610
291 292
292 MaybeCompleteDownload(); 293 MaybeCompleteDownload();
293 } 294 }
294 295
295 void DownloadItemImpl::StealDangerousDownload( 296 void DownloadItemImpl::StealDangerousDownload(
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 // There must be no pending destination_error_. 1032 // There must be no pending destination_error_.
1032 DCHECK_EQ(destination_error_, DOWNLOAD_INTERRUPT_REASON_NONE); 1033 DCHECK_EQ(destination_error_, DOWNLOAD_INTERRUPT_REASON_NONE);
1033 1034
1034 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far 1035 DVLOG(20) << __func__ << "() so_far=" << bytes_so_far
1035 << " per_sec=" << bytes_per_sec 1036 << " per_sec=" << bytes_per_sec
1036 << " download=" << DebugString(true); 1037 << " download=" << DebugString(true);
1037 1038
1038 UpdateProgress(bytes_so_far, bytes_per_sec); 1039 UpdateProgress(bytes_so_far, bytes_per_sec);
1039 if (bound_net_log_.IsCapturing()) { 1040 if (bound_net_log_.IsCapturing()) {
1040 bound_net_log_.AddEvent( 1041 bound_net_log_.AddEvent(
1041 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, 1042 net::NetLogEventType::DOWNLOAD_ITEM_UPDATED,
1042 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); 1043 net::NetLog::Int64Callback("bytes_so_far", received_bytes_));
1043 } 1044 }
1044 1045
1045 UpdateObservers(); 1046 UpdateObservers();
1046 } 1047 }
1047 1048
1048 void DownloadItemImpl::DestinationError( 1049 void DownloadItemImpl::DestinationError(
1049 DownloadInterruptReason reason, 1050 DownloadInterruptReason reason,
1050 int64_t bytes_so_far, 1051 int64_t bytes_so_far,
1051 std::unique_ptr<crypto::SecureHash> secure_hash) { 1052 std::unique_ptr<crypto::SecureHash> secure_hash) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 file_name = suggested_filename_; 1111 file_name = suggested_filename_;
1111 // From the URL file name. 1112 // From the URL file name.
1112 if (file_name.empty()) 1113 if (file_name.empty())
1113 file_name = GetURL().ExtractFileName(); 1114 file_name = GetURL().ExtractFileName();
1114 } 1115 }
1115 1116
1116 net::NetLog::ParametersCallback active_data = 1117 net::NetLog::ParametersCallback active_data =
1117 base::Bind(&ItemActivatedNetLogCallback, this, download_type, &file_name); 1118 base::Bind(&ItemActivatedNetLogCallback, this, download_type, &file_name);
1118 if (active) { 1119 if (active) {
1119 bound_net_log_.BeginEvent( 1120 bound_net_log_.BeginEvent(
1120 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); 1121 net::NetLogEventType::DOWNLOAD_ITEM_ACTIVE, active_data);
1121 } else { 1122 } else {
1122 bound_net_log_.AddEvent( 1123 bound_net_log_.AddEvent(
1123 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); 1124 net::NetLogEventType::DOWNLOAD_ITEM_ACTIVE, active_data);
1124 } 1125 }
1125 1126
1126 DVLOG(20) << __func__ << "() " << DebugString(true); 1127 DVLOG(20) << __func__ << "() " << DebugString(true);
1127 } 1128 }
1128 1129
1129 // We're starting the download. 1130 // We're starting the download.
1130 void DownloadItemImpl::Start( 1131 void DownloadItemImpl::Start(
1131 std::unique_ptr<DownloadFile> file, 1132 std::unique_ptr<DownloadFile> file,
1132 std::unique_ptr<DownloadRequestHandleInterface> req_handle, 1133 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
1133 const DownloadCreateInfo& new_create_info) { 1134 const DownloadCreateInfo& new_create_info) {
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 1749
1749 case COMPLETING_INTERNAL: 1750 case COMPLETING_INTERNAL:
1750 DCHECK(all_data_saved_) << "All data must be saved prior to completion."; 1751 DCHECK(all_data_saved_) << "All data must be saved prior to completion.";
1751 DCHECK(!download_file_) 1752 DCHECK(!download_file_)
1752 << "Download file must be released prior to completion."; 1753 << "Download file must be released prior to completion.";
1753 DCHECK(!target_path_.empty()) << "Target path must be known."; 1754 DCHECK(!target_path_.empty()) << "Target path must be known.";
1754 DCHECK(current_path_ == target_path_) 1755 DCHECK(current_path_ == target_path_)
1755 << "Current output path must match target path."; 1756 << "Current output path must match target path.";
1756 1757
1757 bound_net_log_.AddEvent( 1758 bound_net_log_.AddEvent(
1758 net::NetLog::TYPE_DOWNLOAD_ITEM_COMPLETING, 1759 net::NetLogEventType::DOWNLOAD_ITEM_COMPLETING,
1759 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_)); 1760 base::Bind(&ItemCompletingNetLogCallback, received_bytes_, &hash_));
1760 break; 1761 break;
1761 1762
1762 case COMPLETE_INTERNAL: 1763 case COMPLETE_INTERNAL:
1763 bound_net_log_.AddEvent( 1764 bound_net_log_.AddEvent(
1764 net::NetLog::TYPE_DOWNLOAD_ITEM_FINISHED, 1765 net::NetLogEventType::DOWNLOAD_ITEM_FINISHED,
1765 base::Bind(&ItemFinishedNetLogCallback, auto_opened_)); 1766 base::Bind(&ItemFinishedNetLogCallback, auto_opened_));
1766 break; 1767 break;
1767 1768
1768 case INTERRUPTED_INTERNAL: 1769 case INTERRUPTED_INTERNAL:
1769 bound_net_log_.AddEvent( 1770 bound_net_log_.AddEvent(
1770 net::NetLog::TYPE_DOWNLOAD_ITEM_INTERRUPTED, 1771 net::NetLogEventType::DOWNLOAD_ITEM_INTERRUPTED,
1771 base::Bind( 1772 base::Bind(
1772 &ItemInterruptedNetLogCallback, last_reason_, received_bytes_)); 1773 &ItemInterruptedNetLogCallback, last_reason_, received_bytes_));
1773 break; 1774 break;
1774 1775
1775 case RESUMING_INTERNAL: 1776 case RESUMING_INTERNAL:
1776 bound_net_log_.AddEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_RESUMED, 1777 bound_net_log_.AddEvent(net::NetLogEventType::DOWNLOAD_ITEM_RESUMED,
1777 base::Bind(&ItemResumingNetLogCallback, 1778 base::Bind(&ItemResumingNetLogCallback,
1778 false, 1779 false,
1779 last_reason_, 1780 last_reason_,
1780 received_bytes_)); 1781 received_bytes_));
1781 break; 1782 break;
1782 1783
1783 case CANCELLED_INTERNAL: 1784 case CANCELLED_INTERNAL:
1784 bound_net_log_.AddEvent( 1785 bound_net_log_.AddEvent(
1785 net::NetLog::TYPE_DOWNLOAD_ITEM_CANCELED, 1786 net::NetLogEventType::DOWNLOAD_ITEM_CANCELED,
1786 base::Bind(&ItemCanceledNetLogCallback, received_bytes_)); 1787 base::Bind(&ItemCanceledNetLogCallback, received_bytes_));
1787 break; 1788 break;
1788 1789
1789 case MAX_DOWNLOAD_INTERNAL_STATE: 1790 case MAX_DOWNLOAD_INTERNAL_STATE:
1790 NOTREACHED(); 1791 NOTREACHED();
1791 break; 1792 break;
1792 } 1793 }
1793 1794
1794 DVLOG(20) << __func__ << "() from:" << DebugDownloadStateString(old_state) 1795 DVLOG(20) << __func__ << "() from:" << DebugDownloadStateString(old_state)
1795 << " to:" << DebugDownloadStateString(state_) 1796 << " to:" << DebugDownloadStateString(state_)
1796 << " this = " << DebugString(true); 1797 << " this = " << DebugString(true);
1797 bool is_done = 1798 bool is_done =
1798 (state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL || 1799 (state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL ||
1799 state_ == RESUMING_INTERNAL || state_ == CANCELLED_INTERNAL); 1800 state_ == RESUMING_INTERNAL || state_ == CANCELLED_INTERNAL);
1800 bool was_done = 1801 bool was_done =
1801 (old_state == COMPLETE_INTERNAL || old_state == INTERRUPTED_INTERNAL || 1802 (old_state == COMPLETE_INTERNAL || old_state == INTERRUPTED_INTERNAL ||
1802 old_state == RESUMING_INTERNAL || old_state == CANCELLED_INTERNAL); 1803 old_state == RESUMING_INTERNAL || old_state == CANCELLED_INTERNAL);
1803 1804
1804 // Termination 1805 // Termination
1805 if (is_done && !was_done) 1806 if (is_done && !was_done)
1806 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); 1807 bound_net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_ITEM_ACTIVE);
1807 1808
1808 // Resumption 1809 // Resumption
1809 if (was_done && !is_done) { 1810 if (was_done && !is_done) {
1810 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); 1811 std::string file_name(target_path_.BaseName().AsUTF8Unsafe());
1811 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, 1812 bound_net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_ITEM_ACTIVE,
1812 base::Bind(&ItemActivatedNetLogCallback, 1813 base::Bind(&ItemActivatedNetLogCallback,
1813 this, SRC_ACTIVE_DOWNLOAD, 1814 this, SRC_ACTIVE_DOWNLOAD,
1814 &file_name)); 1815 &file_name));
1815 } 1816 }
1816 } 1817 }
1817 1818
1818 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { 1819 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) {
1819 if (danger_type != danger_type_) { 1820 if (danger_type != danger_type_) {
1820 bound_net_log_.AddEvent( 1821 bound_net_log_.AddEvent(
1821 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 1822 net::NetLogEventType::DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
1822 base::Bind(&ItemCheckedNetLogCallback, danger_type)); 1823 base::Bind(&ItemCheckedNetLogCallback, danger_type));
1823 } 1824 }
1824 // Only record the Malicious UMA stat if it's going from {not malicious} -> 1825 // Only record the Malicious UMA stat if it's going from {not malicious} ->
1825 // {malicious}. 1826 // {malicious}.
1826 if ((danger_type_ == DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || 1827 if ((danger_type_ == DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS ||
1827 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || 1828 danger_type_ == DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
1828 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT || 1829 danger_type_ == DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT ||
1829 danger_type_ == DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) && 1830 danger_type_ == DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) &&
1830 (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || 1831 (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST ||
1831 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || 1832 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
1832 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || 1833 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
1833 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) { 1834 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) {
1834 RecordMaliciousDownloadClassified(danger_type); 1835 RecordMaliciousDownloadClassified(danger_type);
1835 } 1836 }
1836 danger_type_ = danger_type; 1837 danger_type_ = danger_type;
1837 } 1838 }
1838 1839
1839 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { 1840 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) {
1840 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1841 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1841 DVLOG(20) << __func__ << "() new_path = \"" << new_path.value() << "\" " 1842 DVLOG(20) << __func__ << "() new_path = \"" << new_path.value() << "\" "
1842 << DebugString(true); 1843 << DebugString(true);
1843 DCHECK(!new_path.empty()); 1844 DCHECK(!new_path.empty());
1844 1845
1845 bound_net_log_.AddEvent( 1846 bound_net_log_.AddEvent(
1846 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1847 net::NetLogEventType::DOWNLOAD_ITEM_RENAMED,
1847 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path)); 1848 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path));
1848 1849
1849 current_path_ = new_path; 1850 current_path_ = new_path;
1850 } 1851 }
1851 1852
1852 void DownloadItemImpl::AutoResumeIfValid() { 1853 void DownloadItemImpl::AutoResumeIfValid() {
1853 DVLOG(20) << __func__ << "() " << DebugString(true); 1854 DVLOG(20) << __func__ << "() " << DebugString(true);
1854 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1855 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1855 ResumeMode mode = GetResumeMode(); 1856 ResumeMode mode = GetResumeMode();
1856 1857
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 case RESUME_MODE_USER_CONTINUE: 2090 case RESUME_MODE_USER_CONTINUE:
2090 return "USER_CONTINUE"; 2091 return "USER_CONTINUE";
2091 case RESUME_MODE_USER_RESTART: 2092 case RESUME_MODE_USER_RESTART:
2092 return "USER_RESTART"; 2093 return "USER_RESTART";
2093 } 2094 }
2094 NOTREACHED() << "Unknown resume mode " << mode; 2095 NOTREACHED() << "Unknown resume mode " << mode;
2095 return "unknown"; 2096 return "unknown";
2096 } 2097 }
2097 2098
2098 } // namespace content 2099 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698