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

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

Issue 10950015: Shift "commit point" for when a download will no longer accept cancels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments. Created 8 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 | Annotate | Revision Log
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 // The DownloadFileManager owns a set of DownloadFile objects, each of which 5 // The DownloadFileManager owns a set of DownloadFile objects, each of which
6 // represent one in progress download and performs the disk IO for that 6 // represent one in progress download and performs the disk IO for that
7 // download. The DownloadFileManager itself is a singleton object owned by the 7 // download. The DownloadFileManager itself is a singleton object owned by the
8 // ResourceDispatcherHostImpl. 8 // ResourceDispatcherHostImpl.
9 // 9 //
10 // The DownloadFileManager uses the file_thread for performing file write 10 // The DownloadFileManager uses the file_thread for performing file write
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 #include "base/atomic_sequence_num.h" 44 #include "base/atomic_sequence_num.h"
45 #include "base/basictypes.h" 45 #include "base/basictypes.h"
46 #include "base/callback_forward.h" 46 #include "base/callback_forward.h"
47 #include "base/gtest_prod_util.h" 47 #include "base/gtest_prod_util.h"
48 #include "base/hash_tables.h" 48 #include "base/hash_tables.h"
49 #include "base/memory/ref_counted.h" 49 #include "base/memory/ref_counted.h"
50 #include "base/memory/scoped_ptr.h" 50 #include "base/memory/scoped_ptr.h"
51 #include "base/timer.h" 51 #include "base/timer.h"
52 #include "content/browser/download/download_file.h" 52 #include "content/browser/download/download_file.h"
53 #include "content/browser/download/download_file_factory.h"
53 #include "content/common/content_export.h" 54 #include "content/common/content_export.h"
54 #include "content/public/browser/download_id.h" 55 #include "content/public/browser/download_id.h"
55 #include "content/public/browser/download_interrupt_reasons.h" 56 #include "content/public/browser/download_interrupt_reasons.h"
56 #include "net/base/net_errors.h" 57 #include "net/base/net_errors.h"
57 #include "ui/gfx/native_widget_types.h" 58 #include "ui/gfx/native_widget_types.h"
58 59
59 struct DownloadCreateInfo; 60 struct DownloadCreateInfo;
60 class DownloadRequestHandle; 61 class DownloadRequestHandle;
61 class FilePath; 62 class FilePath;
62 63
(...skipping 15 matching lines...) Expand all
78 public: 79 public:
79 // Callback used with CreateDownloadFile(). |reason| will be 80 // Callback used with CreateDownloadFile(). |reason| will be
80 // DOWNLOAD_INTERRUPT_REASON_NONE on a successful creation. 81 // DOWNLOAD_INTERRUPT_REASON_NONE on a successful creation.
81 typedef base::Callback<void(content::DownloadInterruptReason reason)> 82 typedef base::Callback<void(content::DownloadInterruptReason reason)>
82 CreateDownloadFileCallback; 83 CreateDownloadFileCallback;
83 84
84 // Callback used with RenameDownloadFile(). 85 // Callback used with RenameDownloadFile().
85 typedef content::DownloadFile::RenameCompletionCallback 86 typedef content::DownloadFile::RenameCompletionCallback
86 RenameCompletionCallback; 87 RenameCompletionCallback;
87 88
88 class DownloadFileFactory {
89 public:
90 virtual ~DownloadFileFactory() {}
91
92 virtual content::DownloadFile* CreateFile(
93 DownloadCreateInfo* info,
94 scoped_ptr<content::ByteStreamReader> stream,
95 content::DownloadManager* download_manager,
96 bool calculate_hash,
97 const net::BoundNetLog& bound_net_log) = 0;
98 };
99
100 // Takes ownership of the factory. 89 // Takes ownership of the factory.
101 // Passing in a NULL for |factory| will cause a default 90 // Passing in a NULL for |factory| will cause a default
102 // |DownloadFileFactory| to be used. 91 // |DownloadFileFactory| to be used.
103 explicit DownloadFileManager(DownloadFileFactory* factory); 92 explicit DownloadFileManager(content::DownloadFileFactory* factory);
104 93
105 // Create a download file and record it in the download file manager. 94 // Create a download file and record it in the download file manager.
106 virtual void CreateDownloadFile( 95 virtual void CreateDownloadFile(
107 scoped_ptr<DownloadCreateInfo> info, 96 scoped_ptr<DownloadCreateInfo> info,
108 scoped_ptr<content::ByteStreamReader> stream, 97 scoped_ptr<content::ByteStreamReader> stream,
109 scoped_refptr<content::DownloadManager> download_manager, 98 scoped_refptr<content::DownloadManager> download_manager,
110 bool hash_needed, 99 bool hash_needed,
111 const net::BoundNetLog& bound_net_log, 100 const net::BoundNetLog& bound_net_log,
112 const CreateDownloadFileCallback& callback); 101 const CreateDownloadFileCallback& callback);
113 102
(...skipping 18 matching lines...) Expand all
132 virtual void RenameDownloadFile( 121 virtual void RenameDownloadFile(
133 content::DownloadId id, 122 content::DownloadId id,
134 const FilePath& full_path, 123 const FilePath& full_path,
135 bool overwrite_existing_file, 124 bool overwrite_existing_file,
136 const RenameCompletionCallback& callback); 125 const RenameCompletionCallback& callback);
137 126
138 // The number of downloads currently active on the DownloadFileManager. 127 // The number of downloads currently active on the DownloadFileManager.
139 // Primarily for testing. 128 // Primarily for testing.
140 virtual int NumberOfActiveDownloads() const; 129 virtual int NumberOfActiveDownloads() const;
141 130
142 void SetFileFactoryForTesting(scoped_ptr<DownloadFileFactory> file_factory) { 131 void SetFileFactoryForTesting(
132 scoped_ptr<content::DownloadFileFactory> file_factory) {
143 download_file_factory_.reset(file_factory.release()); 133 download_file_factory_.reset(file_factory.release());
144 } 134 }
145 135
146 DownloadFileFactory* GetFileFactoryForTesting() const { 136 content::DownloadFileFactory* GetFileFactoryForTesting() const {
147 return download_file_factory_.get(); // Explicitly NOT a scoped_ptr. 137 return download_file_factory_.get(); // Explicitly NOT a scoped_ptr.
148 } 138 }
149 139
150 protected: 140 protected:
151 virtual ~DownloadFileManager(); 141 virtual ~DownloadFileManager();
152 142
153 private: 143 private:
154 friend class base::RefCountedThreadSafe<DownloadFileManager>; 144 friend class base::RefCountedThreadSafe<DownloadFileManager>;
155 friend class DownloadFileManagerTest; 145 friend class DownloadFileManagerTest;
156 friend class DownloadManagerTest; 146 friend class DownloadManagerTest;
157 FRIEND_TEST_ALL_PREFIXES(DownloadManagerTest, StartDownload); 147 FRIEND_TEST_ALL_PREFIXES(DownloadManagerTest, StartDownload);
158 148
159 // Clean up helper that runs on the download thread. 149 // Clean up helper that runs on the download thread.
160 void OnShutdown(); 150 void OnShutdown();
161 151
162 // Called only on the download thread. 152 // Called only on the download thread.
163 content::DownloadFile* GetDownloadFile(content::DownloadId global_id); 153 content::DownloadFile* GetDownloadFile(content::DownloadId global_id);
164 154
165 // Erases the download file with the given the download |id| and removes 155 // Erases the download file with the given the download |id| and removes
166 // it from the maps. 156 // it from the maps.
167 void EraseDownload(content::DownloadId global_id); 157 void EraseDownload(content::DownloadId global_id);
168 158
169 typedef base::hash_map<content::DownloadId, content::DownloadFile*> 159 typedef base::hash_map<content::DownloadId, content::DownloadFile*>
170 DownloadFileMap; 160 DownloadFileMap;
171 161
172 // A map of all in progress downloads. It owns the download files. 162 // A map of all in progress downloads. It owns the download files.
173 DownloadFileMap downloads_; 163 DownloadFileMap downloads_;
174 164
175 scoped_ptr<DownloadFileFactory> download_file_factory_; 165 scoped_ptr<content::DownloadFileFactory> download_file_factory_;
176 166
177 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 167 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
178 }; 168 };
179 169
180 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 170 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698