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