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 // 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 14 matching lines...) Expand all Loading... |
25 // all persisted downloads. | 25 // all persisted downloads. |
26 | 26 |
27 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ | 27 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ |
28 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ | 28 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ |
29 #pragma once | 29 #pragma once |
30 | 30 |
31 #include <string> | 31 #include <string> |
32 #include <vector> | 32 #include <vector> |
33 | 33 |
34 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
| 35 #include "base/callback.h" |
35 #include "base/file_path.h" | 36 #include "base/file_path.h" |
36 #include "base/gtest_prod_util.h" | 37 #include "base/gtest_prod_util.h" |
37 #include "base/message_loop_helpers.h" | 38 #include "base/message_loop_helpers.h" |
38 #include "base/time.h" | 39 #include "base/time.h" |
39 #include "content/public/browser/download_id.h" | 40 #include "content/public/browser/download_id.h" |
40 #include "content/public/browser/download_interrupt_reasons.h" | 41 #include "content/public/browser/download_interrupt_reasons.h" |
41 #include "content/public/browser/download_item.h" | 42 #include "content/public/browser/download_item.h" |
42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
43 #include "net/base/net_log.h" | 44 #include "net/base/net_log.h" |
44 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
45 | 46 |
46 class DownloadRequestHandle; | 47 class DownloadRequestHandle; |
47 class GURL; | 48 class GURL; |
48 class TabContents; | 49 class TabContents; |
49 struct DownloadCreateInfo; | 50 struct DownloadCreateInfo; |
50 struct DownloadRetrieveInfo; | 51 struct DownloadRetrieveInfo; |
51 struct DownloadSaveInfo; | 52 struct DownloadSaveInfo; |
52 | 53 |
53 namespace content { | 54 namespace content { |
54 class BrowserContext; | 55 class BrowserContext; |
55 class DownloadManagerDelegate; | 56 class DownloadManagerDelegate; |
56 class DownloadQuery; | 57 class DownloadQuery; |
57 class WebContents; | 58 class WebContents; |
58 | 59 |
59 // Browser's download manager: manages all downloads and destination view. | 60 // Browser's download manager: manages all downloads and destination view. |
60 class CONTENT_EXPORT DownloadManager | 61 class CONTENT_EXPORT DownloadManager |
61 : public base::RefCountedThreadSafe<DownloadManager> { | 62 : public base::RefCountedThreadSafe<DownloadManager> { |
62 public: | 63 public: |
| 64 // NOTE: If there is an error, the DownloadId will be invalid. |
| 65 typedef base::Callback<void(DownloadId, net::Error)> OnStartedCallback; |
| 66 |
63 virtual ~DownloadManager() {} | 67 virtual ~DownloadManager() {} |
64 | 68 |
65 static DownloadManager* Create( | 69 static DownloadManager* Create( |
66 DownloadManagerDelegate* delegate, | 70 DownloadManagerDelegate* delegate, |
67 net::NetLog* net_log); | 71 net::NetLog* net_log); |
68 | 72 |
69 // A method that can be used in tests to ensure that all the internal download | 73 // A method that can be used in tests to ensure that all the internal download |
70 // classes have no pending downloads. | 74 // classes have no pending downloads. |
71 static bool EnsureNoPendingDownloadsForTesting(); | 75 static bool EnsureNoPendingDownloadsForTesting(); |
72 | 76 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Downloads the content at |url|. |referrer| and |referrer_encoding| are the | 176 // Downloads the content at |url|. |referrer| and |referrer_encoding| are the |
173 // referrer for the download, and may be empty. If |prefer_cache| is true, | 177 // referrer for the download, and may be empty. If |prefer_cache| is true, |
174 // then if the response to |url| is in the HTTP cache it will be used without | 178 // then if the response to |url| is in the HTTP cache it will be used without |
175 // revalidation. If |post_id| is non-negative, then it identifies the post | 179 // revalidation. If |post_id| is non-negative, then it identifies the post |
176 // transaction used to originally retrieve the |url| resource - it also | 180 // transaction used to originally retrieve the |url| resource - it also |
177 // requires |prefer_cache| to be |true| since re-post'ing is not done. | 181 // requires |prefer_cache| to be |true| since re-post'ing is not done. |
178 // |save_info| specifies where the downloaded file should be | 182 // |save_info| specifies where the downloaded file should be |
179 // saved, and whether the user should be prompted about the download. | 183 // saved, and whether the user should be prompted about the download. |
180 // |web_contents| is the web page that the download is done in context of, | 184 // |web_contents| is the web page that the download is done in context of, |
181 // and must be non-NULL. | 185 // and must be non-NULL. |
| 186 // |callback| will be called when the download starts, or if an error |
| 187 // occurs that prevents a download item from being created. |
182 virtual void DownloadUrl(const GURL& url, | 188 virtual void DownloadUrl(const GURL& url, |
183 const GURL& referrer, | 189 const GURL& referrer, |
184 const std::string& referrer_encoding, | 190 const std::string& referrer_encoding, |
185 bool prefer_cache, | 191 bool prefer_cache, |
186 int64 post_id, | 192 int64 post_id, |
187 const DownloadSaveInfo& save_info, | 193 const DownloadSaveInfo& save_info, |
188 content::WebContents* web_contents) = 0; | 194 content::WebContents* web_contents, |
| 195 const OnStartedCallback& callback) = 0; |
189 | 196 |
190 // Allow objects to observe the download creation process. | 197 // Allow objects to observe the download creation process. |
191 virtual void AddObserver(Observer* observer) = 0; | 198 virtual void AddObserver(Observer* observer) = 0; |
192 | 199 |
193 // Remove a download observer from ourself. | 200 // Remove a download observer from ourself. |
194 virtual void RemoveObserver(Observer* observer) = 0; | 201 virtual void RemoveObserver(Observer* observer) = 0; |
195 | 202 |
196 // Called by the embedder, after creating the download manager, to let it know | 203 // Called by the embedder, after creating the download manager, to let it know |
197 // about downloads from previous runs of the browser. | 204 // about downloads from previous runs of the browser. |
198 virtual void OnPersistentStoreQueryComplete( | 205 virtual void OnPersistentStoreQueryComplete( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 friend class base::RefCountedThreadSafe< | 272 friend class base::RefCountedThreadSafe< |
266 DownloadManager, content::BrowserThread::DeleteOnUIThread>; | 273 DownloadManager, content::BrowserThread::DeleteOnUIThread>; |
267 friend struct content::BrowserThread::DeleteOnThread< | 274 friend struct content::BrowserThread::DeleteOnThread< |
268 content::BrowserThread::UI>; | 275 content::BrowserThread::UI>; |
269 friend class base::DeleteHelper<DownloadManager>; | 276 friend class base::DeleteHelper<DownloadManager>; |
270 }; | 277 }; |
271 | 278 |
272 } // namespace content | 279 } // namespace content |
273 | 280 |
274 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ | 281 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_H_ |
OLD | NEW |