| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 // auto-opened. | 22 // auto-opened. |
| 23 | 23 |
| 24 #include "content/browser/download/download_item_impl.h" | 24 #include "content/browser/download/download_item_impl.h" |
| 25 | 25 |
| 26 #include <utility> | 26 #include <utility> |
| 27 #include <vector> | 27 #include <vector> |
| 28 | 28 |
| 29 #include "base/bind.h" | 29 #include "base/bind.h" |
| 30 #include "base/files/file_util.h" | 30 #include "base/files/file_util.h" |
| 31 #include "base/format_macros.h" | 31 #include "base/format_macros.h" |
| 32 #include "base/guid.h" |
| 32 #include "base/logging.h" | 33 #include "base/logging.h" |
| 33 #include "base/metrics/histogram.h" | 34 #include "base/metrics/histogram.h" |
| 34 #include "base/stl_util.h" | 35 #include "base/stl_util.h" |
| 36 #include "base/strings/string_util.h" |
| 35 #include "base/strings/stringprintf.h" | 37 #include "base/strings/stringprintf.h" |
| 36 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 37 #include "content/browser/download/download_create_info.h" | 39 #include "content/browser/download/download_create_info.h" |
| 38 #include "content/browser/download/download_file.h" | 40 #include "content/browser/download/download_file.h" |
| 39 #include "content/browser/download/download_interrupt_reasons_impl.h" | 41 #include "content/browser/download/download_interrupt_reasons_impl.h" |
| 40 #include "content/browser/download/download_item_impl_delegate.h" | 42 #include "content/browser/download/download_item_impl_delegate.h" |
| 41 #include "content/browser/download/download_request_handle.h" | 43 #include "content/browser/download/download_request_handle.h" |
| 42 #include "content/browser/download/download_stats.h" | 44 #include "content/browser/download/download_stats.h" |
| 43 #include "content/browser/renderer_host/render_view_host_impl.h" | 45 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 44 #include "content/browser/web_contents/web_contents_impl.h" | 46 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 100 |
| 99 const uint32_t DownloadItem::kInvalidId = 0; | 101 const uint32_t DownloadItem::kInvalidId = 0; |
| 100 | 102 |
| 101 const char DownloadItem::kEmptyFileHash[] = ""; | 103 const char DownloadItem::kEmptyFileHash[] = ""; |
| 102 | 104 |
| 103 // The maximum number of attempts we will make to resume automatically. | 105 // The maximum number of attempts we will make to resume automatically. |
| 104 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; | 106 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; |
| 105 | 107 |
| 106 // Constructor for reading from the history service. | 108 // Constructor for reading from the history service. |
| 107 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 109 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 110 const std::string& guid, |
| 108 uint32_t download_id, | 111 uint32_t download_id, |
| 109 const base::FilePath& current_path, | 112 const base::FilePath& current_path, |
| 110 const base::FilePath& target_path, | 113 const base::FilePath& target_path, |
| 111 const std::vector<GURL>& url_chain, | 114 const std::vector<GURL>& url_chain, |
| 112 const GURL& referrer_url, | 115 const GURL& referrer_url, |
| 113 const std::string& mime_type, | 116 const std::string& mime_type, |
| 114 const std::string& original_mime_type, | 117 const std::string& original_mime_type, |
| 115 const base::Time& start_time, | 118 const base::Time& start_time, |
| 116 const base::Time& end_time, | 119 const base::Time& end_time, |
| 117 const std::string& etag, | 120 const std::string& etag, |
| 118 const std::string& last_modified, | 121 const std::string& last_modified, |
| 119 int64_t received_bytes, | 122 int64_t received_bytes, |
| 120 int64_t total_bytes, | 123 int64_t total_bytes, |
| 121 DownloadItem::DownloadState state, | 124 DownloadItem::DownloadState state, |
| 122 DownloadDangerType danger_type, | 125 DownloadDangerType danger_type, |
| 123 DownloadInterruptReason interrupt_reason, | 126 DownloadInterruptReason interrupt_reason, |
| 124 bool opened, | 127 bool opened, |
| 125 const net::BoundNetLog& bound_net_log) | 128 const net::BoundNetLog& bound_net_log) |
| 126 : download_id_(download_id), | 129 : guid_(base::ToUpperASCII(guid)), |
| 130 download_id_(download_id), |
| 127 current_path_(current_path), | 131 current_path_(current_path), |
| 128 target_path_(target_path), | 132 target_path_(target_path), |
| 129 url_chain_(url_chain), | 133 url_chain_(url_chain), |
| 130 referrer_url_(referrer_url), | 134 referrer_url_(referrer_url), |
| 131 mime_type_(mime_type), | 135 mime_type_(mime_type), |
| 132 original_mime_type_(original_mime_type), | 136 original_mime_type_(original_mime_type), |
| 133 total_bytes_(total_bytes), | 137 total_bytes_(total_bytes), |
| 134 received_bytes_(received_bytes), | 138 received_bytes_(received_bytes), |
| 135 last_modified_time_(last_modified), | 139 last_modified_time_(last_modified), |
| 136 etag_(etag), | 140 etag_(etag), |
| 137 last_reason_(interrupt_reason), | 141 last_reason_(interrupt_reason), |
| 138 start_tick_(base::TimeTicks()), | 142 start_tick_(base::TimeTicks()), |
| 139 state_(ExternalToInternalState(state)), | 143 state_(ExternalToInternalState(state)), |
| 140 danger_type_(danger_type), | 144 danger_type_(danger_type), |
| 141 start_time_(start_time), | 145 start_time_(start_time), |
| 142 end_time_(end_time), | 146 end_time_(end_time), |
| 143 delegate_(delegate), | 147 delegate_(delegate), |
| 144 all_data_saved_(state == COMPLETE), | 148 all_data_saved_(state == COMPLETE), |
| 145 opened_(opened), | 149 opened_(opened), |
| 146 bound_net_log_(bound_net_log), | 150 bound_net_log_(bound_net_log), |
| 147 weak_ptr_factory_(this) { | 151 weak_ptr_factory_(this) { |
| 148 delegate_->Attach(); | 152 delegate_->Attach(); |
| 149 DCHECK(state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL || | 153 DCHECK(state_ == COMPLETE_INTERNAL || state_ == INTERRUPTED_INTERNAL || |
| 150 state_ == CANCELLED_INTERNAL); | 154 state_ == CANCELLED_INTERNAL); |
| 155 DCHECK(base::IsValidGUID(guid_)); |
| 151 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); | 156 Init(false /* not actively downloading */, SRC_HISTORY_IMPORT); |
| 152 } | 157 } |
| 153 | 158 |
| 154 // Constructing for a regular download: | 159 // Constructing for a regular download: |
| 155 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, | 160 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, |
| 156 uint32_t download_id, | 161 uint32_t download_id, |
| 157 const DownloadCreateInfo& info, | 162 const DownloadCreateInfo& info, |
| 158 const net::BoundNetLog& bound_net_log) | 163 const net::BoundNetLog& bound_net_log) |
| 159 : download_id_(download_id), | 164 : guid_(base::ToUpperASCII(base::GenerateGUID())), |
| 165 download_id_(download_id), |
| 160 target_disposition_((info.save_info->prompt_for_save_location) | 166 target_disposition_((info.save_info->prompt_for_save_location) |
| 161 ? TARGET_DISPOSITION_PROMPT | 167 ? TARGET_DISPOSITION_PROMPT |
| 162 : TARGET_DISPOSITION_OVERWRITE), | 168 : TARGET_DISPOSITION_OVERWRITE), |
| 163 url_chain_(info.url_chain), | 169 url_chain_(info.url_chain), |
| 164 referrer_url_(info.referrer_url), | 170 referrer_url_(info.referrer_url), |
| 165 tab_url_(info.tab_url), | 171 tab_url_(info.tab_url), |
| 166 tab_referrer_url_(info.tab_referrer_url), | 172 tab_referrer_url_(info.tab_referrer_url), |
| 167 suggested_filename_(base::UTF16ToUTF8(info.save_info->suggested_name)), | 173 suggested_filename_(base::UTF16ToUTF8(info.save_info->suggested_name)), |
| 168 forced_file_path_(info.save_info->file_path), | 174 forced_file_path_(info.save_info->file_path), |
| 169 transition_type_(info.transition_type), | 175 transition_type_(info.transition_type), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 200 DownloadItemImpl::DownloadItemImpl( | 206 DownloadItemImpl::DownloadItemImpl( |
| 201 DownloadItemImplDelegate* delegate, | 207 DownloadItemImplDelegate* delegate, |
| 202 uint32_t download_id, | 208 uint32_t download_id, |
| 203 const base::FilePath& path, | 209 const base::FilePath& path, |
| 204 const GURL& url, | 210 const GURL& url, |
| 205 const std::string& mime_type, | 211 const std::string& mime_type, |
| 206 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 212 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
| 207 const net::BoundNetLog& bound_net_log) | 213 const net::BoundNetLog& bound_net_log) |
| 208 : is_save_package_download_(true), | 214 : is_save_package_download_(true), |
| 209 request_handle_(std::move(request_handle)), | 215 request_handle_(std::move(request_handle)), |
| 216 guid_(base::ToUpperASCII(base::GenerateGUID())), |
| 210 download_id_(download_id), | 217 download_id_(download_id), |
| 211 current_path_(path), | 218 current_path_(path), |
| 212 target_path_(path), | 219 target_path_(path), |
| 213 url_chain_(1, url), | 220 url_chain_(1, url), |
| 214 mime_type_(mime_type), | 221 mime_type_(mime_type), |
| 215 original_mime_type_(mime_type), | 222 original_mime_type_(mime_type), |
| 216 start_tick_(base::TimeTicks::Now()), | 223 start_tick_(base::TimeTicks::Now()), |
| 217 state_(IN_PROGRESS_INTERNAL), | 224 state_(IN_PROGRESS_INTERNAL), |
| 218 start_time_(base::Time::Now()), | 225 start_time_(base::Time::Now()), |
| 219 delegate_(delegate), | 226 delegate_(delegate), |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 void DownloadItemImpl::ShowDownloadInShell() { | 425 void DownloadItemImpl::ShowDownloadInShell() { |
| 419 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 426 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 420 | 427 |
| 421 delegate_->ShowDownloadInShell(this); | 428 delegate_->ShowDownloadInShell(this); |
| 422 } | 429 } |
| 423 | 430 |
| 424 uint32_t DownloadItemImpl::GetId() const { | 431 uint32_t DownloadItemImpl::GetId() const { |
| 425 return download_id_; | 432 return download_id_; |
| 426 } | 433 } |
| 427 | 434 |
| 435 const std::string& DownloadItemImpl::GetGuid() const { |
| 436 return guid_; |
| 437 } |
| 438 |
| 428 DownloadItem::DownloadState DownloadItemImpl::GetState() const { | 439 DownloadItem::DownloadState DownloadItemImpl::GetState() const { |
| 429 return InternalToExternalState(state_); | 440 return InternalToExternalState(state_); |
| 430 } | 441 } |
| 431 | 442 |
| 432 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { | 443 DownloadInterruptReason DownloadItemImpl::GetLastReason() const { |
| 433 return last_reason_; | 444 return last_reason_; |
| 434 } | 445 } |
| 435 | 446 |
| 436 bool DownloadItemImpl::IsPaused() const { | 447 bool DownloadItemImpl::IsPaused() const { |
| 437 return is_paused_; | 448 return is_paused_; |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 case RESUME_MODE_USER_CONTINUE: | 2003 case RESUME_MODE_USER_CONTINUE: |
| 1993 return "USER_CONTINUE"; | 2004 return "USER_CONTINUE"; |
| 1994 case RESUME_MODE_USER_RESTART: | 2005 case RESUME_MODE_USER_RESTART: |
| 1995 return "USER_RESTART"; | 2006 return "USER_RESTART"; |
| 1996 } | 2007 } |
| 1997 NOTREACHED() << "Unknown resume mode " << mode; | 2008 NOTREACHED() << "Unknown resume mode " << mode; |
| 1998 return "unknown"; | 2009 return "unknown"; |
| 1999 } | 2010 } |
| 2000 | 2011 |
| 2001 } // namespace content | 2012 } // namespace content |
| OLD | NEW |