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" | |
21 #include "content/browser/download/download_status_updater_delegate.h" | 22 #include "content/browser/download/download_status_updater_delegate.h" |
22 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
23 | 24 |
24 class DownloadIdFactory; | 25 class DownloadIdFactory; |
25 class DownloadStatusUpdater; | 26 class DownloadStatusUpdater; |
26 | 27 |
27 class CONTENT_EXPORT DownloadManagerImpl | 28 class CONTENT_EXPORT DownloadManagerImpl |
28 : public DownloadManager, | 29 : public DownloadManager, |
30 public DownloadItemImpl::Delegate, | |
cbentzel
2011/11/29 21:30:44
I think this is additional argument that the Deleg
Randy Smith (Not in Mondays)
2011/11/30 22:44:05
As per our offline conversation and my comments el
| |
29 public DownloadStatusUpdaterDelegate { | 31 public DownloadStatusUpdaterDelegate { |
30 public: | 32 public: |
31 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, | 33 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, |
32 DownloadIdFactory* id_factory, | 34 DownloadIdFactory* id_factory, |
33 DownloadStatusUpdater* status_updater); | 35 DownloadStatusUpdater* status_updater); |
34 | 36 |
35 // DownloadManager functions. | 37 // DownloadManager functions. |
36 virtual void Shutdown() OVERRIDE; | 38 virtual void Shutdown() OVERRIDE; |
37 virtual void GetTemporaryDownloads(const FilePath& dir_path, | 39 virtual void GetTemporaryDownloads(const FilePath& dir_path, |
38 DownloadVector* result) OVERRIDE; | 40 DownloadVector* result) OVERRIDE; |
39 virtual void GetAllDownloads(const FilePath& dir_path, | 41 virtual void GetAllDownloads(const FilePath& dir_path, |
40 DownloadVector* result) OVERRIDE; | 42 DownloadVector* result) OVERRIDE; |
41 virtual void SearchDownloads(const string16& query, | 43 virtual void SearchDownloads(const string16& query, |
42 DownloadVector* result) OVERRIDE; | 44 DownloadVector* result) OVERRIDE; |
43 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; | 45 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; |
44 virtual void StartDownload(int32 id) OVERRIDE; | 46 virtual void StartDownload(int32 id) OVERRIDE; |
45 virtual void UpdateDownload(int32 download_id, int64 size) OVERRIDE; | 47 virtual void UpdateDownload(int32 download_id, int64 size) OVERRIDE; |
46 virtual void OnResponseCompleted(int32 download_id, int64 size, | 48 virtual void OnResponseCompleted(int32 download_id, int64 size, |
47 const std::string& hash) OVERRIDE; | 49 const std::string& hash) OVERRIDE; |
48 virtual void CancelDownload(int32 download_id) OVERRIDE; | 50 virtual void CancelDownload(int32 download_id) OVERRIDE; |
49 virtual void OnDownloadInterrupted(int32 download_id, int64 size, | 51 virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
50 InterruptReason reason) OVERRIDE; | 52 InterruptReason reason) OVERRIDE; |
51 virtual void DownloadCancelledInternal(DownloadItem* download) OVERRIDE; | |
52 virtual void RemoveDownload(int64 download_handle) OVERRIDE; | |
53 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) OVERRIDE; | |
54 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; | 53 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; |
55 virtual void OnDownloadRenamedToFinalName(int download_id, | 54 virtual void OnDownloadRenamedToFinalName(int download_id, |
56 const FilePath& full_path, | 55 const FilePath& full_path, |
57 int uniquifier) OVERRIDE; | 56 int uniquifier) OVERRIDE; |
58 virtual int RemoveDownloadsBetween(const base::Time remove_begin, | 57 virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
59 const base::Time remove_end) OVERRIDE; | 58 const base::Time remove_end) OVERRIDE; |
60 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; | 59 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; |
61 virtual int RemoveAllDownloads() OVERRIDE; | 60 virtual int RemoveAllDownloads() OVERRIDE; |
62 virtual void DownloadCompleted(int32 download_id) OVERRIDE; | |
63 virtual void DownloadUrl(const GURL& url, | 61 virtual void DownloadUrl(const GURL& url, |
64 const GURL& referrer, | 62 const GURL& referrer, |
65 const std::string& referrer_encoding, | 63 const std::string& referrer_encoding, |
66 TabContents* tab_contents) OVERRIDE; | 64 TabContents* tab_contents) OVERRIDE; |
67 virtual void DownloadUrlToFile(const GURL& url, | 65 virtual void DownloadUrlToFile(const GURL& url, |
68 const GURL& referrer, | 66 const GURL& referrer, |
69 const std::string& referrer_encoding, | 67 const std::string& referrer_encoding, |
70 const DownloadSaveInfo& save_info, | 68 const DownloadSaveInfo& save_info, |
71 TabContents* tab_contents) OVERRIDE; | 69 TabContents* tab_contents) OVERRIDE; |
72 virtual void AddObserver(Observer* observer) OVERRIDE; | 70 virtual void AddObserver(Observer* observer) OVERRIDE; |
73 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 71 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
74 virtual void OnPersistentStoreQueryComplete( | 72 virtual void OnPersistentStoreQueryComplete( |
75 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; | 73 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; |
76 virtual void OnItemAddedToPersistentStore(int32 download_id, | 74 virtual void OnItemAddedToPersistentStore(int32 download_id, |
77 int64 db_handle) OVERRIDE; | 75 int64 db_handle) OVERRIDE; |
78 virtual void ShowDownloadInBrowser(DownloadItem* download) OVERRIDE; | |
79 virtual int InProgressCount() const OVERRIDE; | 76 virtual int InProgressCount() const OVERRIDE; |
80 virtual content::BrowserContext* BrowserContext() OVERRIDE; | 77 virtual content::BrowserContext* BrowserContext() const OVERRIDE; |
81 virtual FilePath LastDownloadPath() OVERRIDE; | 78 virtual FilePath LastDownloadPath() OVERRIDE; |
82 virtual void CreateDownloadItem( | 79 virtual void CreateDownloadItem( |
83 DownloadCreateInfo* info, | 80 DownloadCreateInfo* info, |
84 const DownloadRequestHandle& request_handle) OVERRIDE; | 81 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; | |
85 virtual void ClearLastDownloadPath() OVERRIDE; | 87 virtual void ClearLastDownloadPath() OVERRIDE; |
86 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; | 88 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; |
87 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 89 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
88 virtual void RestartDownload(int32 download_id) OVERRIDE; | 90 virtual void RestartDownload(int32 download_id) OVERRIDE; |
89 virtual void MarkDownloadOpened(DownloadItem* download) OVERRIDE; | |
90 virtual void CheckForHistoryFilesRemoval() OVERRIDE; | 91 virtual void CheckForHistoryFilesRemoval() OVERRIDE; |
91 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; | |
92 virtual void AssertQueueStateConsistent(DownloadItem* download) OVERRIDE; | |
93 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; | 92 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; |
94 virtual void SavePageDownloadStarted(DownloadItem* download) OVERRIDE; | |
95 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; | 93 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; |
96 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; | 94 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; |
97 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; | 95 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; |
98 virtual void SetDownloadManagerDelegate( | 96 virtual void SetDownloadManagerDelegate( |
99 content::DownloadManagerDelegate* delegate) OVERRIDE; | 97 content::DownloadManagerDelegate* delegate) OVERRIDE; |
100 virtual DownloadId GetNextId() OVERRIDE; | 98 |
99 // Overridden from DownloadItemImpl::Delegate | |
100 // (Note that |MaybeCompleteDownload| and |BrowserContext| are | |
101 // present in both interfaces.) | |
cbentzel
2011/11/29 21:30:44
Ooh. Should that change? I suppose both will go to
Randy Smith (Not in Mondays)
2011/11/30 22:44:05
I agree with you it's not ideal, but I couldn't se
| |
102 virtual bool ShouldOpenDownload(DownloadItem* item) OVERRIDE; | |
103 virtual bool ShouldOpenFileBasedOnExtension( | |
104 const FilePath& path) OVERRIDE; | |
105 virtual void CheckForFileRemoval(DownloadItem* download_item) 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; | |
101 | 111 |
102 // Overridden from DownloadStatusUpdaterDelegate: | 112 // Overridden from DownloadStatusUpdaterDelegate: |
103 virtual bool IsDownloadProgressKnown() const OVERRIDE; | 113 virtual bool IsDownloadProgressKnown() const OVERRIDE; |
104 virtual int64 GetInProgressDownloadCount() const OVERRIDE; | 114 virtual int64 GetInProgressDownloadCount() const OVERRIDE; |
105 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; | 115 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; |
106 virtual int64 GetTotalDownloadBytes() const OVERRIDE; | 116 virtual int64 GetTotalDownloadBytes() const OVERRIDE; |
107 | 117 |
108 private: | 118 private: |
109 typedef std::set<DownloadItem*> DownloadSet; | 119 typedef std::set<DownloadItem*> DownloadSet; |
110 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 120 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
111 | 121 |
112 // For testing. | 122 // For testing. |
113 friend class DownloadManagerTest; | 123 friend class DownloadManagerTest; |
114 friend class DownloadTest; | 124 friend class DownloadTest; |
115 friend class MockDownloadManager; | |
116 | 125 |
117 friend class base::RefCountedThreadSafe< | 126 friend class base::RefCountedThreadSafe< |
118 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; | 127 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; |
119 friend struct content::BrowserThread::DeleteOnThread< | 128 friend struct content::BrowserThread::DeleteOnThread< |
120 content::BrowserThread::UI>; | 129 content::BrowserThread::UI>; |
121 friend class DeleteTask<DownloadManagerImpl>; | 130 friend class DeleteTask<DownloadManagerImpl>; |
122 | 131 |
123 virtual ~DownloadManagerImpl(); | 132 virtual ~DownloadManagerImpl(); |
124 | 133 |
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 | |
125 // Called on the FILE thread to check the existence of a downloaded file. | 145 // Called on the FILE thread to check the existence of a downloaded file. |
126 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 146 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
127 | 147 |
128 // Called on the UI thread if the FILE thread detects the removal of | 148 // Called on the UI thread if the FILE thread detects the removal of |
129 // the downloaded file. The UI thread updates the state of the file | 149 // the downloaded file. The UI thread updates the state of the file |
130 // and then notifies this update to the file's observer. | 150 // and then notifies this update to the file's observer. |
131 void OnFileRemovalDetected(int64 db_handle); | 151 void OnFileRemovalDetected(int64 db_handle); |
132 | 152 |
133 // Called back after a target path for the file to be downloaded to has been | 153 // Called back after a target path for the file to be downloaded to has been |
134 // determined, either automatically based on the suggested file name, or by | 154 // determined, either automatically based on the suggested file name, or by |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 DownloadIdFactory* id_factory_; | 259 DownloadIdFactory* id_factory_; |
240 | 260 |
241 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. | 261 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. |
242 // For debugging only. | 262 // For debugging only. |
243 int64 largest_db_handle_in_history_; | 263 int64 largest_db_handle_in_history_; |
244 | 264 |
245 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 265 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
246 }; | 266 }; |
247 | 267 |
248 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 268 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |