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

Side by Side Diff: content/browser/download/download_file_impl.cc

Issue 8372034: Created an interface for DownloadFile, for use in unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up download file interface and unit test class. Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/download/download_file_impl.h"
6
7 #include <string>
8
9 #include "base/stringprintf.h"
10 #include "content/browser/download/download_create_info.h"
11 #include "content/browser/download/download_manager.h"
12 #include "content/public/browser/browser_thread.h"
13
14 using content::BrowserThread;
15
16 DownloadFileImpl::DownloadFileImpl(
17 const DownloadCreateInfo* info,
18 DownloadRequestHandleInterface* request_handle,
19 DownloadManager* download_manager)
20 : file_(info->save_info.file_path,
21 info->url(),
22 info->referrer_url,
23 info->received_bytes,
24 info->save_info.file_stream),
25 id_(info->download_id),
26 request_handle_(request_handle),
27 download_manager_(download_manager) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
29 }
30
31 DownloadFileImpl::~DownloadFileImpl() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
33 }
34
35 // BaseFile delegated functions.
36 net::Error DownloadFileImpl::Initialize(bool calculate_hash) {
37 return file_.Initialize(calculate_hash);
38 }
39
40 net::Error DownloadFileImpl::AppendDataToFile(const char* data,
41 size_t data_len) {
42 return file_.AppendDataToFile(data, data_len);
43 }
44
45 net::Error DownloadFileImpl::Rename(const FilePath& full_path) {
46 return file_.Rename(full_path);
47 }
48
49 void DownloadFileImpl::Detach() {
50 file_.Detach();
51 }
52
53 void DownloadFileImpl::Cancel() {
54 file_.Cancel();
55 }
56
57 void DownloadFileImpl::Finish() {
58 file_.Finish();
59 }
60
61 void DownloadFileImpl::AnnotateWithSourceInformation() {
62 file_.AnnotateWithSourceInformation();
63 }
64
65 FilePath DownloadFileImpl::FullPath() const {
66 return file_.full_path();
67 }
68
69 bool DownloadFileImpl::InProgress() const {
70 return file_.in_progress();
71 }
72
73 int64 DownloadFileImpl::BytesSoFar() const {
74 return file_.bytes_so_far();
75 }
76
77 bool DownloadFileImpl::GetSha256Hash(std::string* hash) {
78 return file_.GetSha256Hash(hash);
79 }
80
81 // DownloadFileInterface implementation.
82 void DownloadFileImpl::CancelDownloadRequest() {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
84 request_handle_->CancelRequest();
85 }
86
87 int DownloadFileImpl::Id() const {
88 return id_.local();
89 }
90
91 DownloadManager* DownloadFileImpl::GetDownloadManager() {
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
93 return download_manager_.get();
94 }
95
96 const DownloadId& DownloadFileImpl::GlobalId() const {
97 return id_;
98 }
99
100 std::string DownloadFileImpl::DebugString() const {
101 return base::StringPrintf("{"
102 " id_ = " "%d"
103 " request_handle = %s"
104 " Base File = %s"
105 " }",
106 id_.local(),
107 request_handle_->DebugString().c_str(),
108 file_.DebugString().c_str());
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698