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

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

Issue 319603003: [Downloads] Retry renames after transient failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Prepare to reland after XP test fix. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/download/base_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) 2012 The Chromium Authors. All rights reserved. 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 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 CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // |default_directory| and |full_path()| are empty, then a temporary file will 49 // |default_directory| and |full_path()| are empty, then a temporary file will
50 // be created in the default download location as determined by 50 // be created in the default download location as determined by
51 // ContentBrowserClient. 51 // ContentBrowserClient.
52 DownloadInterruptReason Initialize(const base::FilePath& default_directory); 52 DownloadInterruptReason Initialize(const base::FilePath& default_directory);
53 53
54 // Write a new chunk of data to the file. Returns a DownloadInterruptReason 54 // Write a new chunk of data to the file. Returns a DownloadInterruptReason
55 // indicating the result of the operation. 55 // indicating the result of the operation.
56 DownloadInterruptReason AppendDataToFile(const char* data, size_t data_len); 56 DownloadInterruptReason AppendDataToFile(const char* data, size_t data_len);
57 57
58 // Rename the download file. Returns a DownloadInterruptReason indicating the 58 // Rename the download file. Returns a DownloadInterruptReason indicating the
59 // result of the operation. 59 // result of the operation. A return code of NONE indicates that the rename
60 // was successful. After a failure, the full_path() and in_progress() can be
61 // used to determine the last known filename and whether the file is available
62 // for writing or retrying the rename.
60 virtual DownloadInterruptReason Rename(const base::FilePath& full_path); 63 virtual DownloadInterruptReason Rename(const base::FilePath& full_path);
61 64
62 // Detach the file so it is not deleted on destruction. 65 // Detach the file so it is not deleted on destruction.
63 virtual void Detach(); 66 virtual void Detach();
64 67
65 // Abort the download and automatically close the file. 68 // Abort the download and automatically close the file.
66 void Cancel(); 69 void Cancel();
67 70
68 // Indicate that the download has finished. No new data will be received. 71 // Indicate that the download has finished. No new data will be received.
69 void Finish(); 72 void Finish();
70 73
71 // Set the client guid which will be used to identify the app to the 74 // Set the client guid which will be used to identify the app to the
72 // system AV scanning function. Should be called before 75 // system AV scanning function. Should be called before
73 // AnnotateWithSourceInformation() to take effect. 76 // AnnotateWithSourceInformation() to take effect.
74 void SetClientGuid(const std::string& guid); 77 void SetClientGuid(const std::string& guid);
75 78
76 // Informs the OS that this file came from the internet. Returns a 79 // Informs the OS that this file came from the internet. Returns a
77 // DownloadInterruptReason indicating the result of the operation. 80 // DownloadInterruptReason indicating the result of the operation.
78 // Note: SetClientGuid() should be called before this function on 81 // Note: SetClientGuid() should be called before this function on
79 // Windows to ensure the correct app client ID is available. 82 // Windows to ensure the correct app client ID is available.
80 DownloadInterruptReason AnnotateWithSourceInformation(); 83 DownloadInterruptReason AnnotateWithSourceInformation();
81 84
82 base::FilePath full_path() const { return full_path_; } 85 // Returns the last known path to the download file. Can be empty if there's
86 // no file.
87 const base::FilePath& full_path() const { return full_path_; }
88
89 // Returns true if the file is open. If true, the file can be written to or
90 // renamed.
83 bool in_progress() const { return file_.IsValid(); } 91 bool in_progress() const { return file_.IsValid(); }
92
93 // Returns the number of bytes in the file pointed to by full_path().
84 int64 bytes_so_far() const { return bytes_so_far_; } 94 int64 bytes_so_far() const { return bytes_so_far_; }
85 95
86 // Fills |hash| with the hash digest for the file. 96 // Fills |hash| with the hash digest for the file.
87 // Returns true if digest is successfully calculated. 97 // Returns true if digest is successfully calculated.
88 virtual bool GetHash(std::string* hash); 98 virtual bool GetHash(std::string* hash);
89 99
90 // Returns the current (intermediate) state of the hash as a byte string. 100 // Returns the current (intermediate) state of the hash as a byte string.
91 virtual std::string GetHashState(); 101 virtual std::string GetHashState();
92 102
93 // Returns true if the given hash is considered empty. An empty hash is 103 // Returns true if the given hash is considered empty. An empty hash is
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool detached_; 180 bool detached_;
171 181
172 net::BoundNetLog bound_net_log_; 182 net::BoundNetLog bound_net_log_;
173 183
174 DISALLOW_COPY_AND_ASSIGN(BaseFile); 184 DISALLOW_COPY_AND_ASSIGN(BaseFile);
175 }; 185 };
176 186
177 } // namespace content 187 } // namespace content
178 188
179 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 189 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/base_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698