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.
4
5#include "content/browser/download/save_file.h"
6
7#include "base/logging.h"
8#include "content/public/browser/browser_thread.h"
9#include "net/base/file_stream.h"
10
11namespace content {
12
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.
17SaveFile::SaveFile(const SaveFileCreateInfo* info, bool calculate_hash)
18    : file_(base::FilePath(),
19            info->url,
20            GURL(),
21            0,
22            calculate_hash,
23            std::string(),
24            scoped_ptr<net::FileStream>(),
25            net::BoundNetLog()),
26      info_(info) {
27  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
28
29  DCHECK(info);
30  DCHECK(info->path.empty());
31}
32
33SaveFile::~SaveFile() {
34  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
35}
36
37DownloadInterruptReason SaveFile::Initialize() {
38  return file_.Initialize(base::FilePath());
39}
40
41DownloadInterruptReason SaveFile::AppendDataToFile(const char* data,
42                                                   size_t data_len) {
43  return file_.AppendDataToFile(data, data_len);
44}
45
46DownloadInterruptReason SaveFile::Rename(const base::FilePath& full_path) {
47  return file_.Rename(full_path);
48}
49
50void SaveFile::Detach() {
51  file_.Detach();
52}
53
54void SaveFile::Cancel() {
55  file_.Cancel();
56}
57
58void SaveFile::Finish() {
59  file_.Finish();
60}
61
62void SaveFile::AnnotateWithSourceInformation() {
63  // TODO(gbillock): If this method is called, it should set the
64  // file_.SetClientGuid() method first.
65  file_.AnnotateWithSourceInformation();
66}
67
68base::FilePath SaveFile::FullPath() const {
69  return file_.full_path();
70}
71
72bool SaveFile::InProgress() const {
73  return file_.in_progress();
74}
75
76int64 SaveFile::BytesSoFar() const {
77  return file_.bytes_so_far();
78}
79
80bool SaveFile::GetHash(std::string* hash) {
81  return file_.GetHash(hash);
82}
83
84std::string SaveFile::DebugString() const {
85  return file_.DebugString();
86}
87
88}  // namespace content
89