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

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

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed content unit tests. Created 8 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
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_MANAGER_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/sequenced_task_runner_helpers.h" 16 #include "base/sequenced_task_runner_helpers.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "content/browser/download/download_item_factory.h" 18 #include "content/browser/download/download_item_factory.h"
19 #include "content/browser/download/download_item_impl_delegate.h" 19 #include "content/browser/download/download_item_impl_delegate.h"
20 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
21 #include "content/public/browser/download_manager.h" 21 #include "content/public/browser/download_manager.h"
22 #include "content/public/browser/download_url_parameters.h"
22 23
23 class DownloadFileManager; 24 class DownloadFileManager;
24 class DownloadItemImpl; 25 class DownloadItemImpl;
25 26
27 namespace content {
28 class WebContents;
29 }
30
26 class CONTENT_EXPORT DownloadManagerImpl 31 class CONTENT_EXPORT DownloadManagerImpl
27 : public content::DownloadManager, 32 : public content::DownloadManager,
28 private DownloadItemImplDelegate { 33 private DownloadItemImplDelegate {
29 public: 34 public:
30 // Caller guarantees that |file_manager| and |net_log| will remain valid 35 // Caller guarantees that |file_manager| and |net_log| will remain valid
31 // for the lifetime of DownloadManagerImpl (until Shutdown() is called). 36 // for the lifetime of DownloadManagerImpl (until Shutdown() is called).
32 // |factory| may be a default constructed (null) scoped_ptr; if so, 37 // |factory| may be a default constructed (null) scoped_ptr; if so,
33 // the DownloadManagerImpl creates and takes ownership of the 38 // the DownloadManagerImpl creates and takes ownership of the
34 // default DownloadItemFactory. 39 // default DownloadItemFactory.
35 DownloadManagerImpl(DownloadFileManager* file_manager, 40 DownloadManagerImpl(DownloadFileManager* file_manager,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; 96 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector;
92 97
93 // For testing. 98 // For testing.
94 friend class DownloadManagerTest; 99 friend class DownloadManagerTest;
95 friend class DownloadTest; 100 friend class DownloadTest;
96 101
97 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; 102 friend class base::RefCountedThreadSafe<DownloadManagerImpl>;
98 103
99 virtual ~DownloadManagerImpl(); 104 virtual ~DownloadManagerImpl();
100 105
106 virtual void ContinueStartingDownload(
107 int32 id,
108 content::DownloadInterruptReason reason);
109
101 // Creates the download item. Must be called on the UI thread. 110 // Creates the download item. Must be called on the UI thread.
102 // Returns the |BoundNetLog| used by the |DownloadItem|. 111 // Returns the |BoundNetLog| used by the |DownloadItem|.
103 virtual net::BoundNetLog CreateDownloadItem(DownloadCreateInfo* info); 112 virtual net::BoundNetLog CreateDownloadItem(DownloadCreateInfo* info);
104 113
105 // Does nothing if |download_id| is not an active download. 114 // Does nothing if |download_id| is not an active download.
106 void MaybeCompleteDownloadById(int download_id); 115 void MaybeCompleteDownloadById(int download_id);
107 116
108 // Determine if the download is ready for completion, i.e. has had 117 // Determine if the download is ready for completion, i.e. has had
109 // all data saved, and completed the filename determination and 118 // all data saved, and completed the filename determination and
110 // history insertion. 119 // history insertion.
111 bool IsDownloadReadyForCompletion(DownloadItemImpl* download); 120 bool IsDownloadReadyForCompletion(DownloadItemImpl* download);
112 121
113 // Show the download in the browser. 122 // Show the download in the browser.
114 void ShowDownloadInBrowser(DownloadItemImpl* download); 123 void ShowDownloadInBrowser(DownloadItemImpl* download);
115 124
116 // Get next download id. 125 // Get next download id.
117 content::DownloadId GetNextId(); 126 content::DownloadId GetNextId();
118 127
119 // Called on the FILE thread to check the existence of a downloaded file. 128 // Called on the FILE thread to check the existence of a downloaded file.
120 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path); 129 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path);
121 130
122 // Called on the UI thread if the FILE thread detects the removal of 131 // Called on the UI thread if the FILE thread detects the removal of
123 // the downloaded file. The UI thread updates the state of the file 132 // the downloaded file. The UI thread updates the state of the file
124 // and then notifies this update to the file's observer. 133 // and then notifies this update to the file's observer.
125 void OnFileRemovalDetected(int32 download_id); 134 void OnFileRemovalDetected(int32 download_id);
126 135
136 // Retrieves the download from the |download_id|.
137 // Returns NULL if the download is not active.
138 content::DownloadItem* GetActiveDownload(int32 download_id);
139
127 // Removes |download| from the active and in progress maps. 140 // Removes |download| from the active and in progress maps.
128 // Called when the download is cancelled or has an error. 141 // Called when the download is cancelled or has an error.
129 // Does nothing if the download is not in the history DB. 142 // Does nothing if the download is not in the history DB.
130 void RemoveFromActiveList(DownloadItemImpl* download); 143 void RemoveFromActiveList(DownloadItemImpl* download);
131 144
132 // Inform observers that the model has changed. 145 // Inform observers that the model has changed.
133 void NotifyModelChanged(); 146 void NotifyModelChanged();
134 147
135 // Debugging routine to confirm relationship between below 148 // Debugging routine to confirm relationship between below
136 // containers; no-op if NDEBUG. 149 // containers; no-op if NDEBUG.
(...skipping 26 matching lines...) Expand all
163 176
164 // Called when Save Page As entry is committed to the persistent store. 177 // Called when Save Page As entry is committed to the persistent store.
165 void OnSavePageItemAddedToPersistentStore(DownloadItemImpl* item); 178 void OnSavePageItemAddedToPersistentStore(DownloadItemImpl* item);
166 179
167 // Overridden from DownloadItemImplDelegate 180 // Overridden from DownloadItemImplDelegate
168 // (Note that |GetBrowserContext| are present in both interfaces.) 181 // (Note that |GetBrowserContext| are present in both interfaces.)
169 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE; 182 virtual DownloadFileManager* GetDownloadFileManager() OVERRIDE;
170 virtual bool ShouldOpenDownload(DownloadItemImpl* item) OVERRIDE; 183 virtual bool ShouldOpenDownload(DownloadItemImpl* item) OVERRIDE;
171 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; 184 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE;
172 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE; 185 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE;
173 virtual void MaybeCompleteDownload(DownloadItemImpl* download) OVERRIDE; 186 virtual void MaybeCompleteDownload(int32 download_id) OVERRIDE;
187 virtual void RestartInterruptedDownload(
188 DownloadItemImpl* download,
189 const content::DownloadUrlParameters::OnStartedCallback& callback)
190 OVERRIDE;
174 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE; 191 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE;
175 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE; 192 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE;
176 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE; 193 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE;
177 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE; 194 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE;
178 virtual void DownloadRenamedToIntermediateName( 195 virtual void DownloadRenamedToIntermediateName(
179 DownloadItemImpl* download) OVERRIDE; 196 DownloadItemImpl* download) OVERRIDE;
180 virtual void DownloadRenamedToFinalName(DownloadItemImpl* download) OVERRIDE; 197 virtual void DownloadRenamedToFinalName(DownloadItemImpl* download) OVERRIDE;
181 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE; 198 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE;
182 199
183 // Factory for creation of downloads items. 200 // Factory for creation of downloads items.
184 scoped_ptr<content::DownloadItemFactory> factory_; 201 scoped_ptr<content::DownloadItemFactory> factory_;
185 202
203 // Helper to get |WebContents| from a |DownloadItem|.
204 // Falls back to asking the delegate for one.
205 // May return NULL if it can't.
206 content::WebContents* GetWebContents(const content::DownloadItem* download);
207
186 // |downloads_| is the owning set for all downloads known to the 208 // |downloads_| is the owning set for all downloads known to the
187 // DownloadManager. This includes downloads started by the user in 209 // DownloadManager. This includes downloads started by the user in
188 // this session, downloads initialized from the history system, and 210 // this session, downloads initialized from the history system, and
189 // "save page as" downloads. All other DownloadItem containers in 211 // "save page as" downloads. All other DownloadItem containers in
190 // the DownloadManager are maps; they do not own the DownloadItems. 212 // the DownloadManager are maps; they do not own the DownloadItems.
191 // Note that this is the only place (with any functional implications; 213 // Note that this is the only place (with any functional implications;
192 // see save_page_downloads_ below) that "save page as" downloads are 214 // see save_page_downloads_ below) that "save page as" downloads are
193 // kept, as the DownloadManager's only job is to hold onto those 215 // kept, as the DownloadManager's only job is to hold onto those
194 // until destruction. 216 // until destruction.
195 // 217 //
(...skipping 28 matching lines...) Expand all
224 246
225 // Allows an embedder to control behavior. Guaranteed to outlive this object. 247 // Allows an embedder to control behavior. Guaranteed to outlive this object.
226 content::DownloadManagerDelegate* delegate_; 248 content::DownloadManagerDelegate* delegate_;
227 249
228 net::NetLog* net_log_; 250 net::NetLog* net_log_;
229 251
230 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); 252 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
231 }; 253 };
232 254
233 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 255 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698