Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: chrome/browser/download/download_file.h

Issue 3026012: Download code cleanup: (Closed)
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/download/download_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/hash_tables.h" 14 #include "base/hash_tables.h"
15 #include "base/linked_ptr.h" 15 #include "base/linked_ptr.h"
16 #include "chrome/browser/download/download_types.h" 16 #include "chrome/browser/download/download_types.h"
17 #include "chrome/browser/power_save_blocker.h" 17 #include "chrome/browser/power_save_blocker.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 19
20 struct DownloadCreateInfo; 20 struct DownloadCreateInfo;
21 class ResourceDispatcherHost;
darin (slow to review) 2010/07/21 04:44:03 it would be nice if we limited the number of class
21 22
22 // These objects live exclusively on the download thread and handle the writing 23 // 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 // 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 // the download is 'in progress': once the download has been completed or
25 // cancelled, the DownloadFile is destroyed. 26 // cancelled, the DownloadFile is destroyed.
26 class DownloadFile { 27 class DownloadFile {
27 public: 28 public:
28 explicit DownloadFile(const DownloadCreateInfo* info); 29 explicit DownloadFile(const DownloadCreateInfo* info);
29 ~DownloadFile(); 30 ~DownloadFile();
30 31
31 bool Initialize(); 32 bool Initialize();
32 33
33 // Write a new chunk of data to the file. Returns true on success. 34 // Write a new chunk of data to the file. Returns true on success (all bytes
34 bool AppendDataToFile(const char* data, int data_len); 35 // written to the file).
36 bool AppendDataToFile(const char* data, size_t data_len);
35 37
36 // Abort the download and automatically close the file. 38 // Abort the download and automatically close the file.
37 void Cancel(); 39 void Cancel();
38 40
39 // Rename the download file. Returns 'true' if the rename was successful. 41 // Rename the download file. Returns 'true' if the rename was successful.
40 bool Rename(const FilePath& full_path); 42 bool Rename(const FilePath& full_path);
41 43
44 // Indicate that the download has finished. No new data will be received.
45 void Finish();
46
42 // Informs the OS that this file came from the internet. 47 // Informs the OS that this file came from the internet.
43 void AnnotateWithSourceInformation(); 48 void AnnotateWithSourceInformation();
44 49
50 // Cancels the download request associated with this file.
51 void CancelDownloadRequest(ResourceDispatcherHost* rdh);
52
45 // Accessors. 53 // Accessors.
46 int64 bytes_so_far() const { return bytes_so_far_; }
47 int id() const { return id_; } 54 int id() const { return id_; }
48 FilePath full_path() const { return full_path_; }
49 int child_id() const { return child_id_; }
50 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_; } 55 bool path_renamed() const { return path_renamed_; }
53 bool in_progress() const { return file_stream_ != NULL; } 56 bool in_progress() const { return file_stream_ != NULL; }
54 void set_in_progress(bool in_progress) { in_progress_ = in_progress; }
55 57
56 private: 58 private:
57 // Open or Close the OS file stream. The stream is opened in the constructor 59 // Open or Close the OS file stream. The stream is opened in the constructor
58 // based on creation information passed to it, and automatically closed in 60 // based on creation information passed to it, and automatically closed in
59 // the destructor. 61 // the destructor.
60 void Close(); 62 void Close();
61 bool Open(); 63 bool Open();
62 64
63 // OS file stream for writing 65 // OS file stream for writing
64 linked_ptr<net::FileStream> file_stream_; 66 linked_ptr<net::FileStream> file_stream_;
65 67
66 // Source URL for the file being downloaded. 68 // Source URL for the file being downloaded.
67 GURL source_url_; 69 GURL source_url_;
68 70
69 // The URL where the download was initiated. 71 // The URL where the download was initiated.
70 GURL referrer_url_; 72 GURL referrer_url_;
71 73
72 // The unique identifier for this download, assigned at creation by 74 // The unique identifier for this download, assigned at creation by
73 // the DownloadFileManager for its internal record keeping. 75 // the DownloadFileManager for its internal record keeping.
74 int id_; 76 int id_;
75 77
76 // IDs for looking up the tab we are associated with. 78 // IDs for looking up the tab we are associated with.
77 int child_id_; 79 int child_id_;
78 int render_view_id_;
79 80
80 // Handle for informing the ResourceDispatcherHost of a UI based cancel. 81 // Handle for informing the ResourceDispatcherHost of a UI based cancel.
81 int request_id_; 82 int request_id_;
82 83
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. 84 // Full path to the downloaded file.
88 FilePath full_path_; 85 FilePath full_path_;
89 86
90 // Whether the download is still using its initial temporary path. 87 // Whether the download is still using its initial temporary path.
91 bool path_renamed_; 88 bool path_renamed_;
92 89
93 // Whether the download is still receiving data.
94 bool in_progress_;
95
96 // RAII handle to keep the system from sleeping while we're downloading. 90 // RAII handle to keep the system from sleeping while we're downloading.
97 PowerSaveBlocker dont_sleep_; 91 PowerSaveBlocker dont_sleep_;
98 92
99 // The provider used to save the download data.
100 DownloadSaveInfo save_info_;
101
102 DISALLOW_COPY_AND_ASSIGN(DownloadFile); 93 DISALLOW_COPY_AND_ASSIGN(DownloadFile);
103 }; 94 };
104 95
105 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 96 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698