1 // Copyright (c) 2012 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.
5 #include "content/browser/download/save_file.h"
7 #include "base/logging.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "net/base/file_stream.h"
13 // TODO(asanka): SaveFile should use the target directory of the save package as
14 // the default download directory when initializing |file_|.
15 // Unfortunately, as it is, constructors of SaveFile don't always
16 // have access to the SavePackage at this point.
17 SaveFile::SaveFile(const SaveFileCreateInfo
* info
, bool calculate_hash
)
18 : file_(base::FilePath(),
24 scoped_ptr
<net::FileStream
>(),
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
30 DCHECK(info
->path
.empty());
33 SaveFile::~SaveFile() {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
37 DownloadInterruptReason
SaveFile::Initialize() {
38 return file_
.Initialize(base::FilePath());
41 DownloadInterruptReason
SaveFile::AppendDataToFile(const char* data
,
43 return file_
.AppendDataToFile(data
, data_len
);
46 DownloadInterruptReason
SaveFile::Rename(const base::FilePath
& full_path
) {
47 return file_
.Rename(full_path
);
50 void SaveFile::Detach() {
54 void SaveFile::Cancel() {
58 void SaveFile::Finish() {
62 void SaveFile::AnnotateWithSourceInformation() {
63 file_
.AnnotateWithSourceInformation();
66 base::FilePath
SaveFile::FullPath() const {
67 return file_
.full_path();
70 bool SaveFile::InProgress() const {
71 return file_
.in_progress();
74 int64
SaveFile::BytesSoFar() const {
75 return file_
.bytes_so_far();
78 bool SaveFile::GetHash(std::string
* hash
) {
79 return file_
.GetHash(hash
);
82 std::string
SaveFile::DebugString() const {
83 return file_
.DebugString();
86 } // namespace content