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

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

Issue 2712713007: Make DownloadFileImpl handle multiple byte streams. (Closed)
Patch Set: Export the new class for linking on windows. Created 3 years, 10 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) 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_DOWNLOAD_FILE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
qinmin 2017/02/27 18:55:29 remove these newly added includes
xingliu 2017/02/28 00:57:06 Done. <memory> is kept for compiling.
10 #include <string> 11 #include <string>
12 #include <unordered_map>
11 13
12 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
13 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
14 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
15 #include "content/public/browser/download_interrupt_reasons.h" 17 #include "content/public/browser/download_interrupt_reasons.h"
16 18
17 class GURL; 19 class GURL;
18 20
19 namespace content { 21 namespace content {
20 22
23 class ByteStreamReader;
24
21 // These objects live exclusively on the file thread and handle the writing 25 // These objects live exclusively on the file thread and handle the writing
22 // operations for one download. These objects live only for the duration that 26 // operations for one download. These objects live only for the duration that
23 // the download is 'in progress': once the download has been completed or 27 // the download is 'in progress': once the download has been completed or
24 // cancelled, the DownloadFile is destroyed. 28 // cancelled, the DownloadFile is destroyed.
25 class CONTENT_EXPORT DownloadFile { 29 class CONTENT_EXPORT DownloadFile {
26 public: 30 public:
27 // Callback used with Initialize. On a successful initialize, |reason| will 31 // Callback used with Initialize. On a successful initialize, |reason| will
28 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be 32 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be
29 // set to the reason for the failure. 33 // set to the reason for the failure.
30 typedef base::Callback<void(DownloadInterruptReason reason)> 34 typedef base::Callback<void(DownloadInterruptReason reason)>
31 InitializeCallback; 35 InitializeCallback;
32 36
33 // Callback used with Rename*(). On a successful rename |reason| will be 37 // Callback used with Rename*(). On a successful rename |reason| will be
34 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename 38 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename
35 // was done to. On a failed rename, |reason| will contain the 39 // was done to. On a failed rename, |reason| will contain the
36 // error. 40 // error.
37 typedef base::Callback<void(DownloadInterruptReason reason, 41 typedef base::Callback<void(DownloadInterruptReason reason,
38 const base::FilePath& path)> 42 const base::FilePath& path)>
39 RenameCompletionCallback; 43 RenameCompletionCallback;
40 44
41 virtual ~DownloadFile() {} 45 virtual ~DownloadFile() {}
42 46
43 // Upon completion, |callback| will be called on the UI 47 // Upon completion, |callback| will be called on the UI
44 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE 48 // thread as per the comment above, passing DOWNLOAD_INTERRUPT_REASON_NONE
45 // on success, or a network download interrupt reason on failure. 49 // on success, or a network download interrupt reason on failure.
46 virtual void Initialize(const InitializeCallback& callback) = 0; 50 virtual void Initialize(const InitializeCallback& callback) = 0;
47 51
52 // Add a byte stream reader to write into a slice of the file, used for
53 // parallel download.
54 virtual void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
55 int64_t offset) = 0;
56
48 // Rename the download file to |full_path|. If that file exists 57 // Rename the download file to |full_path|. If that file exists
49 // |full_path| will be uniquified by suffixing " (<number>)" to the 58 // |full_path| will be uniquified by suffixing " (<number>)" to the
50 // file name before the extension. 59 // file name before the extension.
51 virtual void RenameAndUniquify(const base::FilePath& full_path, 60 virtual void RenameAndUniquify(const base::FilePath& full_path,
52 const RenameCompletionCallback& callback) = 0; 61 const RenameCompletionCallback& callback) = 0;
53 62
54 // Rename the download file to |full_path| and annotate it with 63 // Rename the download file to |full_path| and annotate it with
55 // "Mark of the Web" information about its source. No uniquification 64 // "Mark of the Web" information about its source. No uniquification
56 // will be performed. 65 // will be performed.
57 virtual void RenameAndAnnotate(const base::FilePath& full_path, 66 virtual void RenameAndAnnotate(const base::FilePath& full_path,
58 const std::string& client_guid, 67 const std::string& client_guid,
59 const GURL& source_url, 68 const GURL& source_url,
60 const GURL& referrer_url, 69 const GURL& referrer_url,
61 const RenameCompletionCallback& callback) = 0; 70 const RenameCompletionCallback& callback) = 0;
62 71
63 // Detach the file so it is not deleted on destruction. 72 // Detach the file so it is not deleted on destruction.
64 virtual void Detach() = 0; 73 virtual void Detach() = 0;
65 74
66 // Abort the download and automatically close the file. 75 // Abort the download and automatically close the file.
67 virtual void Cancel() = 0; 76 virtual void Cancel() = 0;
68 77
69 virtual const base::FilePath& FullPath() const = 0; 78 virtual const base::FilePath& FullPath() const = 0;
70 virtual bool InProgress() const = 0; 79 virtual bool InProgress() const = 0;
71 }; 80 };
72 81
73 } // namespace content 82 } // namespace content
74 83
75 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 84 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698