| Index: content/browser/download/download_file_impl.cc
|
| ===================================================================
|
| --- content/browser/download/download_file_impl.cc (revision 154444)
|
| +++ content/browser/download/download_file_impl.cc (working copy)
|
| @@ -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_destination_observer.h"
|
| +#include "content/public/browser/download_manager.h"
|
| #include "content/browser/download/download_stats.h"
|
| #include "net/base/io_buffer.h"
|
|
|
| @@ -27,72 +27,57 @@
|
| const int kUpdatePeriodMs = 500;
|
| const int kMaxTimeBlockingFileThreadMs = 1000;
|
|
|
| -int content::DownloadFile::number_active_objects_ = 0;
|
| -
|
| DownloadFileImpl::DownloadFileImpl(
|
| - const content::DownloadSaveInfo& save_info,
|
| - const GURL& url,
|
| - const GURL& referrer_url,
|
| - int64 received_bytes,
|
| - bool calculate_hash,
|
| + const DownloadCreateInfo* info,
|
| scoped_ptr<content::ByteStreamReader> stream,
|
| - const net::BoundNetLog& bound_net_log,
|
| + DownloadRequestHandleInterface* request_handle,
|
| + scoped_refptr<DownloadManager> download_manager,
|
| + bool calculate_hash,
|
| scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
|
| - base::WeakPtr<content::DownloadDestinationObserver> observer)
|
| - : file_(save_info.file_path,
|
| - url,
|
| - referrer_url,
|
| - received_bytes,
|
| + const net::BoundNetLog& bound_net_log)
|
| + : file_(info->save_info.file_path,
|
| + info->url(),
|
| + info->referrer_url,
|
| + info->received_bytes,
|
| calculate_hash,
|
| - save_info.hash_state,
|
| - save_info.file_stream,
|
| + info->save_info.hash_state,
|
| + info->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),
|
| - observer_(observer),
|
| 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_;
|
| }
|
|
|
| -void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
|
| -
|
| +content::DownloadInterruptReason DownloadFileImpl::Initialize() {
|
| update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>());
|
| -
|
| - 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;
|
| + net::Error result = file_.Initialize();
|
| + if (result != net::OK) {
|
| + return content::ConvertNetErrorToInterruptReason(
|
| + result, content::DOWNLOAD_INTERRUPT_FROM_DISK);
|
| }
|
|
|
| stream_reader_->RegisterCallback(
|
| base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr()));
|
|
|
| download_start_ = base::TimeTicks::Now();
|
| -
|
| // Initial pull from the straw.
|
| StreamActive();
|
|
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE, base::Bind(
|
| - callback, content::DOWNLOAD_INTERRUPT_REASON_NONE));
|
| -
|
| - ++number_active_objects_;
|
| + return content::DOWNLOAD_INTERRUPT_REASON_NONE;
|
| }
|
|
|
| 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),
|
| @@ -106,8 +91,6 @@
|
| 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.
|
| @@ -143,14 +126,6 @@
|
| }
|
|
|
| void DownloadFileImpl::Detach() {
|
| - // Done here on Windows so that anti-virus scanners invoked by
|
| - // the attachment service actually see the data; see
|
| - // http://crbug.com/127999.
|
| - // Done here for mac because we only want to do this once; see
|
| - // http://crbug.com/13120 for details.
|
| - // Other platforms don't currently do source annotation.
|
| - AnnotateWithSourceInformation();
|
| -
|
| file_.Detach();
|
| }
|
|
|
| @@ -188,6 +163,36 @@
|
| 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;
|
| @@ -256,18 +261,18 @@
|
|
|
| download_stats::RecordContiguousWriteTime(now - start);
|
|
|
| - // Take care of communication with our observer.
|
| + // Take care of communication with our controller.
|
| if (reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) {
|
| // Error case for both upstream source and file write.
|
| - // Shut down processing and signal an error to our observer.
|
| - // Our observer will clean us up.
|
| + // Shut down processing and signal an error to our controller.
|
| + // Our controller will clean us up.
|
| stream_reader_->RegisterCallback(base::Closure());
|
| weak_factory_.InvalidateWeakPtrs();
|
| SendUpdate(); // Make info up to date before error.
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&content::DownloadDestinationObserver::DestinationError,
|
| - observer_, reason));
|
| + base::Bind(&DownloadManager::OnDownloadInterrupted,
|
| + download_manager_, id_.local(), reason));
|
| } else if (state == content::ByteStreamReader::STREAM_COMPLETE) {
|
| // Signal successful completion and shut down processing.
|
| stream_reader_->RegisterCallback(base::Closure());
|
| @@ -275,12 +280,11 @@
|
| std::string hash;
|
| if (!GetHash(&hash) || file_.IsEmptyHash(hash))
|
| hash.clear();
|
| - SendUpdate();
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(
|
| - &content::DownloadDestinationObserver::DestinationCompleted,
|
| - observer_, hash));
|
| + base::Bind(&DownloadManager::OnResponseCompleted,
|
| + download_manager_, id_.local(),
|
| + BytesSoFar(), hash));
|
| }
|
| if (bound_net_log_.IsLoggingAllEvents()) {
|
| bound_net_log_.AddEvent(
|
| @@ -293,12 +297,7 @@
|
| void DownloadFileImpl::SendUpdate() {
|
| BrowserThread::PostTask(
|
| BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&content::DownloadDestinationObserver::DestinationUpdate,
|
| - observer_, BytesSoFar(), CurrentSpeed(), GetHashState()));
|
| + base::Bind(&DownloadManager::UpdateDownload,
|
| + download_manager_, id_.local(),
|
| + BytesSoFar(), CurrentSpeed(), GetHashState()));
|
| }
|
| -
|
| -// static
|
| -int content::DownloadFile::GetNumberOfDownloadFiles() {
|
| - return number_active_objects_;
|
| -}
|
| -
|
|
|