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 // The DownloadManager object manages the process of downloading, including | 5 // The DownloadManager object manages the process of downloading, including |
6 // updates to the history system and providing the information for displaying | 6 // updates to the history system and providing the information for displaying |
7 // the downloads view in the Destinations tab. There is one DownloadManager per | 7 // the downloads view in the Destinations tab. There is one DownloadManager per |
8 // active browser context in Chrome. | 8 // active browser context in Chrome. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "base/hash_tables.h" | 39 #include "base/hash_tables.h" |
40 #include "base/memory/ref_counted.h" | 40 #include "base/memory/ref_counted.h" |
41 #include "base/memory/scoped_ptr.h" | 41 #include "base/memory/scoped_ptr.h" |
42 #include "base/memory/weak_ptr.h" | 42 #include "base/memory/weak_ptr.h" |
43 #include "base/observer_list.h" | 43 #include "base/observer_list.h" |
44 #include "base/time.h" | 44 #include "base/time.h" |
45 #include "content/browser/browser_thread.h" | 45 #include "content/browser/browser_thread.h" |
46 #include "content/browser/download/download_item.h" | 46 #include "content/browser/download/download_item.h" |
47 #include "content/browser/download/download_request_handle.h" | 47 #include "content/browser/download/download_request_handle.h" |
48 #include "content/browser/download/download_status_updater_delegate.h" | 48 #include "content/browser/download/download_status_updater_delegate.h" |
| 49 #include "content/common/content_export.h" |
49 #include "net/base/net_errors.h" | 50 #include "net/base/net_errors.h" |
50 | 51 |
51 class DownloadFileManager; | 52 class DownloadFileManager; |
52 class DownloadManagerDelegate; | 53 class DownloadManagerDelegate; |
53 class DownloadStatusUpdater; | 54 class DownloadStatusUpdater; |
54 class GURL; | 55 class GURL; |
55 class ResourceDispatcherHost; | 56 class ResourceDispatcherHost; |
56 class TabContents; | 57 class TabContents; |
57 struct DownloadCreateInfo; | 58 struct DownloadCreateInfo; |
58 struct DownloadSaveInfo; | 59 struct DownloadSaveInfo; |
59 | 60 |
60 namespace content { | 61 namespace content { |
61 class BrowserContext; | 62 class BrowserContext; |
62 } | 63 } |
63 | 64 |
64 // Browser's download manager: manages all downloads and destination view. | 65 // Browser's download manager: manages all downloads and destination view. |
65 class DownloadManager | 66 class CONTENT_EXPORT DownloadManager |
66 : public base::RefCountedThreadSafe<DownloadManager, | 67 : public base::RefCountedThreadSafe<DownloadManager, |
67 BrowserThread::DeleteOnUIThread>, | 68 BrowserThread::DeleteOnUIThread>, |
68 public DownloadStatusUpdaterDelegate { | 69 public DownloadStatusUpdaterDelegate { |
69 public: | 70 public: |
70 DownloadManager(DownloadManagerDelegate* delegate, | 71 DownloadManager(DownloadManagerDelegate* delegate, |
71 DownloadStatusUpdater* status_updater); | 72 DownloadStatusUpdater* status_updater); |
72 | 73 |
73 // Shutdown the download manager. Must be called before destruction. | 74 // Shutdown the download manager. Must be called before destruction. |
74 void Shutdown(); | 75 void Shutdown(); |
75 | 76 |
76 // Interface to implement for observers that wish to be informed of changes | 77 // Interface to implement for observers that wish to be informed of changes |
77 // to the DownloadManager's collection of downloads. | 78 // to the DownloadManager's collection of downloads. |
78 class Observer { | 79 class CONTENT_EXPORT Observer { |
79 public: | 80 public: |
80 // New or deleted download, observers should query us for the current set | 81 // New or deleted download, observers should query us for the current set |
81 // of downloads. | 82 // of downloads. |
82 virtual void ModelChanged() = 0; | 83 virtual void ModelChanged() = 0; |
83 | 84 |
84 // Called when the DownloadManager is being destroyed to prevent Observers | 85 // Called when the DownloadManager is being destroyed to prevent Observers |
85 // from calling back to a stale pointer. | 86 // from calling back to a stale pointer. |
86 virtual void ManagerGoingDown() {} | 87 virtual void ManagerGoingDown() {} |
87 | 88 |
88 // Called immediately after the DownloadManager puts up a select file | 89 // Called immediately after the DownloadManager puts up a select file |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 DownloadManagerDelegate* delegate() const { return delegate_; } | 270 DownloadManagerDelegate* delegate() const { return delegate_; } |
270 | 271 |
271 private: | 272 private: |
272 typedef std::set<DownloadItem*> DownloadSet; | 273 typedef std::set<DownloadItem*> DownloadSet; |
273 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 274 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
274 | 275 |
275 // For testing. | 276 // For testing. |
276 friend class DownloadManagerTest; | 277 friend class DownloadManagerTest; |
277 friend class MockDownloadManager; | 278 friend class MockDownloadManager; |
278 | 279 |
| 280 friend class base::RefCountedThreadSafe<DownloadManager, |
| 281 BrowserThread::DeleteOnUIThread>; |
279 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 282 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
280 friend class DeleteTask<DownloadManager>; | 283 friend class DeleteTask<DownloadManager>; |
281 | 284 |
282 virtual ~DownloadManager(); | 285 virtual ~DownloadManager(); |
283 | 286 |
284 // Called on the FILE thread to check the existence of a downloaded file. | 287 // Called on the FILE thread to check the existence of a downloaded file. |
285 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 288 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
286 | 289 |
287 // Called on the UI thread if the FILE thread detects the removal of | 290 // Called on the UI thread if the FILE thread detects the removal of |
288 // the downloaded file. The UI thread updates the state of the file | 291 // the downloaded file. The UI thread updates the state of the file |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 DownloadManagerDelegate* delegate_; | 401 DownloadManagerDelegate* delegate_; |
399 | 402 |
400 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. | 403 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. |
401 // For debugging only. | 404 // For debugging only. |
402 int64 largest_db_handle_in_history_; | 405 int64 largest_db_handle_in_history_; |
403 | 406 |
404 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 407 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
405 }; | 408 }; |
406 | 409 |
407 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 410 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |