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

Unified Diff: content/browser/download/download_file_impl.cc

Issue 10912173: Replace the DownloadFileManager with direct ownership of DownloadFileImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR (r162700) Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/download_file_impl.h ('k') | content/browser/download/download_file_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9ab0557f5b2cf786e8cfb77a25a8d9eeea8c931f..102081668d7868ca7ac728a4d8ced0877f846d7f 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_observer.h"
#include "content/browser/download/download_stats.h"
#include "net/base/io_buffer.h"
@@ -27,46 +27,52 @@ using content::DownloadManager;
const int kUpdatePeriodMs = 500;
const int kMaxTimeBlockingFileThreadMs = 1000;
+int content::DownloadFile::number_active_objects_ = 0;
+
DownloadFileImpl::DownloadFileImpl(
- scoped_ptr<DownloadCreateInfo> info,
- scoped_ptr<content::ByteStreamReader> stream,
- scoped_ptr<DownloadRequestHandleInterface> request_handle,
- scoped_refptr<DownloadManager> download_manager,
+ scoped_ptr<content::DownloadSaveInfo> save_info,
+ const FilePath& default_download_directory,
+ 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::DownloadDestinationObserver> observer)
+ : file_(save_info->file_path,
+ url,
+ referrer_url,
+ received_bytes,
calculate_hash,
- info->save_info->hash_state,
- info->save_info->file_stream.Pass(),
+ save_info->hash_state,
+ save_info->file_stream.Pass(),
bound_net_log),
+ default_download_directory_(default_download_directory),
stream_reader_(stream.Pass()),
- id_(info->download_id),
- default_download_directory_(info->default_download_directory),
- request_handle_(request_handle.Pass()),
- 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_;
}
-content::DownloadInterruptReason DownloadFileImpl::Initialize() {
+void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>());
net::Error net_result = file_.Initialize(default_download_directory_);
if (net_result != net::OK) {
- return content::ConvertNetErrorToInterruptReason(
- net_result, content::DOWNLOAD_INTERRUPT_FROM_DISK);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE, base::Bind(
+ callback, content::ConvertNetErrorToInterruptReason(
+ net_result, content::DOWNLOAD_INTERRUPT_FROM_DISK)));
+ return;
}
stream_reader_->RegisterCallback(
@@ -77,11 +83,17 @@ content::DownloadInterruptReason DownloadFileImpl::Initialize() {
// 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),
@@ -95,6 +107,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.
@@ -176,36 +190,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;
@@ -274,18 +258,18 @@ void DownloadFileImpl::StreamActive() {
download_stats::RecordContiguousWriteTime(now - start);
- // Take care of communication with our controller.
+ // Take care of communication with our observer.
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 controller.
- // Our controller will clean us up.
+ // Shut down processing and signal an error to our observer.
+ // Our observer 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(&DownloadManager::OnDownloadInterrupted,
- download_manager_, id_.local(), reason));
+ base::Bind(&content::DownloadDestinationObserver::DestinationError,
+ observer_, reason));
} else if (state == content::ByteStreamReader::STREAM_COMPLETE) {
// Signal successful completion and shut down processing.
stream_reader_->RegisterCallback(base::Closure());
@@ -293,11 +277,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::DownloadDestinationObserver::DestinationCompleted,
+ observer_, hash));
}
if (bound_net_log_.IsLoggingAllEvents()) {
bound_net_log_.AddEvent(
@@ -310,7 +295,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::DownloadDestinationObserver::DestinationUpdate,
+ observer_, BytesSoFar(), CurrentSpeed(), GetHashState()));
}
+
+// static
+int content::DownloadFile::GetNumberOfDownloadFiles() {
+ return number_active_objects_;
+}
+
« no previous file with comments | « content/browser/download/download_file_impl.h ('k') | content/browser/download/download_file_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698