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"
12 // TODO(asanka): SaveFile should use the target directory of the save package as
13 // the default download directory when initializing |file_|.
14 // Unfortunately, as it is, constructors of SaveFile don't always
15 // have access to the SavePackage at this point.
16 SaveFile::SaveFile(const SaveFileCreateInfo
* info
, bool calculate_hash
)
17 : file_(base::FilePath(),
26 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
29 DCHECK(info
->path
.empty());
32 SaveFile::~SaveFile() {
33 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
36 DownloadInterruptReason
SaveFile::Initialize() {
37 return file_
.Initialize(base::FilePath());
40 DownloadInterruptReason
SaveFile::AppendDataToFile(const char* data
,
42 return file_
.AppendDataToFile(data
, data_len
);
45 DownloadInterruptReason
SaveFile::Rename(const base::FilePath
& full_path
) {
46 return file_
.Rename(full_path
);
49 void SaveFile::Detach() {
53 void SaveFile::Cancel() {
57 void SaveFile::Finish() {
61 void SaveFile::AnnotateWithSourceInformation() {
62 // TODO(gbillock): If this method is called, it should set the
63 // file_.SetClientGuid() method first.
64 file_
.AnnotateWithSourceInformation();
67 base::FilePath
SaveFile::FullPath() const {
68 return file_
.full_path();
71 bool SaveFile::InProgress() const {
72 return file_
.in_progress();
75 int64
SaveFile::BytesSoFar() const {
76 return file_
.bytes_so_far();
79 bool SaveFile::GetHash(std::string
* hash
) {
80 return file_
.GetHash(hash
);
83 std::string
SaveFile::DebugString() const {
84 return file_
.DebugString();
87 } // namespace content