OLD | NEW |
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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 scoped_ptr<DownloadCreateInfo> info, | 56 scoped_ptr<DownloadCreateInfo> info, |
57 scoped_ptr<ByteStreamReader> stream) OVERRIDE; | 57 scoped_ptr<ByteStreamReader> stream) OVERRIDE; |
58 virtual void CancelDownload(int32 download_id) OVERRIDE; | 58 virtual void CancelDownload(int32 download_id) OVERRIDE; |
59 virtual int RemoveDownloadsBetween(base::Time remove_begin, | 59 virtual int RemoveDownloadsBetween(base::Time remove_begin, |
60 base::Time remove_end) OVERRIDE; | 60 base::Time remove_end) OVERRIDE; |
61 virtual int RemoveDownloads(base::Time remove_begin) OVERRIDE; | 61 virtual int RemoveDownloads(base::Time remove_begin) OVERRIDE; |
62 virtual int RemoveAllDownloads() OVERRIDE; | 62 virtual int RemoveAllDownloads() OVERRIDE; |
63 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) OVERRIDE; | 63 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) OVERRIDE; |
64 virtual void AddObserver(Observer* observer) OVERRIDE; | 64 virtual void AddObserver(Observer* observer) OVERRIDE; |
65 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 65 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
66 virtual void OnPersistentStoreQueryComplete( | 66 virtual content::DownloadItem* CreateDownloadItem( |
67 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; | 67 const FilePath& path, |
68 virtual void OnItemAddedToPersistentStore(int32 download_id, | 68 const GURL& url, |
69 int64 db_handle) OVERRIDE; | 69 const GURL& referrer_url, |
| 70 const base::Time& start_time, |
| 71 const base::Time& end_time, |
| 72 int64 received_bytes, |
| 73 int64 total_bytes, |
| 74 content::DownloadItem::DownloadState state, |
| 75 bool opened) OVERRIDE; |
70 virtual int InProgressCount() const OVERRIDE; | 76 virtual int InProgressCount() const OVERRIDE; |
71 virtual BrowserContext* GetBrowserContext() const OVERRIDE; | 77 virtual BrowserContext* GetBrowserContext() const OVERRIDE; |
72 virtual void CheckForHistoryFilesRemoval() OVERRIDE; | 78 virtual void CheckForHistoryFilesRemoval() OVERRIDE; |
73 virtual DownloadItem* GetDownload(int id) OVERRIDE; | 79 virtual DownloadItem* GetDownload(int id) OVERRIDE; |
74 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; | |
75 | 80 |
76 // For testing; specifically, accessed from TestFileErrorInjector. | 81 // For testing; specifically, accessed from TestFileErrorInjector. |
77 void SetDownloadItemFactoryForTesting( | 82 void SetDownloadItemFactoryForTesting( |
78 scoped_ptr<DownloadItemFactory> item_factory); | 83 scoped_ptr<DownloadItemFactory> item_factory); |
79 void SetDownloadFileFactoryForTesting( | 84 void SetDownloadFileFactoryForTesting( |
80 scoped_ptr<DownloadFileFactory> file_factory); | 85 scoped_ptr<DownloadFileFactory> file_factory); |
81 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); | 86 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); |
82 | 87 |
83 private: | 88 private: |
84 typedef std::set<DownloadItem*> DownloadSet; | 89 typedef std::set<DownloadItem*> DownloadSet; |
85 typedef base::hash_map<int32, DownloadItemImpl*> DownloadMap; | 90 typedef base::hash_map<int32, DownloadItemImpl*> DownloadMap; |
86 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; | 91 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; |
87 | 92 |
88 // For testing. | 93 // For testing. |
89 friend class DownloadManagerTest; | 94 friend class DownloadManagerTest; |
90 friend class DownloadTest; | 95 friend class DownloadTest; |
91 | 96 |
92 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; | 97 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; |
93 | 98 |
94 virtual ~DownloadManagerImpl(); | 99 virtual ~DownloadManagerImpl(); |
95 | 100 |
96 // Creates the download item. Must be called on the UI thread. | 101 // Creates the download item. Must be called on the UI thread. |
97 virtual DownloadItemImpl* CreateDownloadItem( | 102 virtual DownloadItemImpl* CreateDownloadItem( |
98 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log); | 103 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log); |
99 | 104 |
100 // Show the download in the browser. | |
101 void ShowDownloadInBrowser(DownloadItemImpl* download); | |
102 | |
103 // Get next download id. | 105 // Get next download id. |
104 DownloadId GetNextId(); | 106 DownloadId GetNextId(); |
105 | 107 |
106 // Called on the FILE thread to check the existence of a downloaded file. | 108 // Called on the FILE thread to check the existence of a downloaded file. |
107 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path); | 109 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path); |
108 | 110 |
109 // Called on the UI thread if the FILE thread detects the removal of | 111 // Called on the UI thread if the FILE thread detects the removal of |
110 // the downloaded file. The UI thread updates the state of the file | 112 // the downloaded file. The UI thread updates the state of the file |
111 // and then notifies this update to the file's observer. | 113 // and then notifies this update to the file's observer. |
112 void OnFileRemovalDetected(int32 download_id); | 114 void OnFileRemovalDetected(int32 download_id); |
113 | 115 |
114 // Removes |download| from the active and in progress maps. | 116 // Removes |download| from the active and in progress maps. |
115 // Called when the download is cancelled or has an error. | 117 // Called when the download is cancelled or has an error. |
116 // Does nothing if the download is not in the history DB. | 118 // Does nothing if the download is not in the history DB. |
117 void RemoveFromActiveList(DownloadItemImpl* download); | 119 void RemoveFromActiveList(DownloadItemImpl* download); |
118 | 120 |
119 // Debugging routine to confirm relationship between below | 121 // Debugging routine to confirm relationship between below |
120 // containers; no-op if NDEBUG. | 122 // containers; no-op if NDEBUG. |
121 void AssertContainersConsistent() const; | 123 void AssertContainersConsistent() const; |
122 | 124 |
123 // Add a DownloadItem to history_downloads_. | |
124 void AddDownloadItemToHistory(DownloadItemImpl* item, int64 db_handle); | |
125 | |
126 // Remove from internal maps. | 125 // Remove from internal maps. |
127 int RemoveDownloadItems(const DownloadItemImplVector& pending_deletes); | 126 int RemoveDownloadItems(const DownloadItemImplVector& pending_deletes); |
128 | 127 |
129 // Called when a download entry is committed to the persistent store. | |
130 void OnDownloadItemAddedToPersistentStore(DownloadItemImpl* item); | |
131 | |
132 // Called when Save Page As entry is committed to the persistent store. | |
133 void OnSavePageItemAddedToPersistentStore(DownloadItemImpl* item); | |
134 | |
135 // Overridden from DownloadItemImplDelegate | 128 // Overridden from DownloadItemImplDelegate |
136 // (Note that |GetBrowserContext| are present in both interfaces.) | 129 // (Note that |GetBrowserContext| are present in both interfaces.) |
137 virtual void DetermineDownloadTarget( | 130 virtual void DetermineDownloadTarget( |
138 DownloadItemImpl* item, const DownloadTargetCallback& callback) OVERRIDE; | 131 DownloadItemImpl* item, const DownloadTargetCallback& callback) OVERRIDE; |
139 virtual void ReadyForDownloadCompletion( | 132 virtual void ReadyForDownloadCompletion( |
140 DownloadItemImpl* item, const base::Closure& complete_callback) OVERRIDE; | 133 DownloadItemImpl* item, const base::Closure& complete_callback) OVERRIDE; |
141 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 134 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
142 virtual bool ShouldOpenDownload( | 135 virtual bool ShouldOpenDownload( |
143 DownloadItemImpl* item, | 136 DownloadItemImpl* item, |
144 const ShouldOpenDownloadCallback& callback) OVERRIDE; | 137 const ShouldOpenDownloadCallback& callback) OVERRIDE; |
145 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE; | 138 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE; |
146 virtual void UpdatePersistence(DownloadItemImpl* download) OVERRIDE; | |
147 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE; | 139 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE; |
148 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE; | 140 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE; |
149 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE; | 141 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE; |
150 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE; | 142 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE; |
151 virtual void DownloadRenamedToIntermediateName( | 143 virtual void ShowDownloadInBrowser(DownloadItemImpl* download) OVERRIDE; |
152 DownloadItemImpl* download) OVERRIDE; | |
153 virtual void DownloadRenamedToFinalName(DownloadItemImpl* download) OVERRIDE; | |
154 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE; | 144 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE; |
155 | 145 |
156 // Factory for creation of downloads items. | 146 // Factory for creation of downloads items. |
157 scoped_ptr<DownloadItemFactory> item_factory_; | 147 scoped_ptr<DownloadItemFactory> item_factory_; |
158 | 148 |
159 // Factory for the creation of download files. | 149 // Factory for the creation of download files. |
160 scoped_ptr<DownloadFileFactory> file_factory_; | 150 scoped_ptr<DownloadFileFactory> file_factory_; |
161 | 151 |
162 // |downloads_| is the owning set for all downloads known to the | 152 // |downloads_| is the owning set for all downloads known to the |
163 // DownloadManager. This includes downloads started by the user in | 153 // DownloadManager. This includes downloads started by the user in |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 DownloadManagerDelegate* delegate_; | 188 DownloadManagerDelegate* delegate_; |
199 | 189 |
200 net::NetLog* net_log_; | 190 net::NetLog* net_log_; |
201 | 191 |
202 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 192 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
203 }; | 193 }; |
204 | 194 |
205 } // namespace content | 195 } // namespace content |
206 | 196 |
207 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 197 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |