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/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "chrome/browser/safe_browsing/download_protection_service.h" | 14 #include "chrome/browser/safe_browsing/download_protection_service.h" |
15 #include "content/public/browser/download_manager_delegate.h" | 15 #include "content/public/browser/download_manager_delegate.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 | 18 |
19 class CrxInstaller; | 19 class CrxInstaller; |
20 class DownloadHistory; | 20 class DownloadHistory; |
21 class DownloadItem; | 21 class DownloadItem; |
22 class DownloadManager; | 22 class DownloadManagerInterface; |
23 class DownloadPrefs; | 23 class DownloadPrefs; |
24 class Profile; | 24 class Profile; |
25 struct DownloadStateInfo; | 25 struct DownloadStateInfo; |
26 | 26 |
27 #if defined(COMPILER_GCC) | 27 #if defined(COMPILER_GCC) |
28 namespace __gnu_cxx { | 28 namespace __gnu_cxx { |
29 | 29 |
30 template<> | 30 template<> |
31 struct hash<CrxInstaller*> { | 31 struct hash<CrxInstaller*> { |
32 std::size_t operator()(CrxInstaller* const& p) const { | 32 std::size_t operator()(CrxInstaller* const& p) const { |
33 return reinterpret_cast<std::size_t>(p); | 33 return reinterpret_cast<std::size_t>(p); |
34 } | 34 } |
35 }; | 35 }; |
36 | 36 |
37 } // namespace __gnu_cxx | 37 } // namespace __gnu_cxx |
38 #endif | 38 #endif |
39 | 39 |
40 // This is the Chrome side helper for the download system. | 40 // This is the Chrome side helper for the download system. |
41 class ChromeDownloadManagerDelegate | 41 class ChromeDownloadManagerDelegate |
42 : public base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>, | 42 : public base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>, |
43 public content::DownloadManagerDelegate, | 43 public content::DownloadManagerDelegate, |
44 public content::NotificationObserver { | 44 public content::NotificationObserver { |
45 public: | 45 public: |
46 explicit ChromeDownloadManagerDelegate(Profile* profile); | 46 explicit ChromeDownloadManagerDelegate(Profile* profile); |
47 | 47 |
48 void SetDownloadManager(DownloadManager* dm); | 48 void SetDownloadManager(DownloadManagerInterface* dm); |
49 | 49 |
50 // Returns true if the given item is for an extension download. | 50 // Returns true if the given item is for an extension download. |
51 static bool IsExtensionDownload(const DownloadItem* item); | 51 static bool IsExtensionDownload(const DownloadItem* item); |
52 | 52 |
53 virtual void Shutdown() OVERRIDE; | 53 virtual void Shutdown() OVERRIDE; |
54 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; | 54 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; |
55 virtual void ChooseDownloadPath(TabContents* tab_contents, | 55 virtual void ChooseDownloadPath(TabContents* tab_contents, |
56 const FilePath& suggested_path, | 56 const FilePath& suggested_path, |
57 void* data) OVERRIDE; | 57 void* data) OVERRIDE; |
58 virtual bool OverrideIntermediatePath(DownloadItem* item, | 58 virtual bool OverrideIntermediatePath(DownloadItem* item, |
(...skipping 24 matching lines...) Expand all Loading... |
83 | 83 |
84 DownloadPrefs* download_prefs() { return download_prefs_.get(); } | 84 DownloadPrefs* download_prefs() { return download_prefs_.get(); } |
85 DownloadHistory* download_history() { return download_history_.get(); } | 85 DownloadHistory* download_history() { return download_history_.get(); } |
86 | 86 |
87 protected: | 87 protected: |
88 // So that test classes can inherit from this for override purposes. | 88 // So that test classes can inherit from this for override purposes. |
89 virtual ~ChromeDownloadManagerDelegate(); | 89 virtual ~ChromeDownloadManagerDelegate(); |
90 | 90 |
91 // So that test classes that inherit from this for override purposes | 91 // So that test classes that inherit from this for override purposes |
92 // can call back into the DownloadManager. | 92 // can call back into the DownloadManager. |
93 scoped_refptr<DownloadManager> download_manager_; | 93 scoped_refptr<DownloadManagerInterface> download_manager_; |
94 | 94 |
95 private: | 95 private: |
96 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; | 96 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; |
97 | 97 |
98 // content::NotificationObserver implementation. | 98 // content::NotificationObserver implementation. |
99 virtual void Observe(int type, | 99 virtual void Observe(int type, |
100 const content::NotificationSource& source, | 100 const content::NotificationSource& source, |
101 const content::NotificationDetails& details) OVERRIDE; | 101 const content::NotificationDetails& details) OVERRIDE; |
102 | 102 |
103 // Callback function after url is checked with safebrowsing service. | 103 // Callback function after url is checked with safebrowsing service. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Maps from pending extension installations to DownloadItem IDs. | 147 // Maps from pending extension installations to DownloadItem IDs. |
148 typedef base::hash_map<CrxInstaller*, int> CrxInstallerMap; | 148 typedef base::hash_map<CrxInstaller*, int> CrxInstallerMap; |
149 CrxInstallerMap crx_installers_; | 149 CrxInstallerMap crx_installers_; |
150 | 150 |
151 content::NotificationRegistrar registrar_; | 151 content::NotificationRegistrar registrar_; |
152 | 152 |
153 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 153 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
154 }; | 154 }; |
155 | 155 |
156 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 156 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |