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

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

Issue 10799005: Replace the DownloadFileManager with direct ownership (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to LKGR. Created 8 years, 4 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 | « content/browser/download/base_file.cc ('k') | content/browser/download/download_file_factory.h » ('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_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 <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/download_id.h"
15 #include "content/public/browser/download_interrupt_reasons.h" 14 #include "content/public/browser/download_interrupt_reasons.h"
16 15
17 namespace content { 16 namespace content {
18 17
19 class DownloadManager; 18 class DownloadManager;
20 19
21 // These objects live exclusively on the file thread and handle the writing 20 // 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 21 // 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 22 // the download is 'in progress': once the download has been completed or
24 // cancelled, the DownloadFile is destroyed. 23 // cancelled, the DownloadFile is destroyed.
25 class CONTENT_EXPORT DownloadFile { 24 class CONTENT_EXPORT DownloadFile {
26 public: 25 public:
26 // Callback used with Initialize. On a successful initialize, |reason| will
27 // be DOWNLOAD_INTERRUPT_REASON_NONE; on a failed initialize, it will be
28 // set to the reason for the failure.
29 typedef base::Callback<void(content::DownloadInterruptReason reason)>
30 InitializeCallback;
31
27 // Callback used with Rename(). On a successful rename |reason| will be 32 // Callback used with Rename(). On a successful rename |reason| will be
28 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename 33 // DOWNLOAD_INTERRUPT_REASON_NONE and |path| the path the rename
29 // was done to. On a failed rename, |reason| will contain the 34 // was done to. On a failed rename, |reason| will contain the
30 // error. 35 // error.
31 typedef base::Callback<void(content::DownloadInterruptReason reason, 36 typedef base::Callback<void(content::DownloadInterruptReason reason,
32 const FilePath& path)> RenameCompletionCallback; 37 const FilePath& path)> RenameCompletionCallback;
33 38
34 virtual ~DownloadFile() {} 39 virtual ~DownloadFile() {}
35 40
36 // If calculate_hash is true, sha256 hash will be calculated.
37 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network 41 // Returns DOWNLOAD_INTERRUPT_REASON_NONE on success, or a network
38 // error code on failure. 42 // error code on failure. Upon completion, |callback| will be
39 virtual DownloadInterruptReason Initialize() = 0; 43 // called on the UI thread as per the comment above.
44 virtual void Initialize(const InitializeCallback& callback) = 0;
40 45
41 // Rename the download file to |full_path|. If that file exists and 46 // Rename the download file to |full_path|. If that file exists and
42 // |overwrite_existing_file| is false, |full_path| will be uniquified by 47 // |overwrite_existing_file| is false, |full_path| will be uniquified by
43 // suffixing " (<number>)" to the file name before the extension. 48 // suffixing " (<number>)" to the file name before the extension.
44 // Upon completion, |callback| will be called on the UI thread 49 // Upon completion, |callback| will be called on the UI thread
45 // as per the comment above. 50 // as per the comment above.
46 virtual void Rename(const FilePath& full_path, 51 virtual void Rename(const FilePath& full_path,
47 bool overwrite_existing_file, 52 bool overwrite_existing_file,
48 const RenameCompletionCallback& callback) = 0; 53 const RenameCompletionCallback& callback) = 0;
49 54
(...skipping 11 matching lines...) Expand all
61 virtual int64 BytesSoFar() const = 0; 66 virtual int64 BytesSoFar() const = 0;
62 virtual int64 CurrentSpeed() const = 0; 67 virtual int64 CurrentSpeed() const = 0;
63 68
64 // Set |hash| with sha256 digest for the file. 69 // Set |hash| with sha256 digest for the file.
65 // Returns true if digest is successfully calculated. 70 // Returns true if digest is successfully calculated.
66 virtual bool GetHash(std::string* hash) = 0; 71 virtual bool GetHash(std::string* hash) = 0;
67 72
68 // Returns the current (intermediate) state of the hash as a byte string. 73 // Returns the current (intermediate) state of the hash as a byte string.
69 virtual std::string GetHashState() = 0; 74 virtual std::string GetHashState() = 0;
70 75
71 // Cancels the download request associated with this file. 76 // For testing. Must be called on FILE thread.
72 virtual void CancelDownloadRequest() = 0; 77 static int GetNumberOfDownloadFiles();
73 78
74 virtual int Id() const = 0; 79 protected:
75 virtual DownloadManager* GetDownloadManager() = 0; 80 static int number_active_objects_;
76 virtual const DownloadId& GlobalId() const = 0;
77
78 virtual std::string DebugString() const = 0;
79 }; 81 };
80 82
81 } // namespace content 83 } // namespace content
82 84
83 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 85 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
OLDNEW
« no previous file with comments | « content/browser/download/base_file.cc ('k') | content/browser/download/download_file_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698