OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
8 #pragma once | 8 #pragma once |
9 | 9 |
10 #include "content/browser/download/download_manager.h" | 10 #include "content/browser/download/download_manager.h" |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <set> | 13 #include <set> |
14 | 14 |
15 #include "base/hash_tables.h" | 15 #include "base/hash_tables.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "content/browser/download/download_item_impl.h" | |
22 #include "content/browser/download/download_status_updater_delegate.h" | 21 #include "content/browser/download/download_status_updater_delegate.h" |
23 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
24 | 23 |
25 class DownloadIdFactory; | 24 class DownloadIdFactory; |
26 class DownloadStatusUpdater; | 25 class DownloadStatusUpdater; |
27 | 26 |
28 class CONTENT_EXPORT DownloadManagerImpl | 27 class CONTENT_EXPORT DownloadManagerImpl |
29 : public DownloadManager, | 28 : public DownloadManager, |
30 public DownloadItemImpl::Delegate, | |
31 public DownloadStatusUpdaterDelegate { | 29 public DownloadStatusUpdaterDelegate { |
32 public: | 30 public: |
33 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, | 31 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, |
34 DownloadIdFactory* id_factory, | 32 DownloadIdFactory* id_factory, |
35 DownloadStatusUpdater* status_updater); | 33 DownloadStatusUpdater* status_updater); |
36 | 34 |
37 // DownloadManager functions. | 35 // DownloadManager functions. |
38 virtual void Shutdown() OVERRIDE; | 36 virtual void Shutdown() OVERRIDE; |
39 virtual void GetTemporaryDownloads(const FilePath& dir_path, | 37 virtual void GetTemporaryDownloads(const FilePath& dir_path, |
40 DownloadVector* result) OVERRIDE; | 38 DownloadVector* result) OVERRIDE; |
41 virtual void GetAllDownloads(const FilePath& dir_path, | 39 virtual void GetAllDownloads(const FilePath& dir_path, |
42 DownloadVector* result) OVERRIDE; | 40 DownloadVector* result) OVERRIDE; |
43 virtual void SearchDownloads(const string16& query, | 41 virtual void SearchDownloads(const string16& query, |
44 DownloadVector* result) OVERRIDE; | 42 DownloadVector* result) OVERRIDE; |
45 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; | 43 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; |
46 virtual void StartDownload(int32 id) OVERRIDE; | 44 virtual void StartDownload(int32 id) OVERRIDE; |
47 virtual void UpdateDownload(int32 download_id, int64 bytes_so_far, | 45 virtual void UpdateDownload(int32 download_id, int64 bytes_so_far, |
48 int64 bytes_per_sec) OVERRIDE; | 46 int64 bytes_per_sec) OVERRIDE; |
49 virtual void OnResponseCompleted(int32 download_id, int64 size, | 47 virtual void OnResponseCompleted(int32 download_id, int64 size, |
50 const std::string& hash) OVERRIDE; | 48 const std::string& hash) OVERRIDE; |
51 virtual void CancelDownload(int32 download_id) OVERRIDE; | 49 virtual void CancelDownload(int32 download_id) OVERRIDE; |
52 virtual void OnDownloadInterrupted(int32 download_id, int64 size, | 50 virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
53 InterruptReason reason) OVERRIDE; | 51 InterruptReason reason) OVERRIDE; |
| 52 virtual void DownloadCancelledInternal(DownloadItem* download) OVERRIDE; |
| 53 virtual void RemoveDownload(int64 download_handle) OVERRIDE; |
| 54 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) OVERRIDE; |
| 55 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; |
54 virtual void OnDownloadRenamedToFinalName(int download_id, | 56 virtual void OnDownloadRenamedToFinalName(int download_id, |
55 const FilePath& full_path, | 57 const FilePath& full_path, |
56 int uniquifier) OVERRIDE; | 58 int uniquifier) OVERRIDE; |
57 virtual int RemoveDownloadsBetween(const base::Time remove_begin, | 59 virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
58 const base::Time remove_end) OVERRIDE; | 60 const base::Time remove_end) OVERRIDE; |
59 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; | 61 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; |
60 virtual int RemoveAllDownloads() OVERRIDE; | 62 virtual int RemoveAllDownloads() OVERRIDE; |
| 63 virtual void DownloadCompleted(int32 download_id) OVERRIDE; |
61 virtual void DownloadUrl(const GURL& url, | 64 virtual void DownloadUrl(const GURL& url, |
62 const GURL& referrer, | 65 const GURL& referrer, |
63 const std::string& referrer_encoding, | 66 const std::string& referrer_encoding, |
64 TabContents* tab_contents) OVERRIDE; | 67 TabContents* tab_contents) OVERRIDE; |
65 virtual void DownloadUrlToFile(const GURL& url, | 68 virtual void DownloadUrlToFile(const GURL& url, |
66 const GURL& referrer, | 69 const GURL& referrer, |
67 const std::string& referrer_encoding, | 70 const std::string& referrer_encoding, |
68 const DownloadSaveInfo& save_info, | 71 const DownloadSaveInfo& save_info, |
69 TabContents* tab_contents) OVERRIDE; | 72 TabContents* tab_contents) OVERRIDE; |
70 virtual void AddObserver(Observer* observer) OVERRIDE; | 73 virtual void AddObserver(Observer* observer) OVERRIDE; |
71 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 74 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
72 virtual void OnPersistentStoreQueryComplete( | 75 virtual void OnPersistentStoreQueryComplete( |
73 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; | 76 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; |
74 virtual void OnItemAddedToPersistentStore(int32 download_id, | 77 virtual void OnItemAddedToPersistentStore(int32 download_id, |
75 int64 db_handle) OVERRIDE; | 78 int64 db_handle) OVERRIDE; |
| 79 virtual void ShowDownloadInBrowser(DownloadItem* download) OVERRIDE; |
76 virtual int InProgressCount() const OVERRIDE; | 80 virtual int InProgressCount() const OVERRIDE; |
77 virtual content::BrowserContext* BrowserContext() const OVERRIDE; | 81 virtual content::BrowserContext* BrowserContext() OVERRIDE; |
78 virtual FilePath LastDownloadPath() OVERRIDE; | 82 virtual FilePath LastDownloadPath() OVERRIDE; |
79 virtual void CreateDownloadItem( | 83 virtual void CreateDownloadItem( |
80 DownloadCreateInfo* info, | 84 DownloadCreateInfo* info, |
81 const DownloadRequestHandle& request_handle) OVERRIDE; | 85 const DownloadRequestHandle& request_handle) OVERRIDE; |
82 virtual DownloadItem* CreateSavePackageDownloadItem( | |
83 const FilePath& main_file_path, | |
84 const GURL& page_url, | |
85 bool is_otr, | |
86 DownloadItem::Observer* observer) OVERRIDE; | |
87 virtual void ClearLastDownloadPath() OVERRIDE; | 86 virtual void ClearLastDownloadPath() OVERRIDE; |
88 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; | 87 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; |
89 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 88 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
90 virtual void RestartDownload(int32 download_id) OVERRIDE; | 89 virtual void RestartDownload(int32 download_id) OVERRIDE; |
| 90 virtual void MarkDownloadOpened(DownloadItem* download) OVERRIDE; |
91 virtual void CheckForHistoryFilesRemoval() OVERRIDE; | 91 virtual void CheckForHistoryFilesRemoval() OVERRIDE; |
| 92 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; |
| 93 virtual void AssertQueueStateConsistent(DownloadItem* download) OVERRIDE; |
92 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; | 94 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; |
| 95 virtual void SavePageDownloadStarted(DownloadItem* download) OVERRIDE; |
93 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; | 96 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; |
94 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; | 97 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; |
95 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; | 98 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; |
96 virtual void SetDownloadManagerDelegate( | 99 virtual void SetDownloadManagerDelegate( |
97 content::DownloadManagerDelegate* delegate) OVERRIDE; | 100 content::DownloadManagerDelegate* delegate) OVERRIDE; |
98 | 101 virtual DownloadId GetNextId() OVERRIDE; |
99 // Overridden from DownloadItemImpl::Delegate | |
100 // (Note that |BrowserContext| are present in both interfaces.) | |
101 virtual bool ShouldOpenDownload(DownloadItem* item) OVERRIDE; | |
102 virtual bool ShouldOpenFileBasedOnExtension( | |
103 const FilePath& path) OVERRIDE; | |
104 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; | |
105 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; | |
106 virtual void DownloadCancelled(DownloadItem* download) OVERRIDE; | |
107 virtual void DownloadCompleted(DownloadItem* download) OVERRIDE; | |
108 virtual void DownloadOpened(DownloadItem* download) OVERRIDE; | |
109 virtual void DownloadRemoved(DownloadItem* download) OVERRIDE; | |
110 virtual void AssertStateConsistent(DownloadItem* download) const OVERRIDE; | |
111 | 102 |
112 // Overridden from DownloadStatusUpdaterDelegate: | 103 // Overridden from DownloadStatusUpdaterDelegate: |
113 virtual bool IsDownloadProgressKnown() const OVERRIDE; | 104 virtual bool IsDownloadProgressKnown() const OVERRIDE; |
114 virtual int64 GetInProgressDownloadCount() const OVERRIDE; | 105 virtual int64 GetInProgressDownloadCount() const OVERRIDE; |
115 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; | 106 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; |
116 virtual int64 GetTotalDownloadBytes() const OVERRIDE; | 107 virtual int64 GetTotalDownloadBytes() const OVERRIDE; |
117 | 108 |
118 private: | 109 private: |
119 typedef std::set<DownloadItem*> DownloadSet; | 110 typedef std::set<DownloadItem*> DownloadSet; |
120 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 111 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
121 | 112 |
122 // For testing. | 113 // For testing. |
123 friend class DownloadManagerTest; | 114 friend class DownloadManagerTest; |
124 friend class DownloadTest; | 115 friend class DownloadTest; |
| 116 friend class MockDownloadManager; |
125 | 117 |
126 friend class base::RefCountedThreadSafe< | 118 friend class base::RefCountedThreadSafe< |
127 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; | 119 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; |
128 friend struct content::BrowserThread::DeleteOnThread< | 120 friend struct content::BrowserThread::DeleteOnThread< |
129 content::BrowserThread::UI>; | 121 content::BrowserThread::UI>; |
130 friend class DeleteTask<DownloadManagerImpl>; | 122 friend class DeleteTask<DownloadManagerImpl>; |
131 | 123 |
132 virtual ~DownloadManagerImpl(); | 124 virtual ~DownloadManagerImpl(); |
133 | 125 |
134 // Determine if the download is ready for completion, i.e. has had | |
135 // all data saved, and completed the filename determination and | |
136 // history insertion. | |
137 bool IsDownloadReadyForCompletion(DownloadItem* download); | |
138 | |
139 // Show the download in the browser. | |
140 void ShowDownloadInBrowser(DownloadItem* download); | |
141 | |
142 // Get next download id from factory. | |
143 DownloadId GetNextId(); | |
144 | |
145 // Called on the FILE thread to check the existence of a downloaded file. | 126 // Called on the FILE thread to check the existence of a downloaded file. |
146 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 127 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
147 | 128 |
148 // Called on the UI thread if the FILE thread detects the removal of | 129 // Called on the UI thread if the FILE thread detects the removal of |
149 // the downloaded file. The UI thread updates the state of the file | 130 // the downloaded file. The UI thread updates the state of the file |
150 // and then notifies this update to the file's observer. | 131 // and then notifies this update to the file's observer. |
151 void OnFileRemovalDetected(int64 db_handle); | 132 void OnFileRemovalDetected(int64 db_handle); |
152 | 133 |
153 // Called back after a target path for the file to be downloaded to has been | 134 // Called back after a target path for the file to be downloaded to has been |
154 // determined, either automatically based on the suggested file name, or by | 135 // determined, either automatically based on the suggested file name, or by |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 DownloadIdFactory* id_factory_; | 240 DownloadIdFactory* id_factory_; |
260 | 241 |
261 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. | 242 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. |
262 // For debugging only. | 243 // For debugging only. |
263 int64 largest_db_handle_in_history_; | 244 int64 largest_db_handle_in_history_; |
264 | 245 |
265 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 246 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
266 }; | 247 }; |
267 | 248 |
268 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 249 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |