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 #ifndef CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/task.h" |
10 #include "chrome/browser/download/download_manager_delegate.h" | 12 #include "chrome/browser/download/download_manager_delegate.h" |
11 | 13 |
| 14 class DownloadItem; |
| 15 class DownloadManager; |
| 16 struct DownloadStateInfo; |
| 17 |
12 // Browser's download manager: manages all downloads and destination view. | 18 // Browser's download manager: manages all downloads and destination view. |
13 class ChromeDownloadManagerDelegate : public DownloadManagerDelegate { | 19 class ChromeDownloadManagerDelegate |
| 20 : public base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>, |
| 21 public DownloadManagerDelegate { |
14 public: | 22 public: |
15 ChromeDownloadManagerDelegate(); | 23 ChromeDownloadManagerDelegate(); |
16 | 24 |
| 25 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; |
| 26 virtual void ChooseDownloadPath(TabContents* tab_contents, |
| 27 const FilePath& suggested_path, |
| 28 void* data) OVERRIDE; |
| 29 virtual TabContents* GetAlternativeTabContentsToNotifyForDownload() OVERRIDE; |
| 30 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
17 virtual void GetSaveDir(TabContents* tab_contents, | 31 virtual void GetSaveDir(TabContents* tab_contents, |
18 FilePath* website_save_dir, | 32 FilePath* website_save_dir, |
19 FilePath* download_save_dir) OVERRIDE; | 33 FilePath* download_save_dir) OVERRIDE; |
20 virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, | 34 virtual void ChooseSavePath(const base::WeakPtr<SavePackage>& save_package, |
21 const FilePath& suggested_path, | 35 const FilePath& suggested_path, |
22 bool can_save_as_complete) OVERRIDE; | 36 bool can_save_as_complete) OVERRIDE; |
23 virtual void ChooseDownloadPath(DownloadManager* download_manager, | |
24 TabContents* tab_contents, | |
25 const FilePath& suggested_path, | |
26 void* data) OVERRIDE; | |
27 virtual TabContents* GetAlternativeTabContentsToNotifyForDownload( | |
28 DownloadManager* download_manager) OVERRIDE; | |
29 | 37 |
30 void set_download_manager(DownloadManager* dm) { download_manager_ = dm; } | 38 void set_download_manager(DownloadManager* dm) { download_manager_ = dm; } |
31 | 39 |
32 private: | 40 private: |
33 DownloadManager* download_manager_; | 41 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; |
| 42 virtual ~ChromeDownloadManagerDelegate(); |
| 43 |
| 44 // Callback function after url is checked with safebrowsing service. |
| 45 void CheckDownloadUrlDone(int32 download_id, bool is_dangerous_url); |
| 46 |
| 47 // Callback function after we check whether the referrer URL has been visited |
| 48 // before today. |
| 49 void CheckVisitedReferrerBeforeDone(int32 download_id, |
| 50 bool visited_referrer_before); |
| 51 |
| 52 // Called on the download thread to check whether the suggested file path |
| 53 // exists. We don't check if the file exists on the UI thread to avoid UI |
| 54 // stalls from interacting with the file system. |
| 55 void CheckIfSuggestedPathExists(int32 download_id, |
| 56 DownloadStateInfo state, |
| 57 const FilePath& default_path); |
| 58 |
| 59 // Called on the UI thread once it's determined whether the suggested file |
| 60 // path exists. |
| 61 void OnPathExistenceAvailable(int32 download_id, |
| 62 const DownloadStateInfo& new_state); |
| 63 |
| 64 // Returns true if this download should show the "dangerous file" warning. |
| 65 // Various factors are considered, such as the type of the file, whether a |
| 66 // user action initiated the download, and whether the user has explicitly |
| 67 // marked the file type as "auto open". |
| 68 bool IsDangerousFile(const DownloadItem& download, |
| 69 const DownloadStateInfo& state, |
| 70 bool visited_referrer_before); |
| 71 |
| 72 scoped_refptr<DownloadManager> download_manager_; |
34 | 73 |
35 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 74 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
36 }; | 75 }; |
37 | 76 |
38 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 77 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |