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

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

Issue 3127008: Preliminary work on resuming downloads whose connections have expired.
Patch Set: Waiting to send download automation error message until after other downloads are canceled. Created 10 years, 3 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
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_BASE_FILE_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_BASE_FILE_H_
6 #define CHROME_BROWSER_DOWNLOAD_BASE_FILE_H_ 6 #define CHROME_BROWSER_DOWNLOAD_BASE_FILE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/linked_ptr.h" 10 #include "base/linked_ptr.h"
11 #include "chrome/browser/power_save_blocker.h" 11 #include "chrome/browser/power_save_blocker.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 13
14 namespace net { 14 namespace net {
15 class FileStream; 15 class FileStream;
16 } 16 }
17 17
18 // File being downloaded and saved to disk. This is a base class 18 // File being downloaded and saved to disk. This is a base class
19 // for DownloadFile and SaveFile, which keep more state information. 19 // for DownloadFile and SaveFile, which keep more state information.
20 class BaseFile { 20 class BaseFile {
21 public: 21 public:
22 BaseFile(const FilePath& full_path, 22 BaseFile(const FilePath& full_path,
23 const GURL& source_url, 23 const GURL& source_url,
24 const GURL& referrer_url, 24 const GURL& referrer_url,
25 int64 received_bytes, 25 int64 received_bytes,
26 const linked_ptr<net::FileStream>& file_stream); 26 const linked_ptr<net::FileStream>& file_stream);
27 ~BaseFile(); 27 ~BaseFile();
28 28
29 bool Initialize(); 29 bool Initialize();
30 bool ReOpen();
Paweł Hajdan Jr. 2010/10/01 09:03:55 Please add comment.
30 31
31 // Write a new chunk of data to the file. Returns true on success (all bytes 32 // Write a new chunk of data to the file. Returns true on success (all bytes
32 // written to the file). 33 // written to the file).
33 bool AppendDataToFile(const char* data, size_t data_len); 34 bool AppendDataToFile(const char* data, size_t data_len);
34 35
35 // Rename the download file. Returns true on success. 36 // Rename the download file. Returns true on success.
36 // |path_renamed_| is set to true only if |is_final_rename| is true. 37 // |path_renamed_| is set to true only if |is_final_rename| is true.
37 // Marked virtual for testing. 38 // Marked virtual for testing.
38 virtual bool Rename(const FilePath& full_path, bool is_final_rename); 39 virtual bool Rename(const FilePath& full_path, bool is_final_rename);
39 40
40 // Abort the download and automatically close the file. 41 // Abort the download and automatically close the file.
41 void Cancel(); 42 void Cancel();
42 43
43 // Indicate that the download has finished. No new data will be received. 44 // Indicate that the download has finished. No new data will be received.
44 void Finish(); 45 void Finish();
45 46
46 // Informs the OS that this file came from the internet. 47 // Informs the OS that this file came from the internet.
47 void AnnotateWithSourceInformation(); 48 void AnnotateWithSourceInformation();
48 49
49 FilePath full_path() const { return full_path_; } 50 FilePath full_path() const { return full_path_; }
50 bool path_renamed() const { return path_renamed_; } 51 bool path_renamed() const { return path_renamed_; }
51 bool in_progress() const { return file_stream_ != NULL; } 52 bool in_progress() const { return file_stream_ != NULL; }
52 int64 bytes_so_far() const { return bytes_so_far_; } 53 int64 bytes_so_far() const { return bytes_so_far_; }
53 54
55 // Determines if this DownloadItem matches the |url| and |path|.
56 bool MatchesUrlAndPath(const GURL& url, const FilePath& path) const;
Paweł Hajdan Jr. 2010/10/01 09:03:55 This is wrong, as said in http://codereview.chromi
57
54 protected: 58 protected:
55 bool Open(); 59 bool Open();
56 void Close(); 60 void Close();
57 61
58 // Full path to the file including the file name. 62 // Full path to the file including the file name.
59 FilePath full_path_; 63 FilePath full_path_;
60 64
61 // Whether the download is still using its initial temporary path. 65 // Whether the download is still using its initial temporary path.
62 bool path_renamed_; 66 bool path_renamed_;
63 67
(...skipping 10 matching lines...) Expand all
74 // Amount of data received up so far, in bytes. 78 // Amount of data received up so far, in bytes.
75 int64 bytes_so_far_; 79 int64 bytes_so_far_;
76 80
77 // RAII handle to keep the system from sleeping while we're downloading. 81 // RAII handle to keep the system from sleeping while we're downloading.
78 PowerSaveBlocker power_save_blocker_; 82 PowerSaveBlocker power_save_blocker_;
79 83
80 DISALLOW_COPY_AND_ASSIGN(BaseFile); 84 DISALLOW_COPY_AND_ASSIGN(BaseFile);
81 }; 85 };
82 86
83 #endif // CHROME_BROWSER_DOWNLOAD_BASE_FILE_H_ 87 #endif // CHROME_BROWSER_DOWNLOAD_BASE_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698