summaryrefslogtreecommitdiffstats
path: root/content/browser/download/download_file_impl.cc
diff options
context:
space:
mode:
authorahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-16 22:31:39 +0000
committerahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-16 22:31:39 +0000
commitf6c2b53147fb1fecbad82da4993670542c4404e2 (patch)
tree860d7927148aabaae012ccc2b010937704d36b9e /content/browser/download/download_file_impl.cc
parentd8c8749b93af8d5b8b2a761313673539234680ef (diff)
downloadchromium_src-f6c2b53147fb1fecbad82da4993670542c4404e2.zip
chromium_src-f6c2b53147fb1fecbad82da4993670542c4404e2.tar.gz
chromium_src-f6c2b53147fb1fecbad82da4993670542c4404e2.tar.bz2
Created an interface for DownloadFile, for use in unit tests.
Bug=None Test=None Review URL: http://codereview.chromium.org/8372034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110377 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/download/download_file_impl.cc')
-rw-r--r--content/browser/download/download_file_impl.cc109
1 files changed, 109 insertions, 0 deletions
diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc
new file mode 100644
index 0000000..f998432
--- /dev/null
+++ b/content/browser/download/download_file_impl.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/download/download_file_impl.h"
+
+#include <string>
+
+#include "base/stringprintf.h"
+#include "content/browser/download/download_create_info.h"
+#include "content/browser/download/download_manager.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+DownloadFileImpl::DownloadFileImpl(
+ const DownloadCreateInfo* info,
+ DownloadRequestHandleInterface* request_handle,
+ DownloadManager* download_manager)
+ : file_(info->save_info.file_path,
+ info->url(),
+ info->referrer_url,
+ info->received_bytes,
+ info->save_info.file_stream),
+ id_(info->download_id),
+ request_handle_(request_handle),
+ download_manager_(download_manager) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+}
+
+DownloadFileImpl::~DownloadFileImpl() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+}
+
+// BaseFile delegated functions.
+net::Error DownloadFileImpl::Initialize(bool calculate_hash) {
+ return file_.Initialize(calculate_hash);
+}
+
+net::Error DownloadFileImpl::AppendDataToFile(const char* data,
+ size_t data_len) {
+ return file_.AppendDataToFile(data, data_len);
+}
+
+net::Error DownloadFileImpl::Rename(const FilePath& full_path) {
+ return file_.Rename(full_path);
+}
+
+void DownloadFileImpl::Detach() {
+ file_.Detach();
+}
+
+void DownloadFileImpl::Cancel() {
+ file_.Cancel();
+}
+
+void DownloadFileImpl::Finish() {
+ file_.Finish();
+}
+
+void DownloadFileImpl::AnnotateWithSourceInformation() {
+ file_.AnnotateWithSourceInformation();
+}
+
+FilePath DownloadFileImpl::FullPath() const {
+ return file_.full_path();
+}
+
+bool DownloadFileImpl::InProgress() const {
+ return file_.in_progress();
+}
+
+int64 DownloadFileImpl::BytesSoFar() const {
+ return file_.bytes_so_far();
+}
+
+bool DownloadFileImpl::GetSha256Hash(std::string* hash) {
+ return file_.GetSha256Hash(hash);
+}
+
+// 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());
+}