blob: 97057a6d7cb769428af44cf7c59564acfe6d3b4d [file] [log] [blame]
[email protected]6c69796d2010-07-16 21:41:161// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]e93d28232009-01-30 05:59:595#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
6#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]f5c016b2009-06-16 17:12:318#include <map>
[email protected]be180c802009-10-23 06:33:319#include <string>
initial.commit09911bf2008-07-26 23:55:2910#include <vector>
11
initial.commit09911bf2008-07-26 23:55:2912#include "base/basictypes.h"
[email protected]f5c016b2009-06-16 17:12:3113#include "base/file_path.h"
[email protected]23144032008-09-08 20:51:3014#include "base/hash_tables.h"
[email protected]8af9d032010-02-10 00:00:3215#include "base/linked_ptr.h"
[email protected]6c69796d2010-07-16 21:41:1616#include "chrome/browser/download/download_types.h"
[email protected]36e93a772009-10-23 04:18:0517#include "chrome/browser/power_save_blocker.h"
[email protected]f5c016b2009-06-16 17:12:3118#include "googleurl/src/gurl.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]f5c016b2009-06-16 17:12:3120struct DownloadCreateInfo;
initial.commit09911bf2008-07-26 23:55:2921
22// These objects live exclusively on the download thread and handle the writing
23// operations for one download. These objects live only for the duration that
24// the download is 'in progress': once the download has been completed or
25// cancelled, the DownloadFile is destroyed.
26class DownloadFile {
27 public:
[email protected]11f4857282009-11-13 19:56:1728 explicit DownloadFile(const DownloadCreateInfo* info);
initial.commit09911bf2008-07-26 23:55:2929 ~DownloadFile();
30
31 bool Initialize();
32
33 // Write a new chunk of data to the file. Returns true on success.
34 bool AppendDataToFile(const char* data, int data_len);
35
36 // Abort the download and automatically close the file.
37 void Cancel();
38
39 // Rename the download file. Returns 'true' if the rename was successful.
[email protected]7ae7c2cb2009-01-06 23:31:4140 bool Rename(const FilePath& full_path);
initial.commit09911bf2008-07-26 23:55:2941
[email protected]df72c092009-09-10 19:56:1742 // Informs the OS that this file came from the internet.
43 void AnnotateWithSourceInformation();
44
initial.commit09911bf2008-07-26 23:55:2945 // Accessors.
46 int64 bytes_so_far() const { return bytes_so_far_; }
47 int id() const { return id_; }
[email protected]7ae7c2cb2009-01-06 23:31:4148 FilePath full_path() const { return full_path_; }
[email protected]76543b92009-08-31 17:27:4549 int child_id() const { return child_id_; }
initial.commit09911bf2008-07-26 23:55:2950 int render_view_id() const { return render_view_id_; }
51 int request_id() const { return request_id_; }
52 bool path_renamed() const { return path_renamed_; }
[email protected]8af9d032010-02-10 00:00:3253 bool in_progress() const { return file_stream_ != NULL; }
initial.commit09911bf2008-07-26 23:55:2954 void set_in_progress(bool in_progress) { in_progress_ = in_progress; }
55
56 private:
[email protected]8af9d032010-02-10 00:00:3257 // Open or Close the OS file stream. The stream is opened in the constructor
initial.commit09911bf2008-07-26 23:55:2958 // based on creation information passed to it, and automatically closed in
59 // the destructor.
60 void Close();
[email protected]8af9d032010-02-10 00:00:3261 bool Open();
initial.commit09911bf2008-07-26 23:55:2962
[email protected]8af9d032010-02-10 00:00:3263 // OS file stream for writing
64 linked_ptr<net::FileStream> file_stream_;
initial.commit09911bf2008-07-26 23:55:2965
[email protected]8ef06372009-04-27 21:11:3466 // Source URL for the file being downloaded.
67 GURL source_url_;
68
69 // The URL where the download was initiated.
70 GURL referrer_url_;
71
initial.commit09911bf2008-07-26 23:55:2972 // The unique identifier for this download, assigned at creation by
73 // the DownloadFileManager for its internal record keeping.
74 int id_;
75
76 // IDs for looking up the tab we are associated with.
[email protected]76543b92009-08-31 17:27:4577 int child_id_;
initial.commit09911bf2008-07-26 23:55:2978 int render_view_id_;
79
80 // Handle for informing the ResourceDispatcherHost of a UI based cancel.
81 int request_id_;
82
83 // Amount of data received up to this point. We may not know in advance how
84 // much data to expect since some servers don't provide that information.
85 int64 bytes_so_far_;
86
87 // Full path to the downloaded file.
[email protected]7ae7c2cb2009-01-06 23:31:4188 FilePath full_path_;
initial.commit09911bf2008-07-26 23:55:2989
90 // Whether the download is still using its initial temporary path.
91 bool path_renamed_;
92
93 // Whether the download is still receiving data.
94 bool in_progress_;
95
[email protected]36e93a772009-10-23 04:18:0596 // RAII handle to keep the system from sleeping while we're downloading.
97 PowerSaveBlocker dont_sleep_;
98
[email protected]8af9d032010-02-10 00:00:3299 // The provider used to save the download data.
100 DownloadSaveInfo save_info_;
101
[email protected]e93d28232009-01-30 05:59:59102 DISALLOW_COPY_AND_ASSIGN(DownloadFile);
initial.commit09911bf2008-07-26 23:55:29103};
104
[email protected]e93d28232009-01-30 05:59:59105#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_