| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "content/browser/download/download_item.h" | 5 #include "content/browser/download/download_item.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "chrome/browser/download/download_crx_util.h" | 17 #include "chrome/browser/download/download_crx_util.h" |
| 18 #include "chrome/browser/download/download_extensions.h" | 18 #include "chrome/browser/download/download_extensions.h" |
| 19 #include "chrome/browser/download/download_util.h" | 19 #include "chrome/browser/download/download_util.h" |
| 20 #include "chrome/browser/extensions/crx_installer.h" | 20 #include "chrome/browser/extensions/crx_installer.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 24 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
| 25 #include "content/browser/content_browser_client.h" | 25 #include "content/browser/content_browser_client.h" |
| 26 #include "content/browser/download/download_create_info.h" | 26 #include "content/browser/download/download_create_info.h" |
| 27 #include "content/browser/download/download_file_manager.h" | 27 #include "content/browser/download/download_file_manager.h" |
| 28 #include "content/browser/download/download_id.h" |
| 28 #include "content/browser/download/download_manager.h" | 29 #include "content/browser/download/download_manager.h" |
| 29 #include "content/browser/download/download_manager_delegate.h" | 30 #include "content/browser/download/download_manager_delegate.h" |
| 30 #include "content/browser/download/download_persistent_store_info.h" | 31 #include "content/browser/download/download_persistent_store_info.h" |
| 31 #include "content/browser/download/download_request_handle.h" | 32 #include "content/browser/download/download_request_handle.h" |
| 32 #include "content/browser/download/download_stats.h" | 33 #include "content/browser/download/download_stats.h" |
| 33 #include "content/common/notification_source.h" | 34 #include "content/common/notification_source.h" |
| 34 | 35 |
| 35 // A DownloadItem normally goes through the following states: | 36 // A DownloadItem normally goes through the following states: |
| 36 // * Created (when download starts) | 37 // * Created (when download starts) |
| 37 // * Made visible to consumers (e.g. Javascript) after the | 38 // * Made visible to consumers (e.g. Javascript) after the |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 opened_(false), | 191 opened_(false), |
| 191 open_enabled_(true) { | 192 open_enabled_(true) { |
| 192 Init(true /* actively downloading */); | 193 Init(true /* actively downloading */); |
| 193 } | 194 } |
| 194 | 195 |
| 195 // Constructing for the "Save Page As..." feature: | 196 // Constructing for the "Save Page As..." feature: |
| 196 DownloadItem::DownloadItem(DownloadManager* download_manager, | 197 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| 197 const FilePath& path, | 198 const FilePath& path, |
| 198 const GURL& url, | 199 const GURL& url, |
| 199 bool is_otr, | 200 bool is_otr, |
| 200 int download_id) | 201 DownloadId download_id) |
| 201 : download_id_(download_id), | 202 : download_id_(download_id.local()), |
| 202 full_path_(path), | 203 full_path_(path), |
| 203 url_chain_(1, url), | 204 url_chain_(1, url), |
| 204 referrer_url_(GURL()), | 205 referrer_url_(GURL()), |
| 205 total_bytes_(0), | 206 total_bytes_(0), |
| 206 received_bytes_(0), | 207 received_bytes_(0), |
| 207 last_os_error_(0), | 208 last_os_error_(0), |
| 208 start_tick_(base::TimeTicks::Now()), | 209 start_tick_(base::TimeTicks::Now()), |
| 209 state_(IN_PROGRESS), | 210 state_(IN_PROGRESS), |
| 210 start_time_(base::Time::Now()), | 211 start_time_(base::Time::Now()), |
| 211 db_handle_(DownloadItem::kUninitializedHandle), | 212 db_handle_(DownloadItem::kUninitializedHandle), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 224 } | 225 } |
| 225 | 226 |
| 226 DownloadItem::~DownloadItem() { | 227 DownloadItem::~DownloadItem() { |
| 227 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 228 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 228 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 229 | 230 |
| 230 TransitionTo(REMOVING); | 231 TransitionTo(REMOVING); |
| 231 download_manager_->AssertQueueStateConsistent(this); | 232 download_manager_->AssertQueueStateConsistent(this); |
| 232 } | 233 } |
| 233 | 234 |
| 235 DownloadId DownloadItem::global_id() const { |
| 236 return DownloadId(download_manager_, id()); |
| 237 } |
| 238 |
| 234 void DownloadItem::AddObserver(Observer* observer) { | 239 void DownloadItem::AddObserver(Observer* observer) { |
| 235 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 240 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 | 242 |
| 238 observers_.AddObserver(observer); | 243 observers_.AddObserver(observer); |
| 239 } | 244 } |
| 240 | 245 |
| 241 void DownloadItem::RemoveObserver(Observer* observer) { | 246 void DownloadItem::RemoveObserver(Observer* observer) { |
| 242 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 247 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 243 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 630 |
| 626 VLOG(20) << __FUNCTION__ << "()" | 631 VLOG(20) << __FUNCTION__ << "()" |
| 627 << " needs rename = " << NeedsRename() | 632 << " needs rename = " << NeedsRename() |
| 628 << " " << DebugString(true); | 633 << " " << DebugString(true); |
| 629 DCHECK_NE(DANGEROUS, safety_state()); | 634 DCHECK_NE(DANGEROUS, safety_state()); |
| 630 DCHECK(file_manager); | 635 DCHECK(file_manager); |
| 631 | 636 |
| 632 if (NeedsRename()) { | 637 if (NeedsRename()) { |
| 633 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 638 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 634 NewRunnableMethod(file_manager, | 639 NewRunnableMethod(file_manager, |
| 635 &DownloadFileManager::RenameCompletingDownloadFile, id(), | 640 &DownloadFileManager::RenameCompletingDownloadFile, global_id(), |
| 636 GetTargetFilePath(), safety_state() == SAFE)); | 641 GetTargetFilePath(), safety_state() == SAFE)); |
| 637 return; | 642 return; |
| 638 } | 643 } |
| 639 | 644 |
| 640 DCHECK(!is_extension_install()); | 645 DCHECK(!is_extension_install()); |
| 641 Completed(); | 646 Completed(); |
| 642 | 647 |
| 643 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 648 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod( |
| 644 NewRunnableMethod(file_manager, &DownloadFileManager::CompleteDownload, | 649 file_manager, &DownloadFileManager::CompleteDownload, global_id())); |
| 645 id())); | |
| 646 } | 650 } |
| 647 | 651 |
| 648 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) { | 652 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) { |
| 649 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 653 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 650 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 654 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 651 | 655 |
| 652 VLOG(20) << __FUNCTION__ << "()" | 656 VLOG(20) << __FUNCTION__ << "()" |
| 653 << " full_path = \"" << full_path.value() << "\"" | 657 << " full_path = \"" << full_path.value() << "\"" |
| 654 << " needed rename = " << NeedsRename() | 658 << " needed rename = " << NeedsRename() |
| 655 << " " << DebugString(false); | 659 << " " << DebugString(false); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 state_info_.target_name.value().c_str(), | 851 state_info_.target_name.value().c_str(), |
| 848 full_path().value().c_str()); | 852 full_path().value().c_str()); |
| 849 } else { | 853 } else { |
| 850 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 854 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
| 851 } | 855 } |
| 852 | 856 |
| 853 description += " }"; | 857 description += " }"; |
| 854 | 858 |
| 855 return description; | 859 return description; |
| 856 } | 860 } |
| OLD | NEW |