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