| Index: content/browser/download/download_file_impl.cc
|
| diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc
|
| index a1ab62a1a8908cb5b000f2c478d68da81bcc5464..c7a09426f6fc29b1d0862b76fad15d3b8626acab 100644
|
| --- a/content/browser/download/download_file_impl.cc
|
| +++ b/content/browser/download/download_file_impl.cc
|
| @@ -16,7 +16,7 @@
|
| #include "content/browser/download/download_net_log_parameters.h"
|
| #include "content/browser/power_save_blocker.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/download_manager.h"
|
| +#include "content/public/browser/download_destination_controller.h"
|
| #include "content/browser/download/download_stats.h"
|
| #include "net/base/io_buffer.h"
|
|
|
| @@ -27,57 +27,72 @@ using content::DownloadManager;
|
| const int kUpdatePeriodMs = 500;
|
| const int kMaxTimeBlockingFileThreadMs = 1000;
|
|
|
| +int content::DownloadFile::number_active_objects_ = 0;
|
| +
|
| DownloadFileImpl::DownloadFileImpl(
|
| - const DownloadCreateInfo* info,
|
| - scoped_ptr<content::ByteStreamReader> stream,
|
| - DownloadRequestHandleInterface* request_handle,
|
| - scoped_refptr<DownloadManager> download_manager,
|
| + const content::DownloadSaveInfo& save_info,
|
| + const GURL& url,
|
| + const GURL& referrer_url,
|
| + int64 received_bytes,
|
| bool calculate_hash,
|
| + scoped_ptr<content::ByteStreamReader> stream,
|
| + const net::BoundNetLog& bound_net_log,
|
| scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
|
| - const net::BoundNetLog& bound_net_log)
|
| - : file_(info->save_info.file_path,
|
| - info->url(),
|
| - info->referrer_url,
|
| - info->received_bytes,
|
| + base::WeakPtr<content::DownloadDestinationController> controller)
|
| + : file_(save_info.file_path,
|
| + url,
|
| + referrer_url,
|
| + received_bytes,
|
| calculate_hash,
|
| - info->save_info.hash_state,
|
| - info->save_info.file_stream,
|
| + save_info.hash_state,
|
| + save_info.file_stream,
|
| bound_net_log),
|
| stream_reader_(stream.Pass()),
|
| - id_(info->download_id),
|
| - request_handle_(request_handle),
|
| - download_manager_(download_manager),
|
| bytes_seen_(0),
|
| bound_net_log_(bound_net_log),
|
| + controller_(controller),
|
| weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| power_save_blocker_(power_save_blocker.Pass()) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - DCHECK(download_manager.get());
|
| }
|
|
|
| DownloadFileImpl::~DownloadFileImpl() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| + --number_active_objects_;
|
| }
|
|
|
| -content::DownloadInterruptReason DownloadFileImpl::Initialize() {
|
| +void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| +
|
| update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>());
|
| - net::Error result = file_.Initialize();
|
| - if (result != net::OK) {
|
| - return content::ConvertNetErrorToInterruptReason(
|
| - result, content::DOWNLOAD_INTERRUPT_FROM_DISK);
|
| +
|
| + net::Error net_result = file_.Initialize();
|
| + if (net_result != net::OK) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE, base::Bind(
|
| + callback, content::ConvertNetErrorToInterruptReason(
|
| + net_result, content::DOWNLOAD_INTERRUPT_FROM_DISK)));
|
| + return;
|
| }
|
|
|
| stream_reader_->RegisterCallback(
|
| base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr()));
|
|
|
| download_start_ = base::TimeTicks::Now();
|
| +
|
| // Initial pull from the straw.
|
| StreamActive();
|
|
|
| - return content::DOWNLOAD_INTERRUPT_REASON_NONE;
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE, base::Bind(
|
| + callback, content::DOWNLOAD_INTERRUPT_REASON_NONE));
|
| +
|
| + ++number_active_objects_;
|
| }
|
|
|
| content::DownloadInterruptReason DownloadFileImpl::AppendDataToFile(
|
| const char* data, size_t data_len) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| +
|
| if (!update_timer_->IsRunning()) {
|
| update_timer_->Start(FROM_HERE,
|
| base::TimeDelta::FromMilliseconds(kUpdatePeriodMs),
|
| @@ -91,6 +106,8 @@ content::DownloadInterruptReason DownloadFileImpl::AppendDataToFile(
|
| void DownloadFileImpl::Rename(const FilePath& full_path,
|
| bool overwrite_existing_file,
|
| const RenameCompletionCallback& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| +
|
| FilePath new_path(full_path);
|
| if (!overwrite_existing_file) {
|
| // Make the file unique if requested.
|
| @@ -163,36 +180,6 @@ std::string DownloadFileImpl::GetHashState() {
|
| return file_.GetHashState();
|
| }
|
|
|
| -// DownloadFileInterface implementation.
|
| -void DownloadFileImpl::CancelDownloadRequest() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - request_handle_->CancelRequest();
|
| -}
|
| -
|
| -int DownloadFileImpl::Id() const {
|
| - return id_.local();
|
| -}
|
| -
|
| -DownloadManager* DownloadFileImpl::GetDownloadManager() {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| - return download_manager_.get();
|
| -}
|
| -
|
| -const DownloadId& DownloadFileImpl::GlobalId() const {
|
| - return id_;
|
| -}
|
| -
|
| -std::string DownloadFileImpl::DebugString() const {
|
| - return base::StringPrintf("{"
|
| - " id_ = " "%d"
|
| - " request_handle = %s"
|
| - " Base File = %s"
|
| - " }",
|
| - id_.local(),
|
| - request_handle_->DebugString().c_str(),
|
| - file_.DebugString().c_str());
|
| -}
|
| -
|
| void DownloadFileImpl::StreamActive() {
|
| base::TimeTicks start(base::TimeTicks::Now());
|
| base::TimeTicks now;
|
| @@ -271,8 +258,8 @@ void DownloadFileImpl::StreamActive() {
|
| SendUpdate(); // Make info up to date before error.
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&DownloadManager::OnDownloadInterrupted,
|
| - download_manager_, id_.local(), reason));
|
| + base::Bind(&content::DownloadDestinationController::DestinationError,
|
| + controller_, reason));
|
| } else if (state == content::ByteStreamReader::STREAM_COMPLETE) {
|
| // Signal successful completion and shut down processing.
|
| stream_reader_->RegisterCallback(base::Closure());
|
| @@ -280,11 +267,12 @@ void DownloadFileImpl::StreamActive() {
|
| std::string hash;
|
| if (!GetHash(&hash) || file_.IsEmptyHash(hash))
|
| hash.clear();
|
| + SendUpdate();
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&DownloadManager::OnResponseCompleted,
|
| - download_manager_, id_.local(),
|
| - BytesSoFar(), hash));
|
| + base::Bind(
|
| + &content::DownloadDestinationController::DestinationCompleted,
|
| + controller_, hash));
|
| }
|
| if (bound_net_log_.IsLoggingAllEvents()) {
|
| bound_net_log_.AddEvent(
|
| @@ -297,7 +285,12 @@ void DownloadFileImpl::StreamActive() {
|
| void DownloadFileImpl::SendUpdate() {
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&DownloadManager::UpdateDownload,
|
| - download_manager_, id_.local(),
|
| - BytesSoFar(), CurrentSpeed(), GetHashState()));
|
| + base::Bind(&content::DownloadDestinationController::DestinationUpdate,
|
| + controller_, BytesSoFar(), CurrentSpeed(), GetHashState()));
|
| +}
|
| +
|
| +// static
|
| +int content::DownloadFile::GetNumberOfDownloadFiles() {
|
| + return number_active_objects_;
|
| }
|
| +
|
|
|