[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ | ||||
6 | #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ | ||||
7 | |||||
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 8 | #include "base/callback.h" |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 9 | #include "base/file_path.h" |
10 | #include "content/common/content_export.h" | ||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 11 | #include "content/public/browser/download_danger_type.h" |
12 | #include "content/public/browser/download_item.h" | ||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 13 | |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 14 | namespace content { |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 15 | class DownloadItemImpl; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 16 | class BrowserContext; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 17 | |
18 | // Delegate for operations that a DownloadItemImpl can't do for itself. | ||||
19 | // The base implementation of this class does nothing (returning false | ||||
20 | // on predicates) so interfaces not of interest to a derived class may | ||||
21 | // be left unimplemented. | ||||
22 | class CONTENT_EXPORT DownloadItemImplDelegate { | ||||
23 | public: | ||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 24 | typedef base::Callback<void( |
25 | const FilePath&, // Target path | ||||
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 26 | DownloadItem::TargetDisposition, // overwrite/uniquify target |
27 | DownloadDangerType, | ||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 28 | const FilePath& // Intermediate file path |
29 | )> DownloadTargetCallback; | ||||
30 | |||||
[email protected] | bde0e4f | 2012-11-08 22:49:59 | [diff] [blame] | 31 | // The boolean argument indicates whether or not the download was |
32 | // actually opened. | ||||
33 | typedef base::Callback<void(bool)> ShouldOpenDownloadCallback; | ||||
34 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 35 | DownloadItemImplDelegate(); |
36 | virtual ~DownloadItemImplDelegate(); | ||||
37 | |||||
38 | // Used for catching use-after-free errors. | ||||
39 | void Attach(); | ||||
40 | void Detach(); | ||||
41 | |||||
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 42 | // Request determination of the download target from the delegate. |
43 | virtual void DetermineDownloadTarget( | ||||
44 | DownloadItemImpl* download, const DownloadTargetCallback& callback); | ||||
45 | |||||
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 46 | // Allows the delegate to delay completion of the download. This function |
47 | // will call the callback passed when the download is ready for completion. | ||||
48 | // This may be done immediately, from within the routine itself, or it | ||||
49 | // may be delayed. | ||||
50 | // This routine should only be called once per download. | ||||
51 | virtual void ReadyForDownloadCompletion( | ||||
52 | DownloadItemImpl* download, | ||||
53 | const base::Closure& complete_callback); | ||||
54 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 55 | // Allows the delegate to override the opening of a download. If it returns |
56 | // true then it's reponsible for opening the item. | ||||
[email protected] | bde0e4f | 2012-11-08 22:49:59 | [diff] [blame] | 57 | virtual bool ShouldOpenDownload( |
58 | DownloadItemImpl* download, const ShouldOpenDownloadCallback& callback); | ||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 59 | |
[email protected] | 53ac00e8 | 2012-10-18 20:59:20 | [diff] [blame] | 60 | // Tests if a file type should be opened automatically. |
61 | virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); | ||||
62 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 63 | // Checks whether a downloaded file still exists and updates the |
64 | // file's state if the file is already removed. | ||||
65 | // The check may or may not result in a later asynchronous call | ||||
66 | // to OnDownloadedFileRemoved(). | ||||
67 | virtual void CheckForFileRemoval(DownloadItemImpl* download_item); | ||||
68 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 69 | // For contextual issues like language and prefs. |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 70 | virtual BrowserContext* GetBrowserContext() const; |
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 71 | |
[email protected] | 18710a42a | 2012-10-17 19:50:43 | [diff] [blame] | 72 | // Update the persistent store with our information. |
73 | virtual void UpdatePersistence(DownloadItemImpl* download); | ||||
74 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 75 | // Handle any delegate portions of a state change operation on the |
76 | // DownloadItem. | ||||
77 | virtual void DownloadStopped(DownloadItemImpl* download); | ||||
78 | virtual void DownloadCompleted(DownloadItemImpl* download); | ||||
79 | virtual void DownloadOpened(DownloadItemImpl* download); | ||||
80 | virtual void DownloadRemoved(DownloadItemImpl* download); | ||||
[email protected] | 3d95e54 | 2012-11-20 00:52:08 | [diff] [blame^] | 81 | |
82 | // Show the download in the browser. | ||||
83 | virtual void ShowDownloadInBrowser(DownloadItemImpl* download); | ||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 84 | |
85 | // Assert consistent state for delgate object at various transitions. | ||||
86 | virtual void AssertStateConsistent(DownloadItemImpl* download) const; | ||||
87 | |||||
88 | private: | ||||
89 | // For "Outlives attached DownloadItemImpl" invariant assertion. | ||||
90 | int count_; | ||||
91 | |||||
92 | DISALLOW_COPY_AND_ASSIGN(DownloadItemImplDelegate); | ||||
93 | }; | ||||
94 | |||||
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 95 | } // namespace content |
96 | |||||
[email protected] | db1d8f7 | 2012-07-13 19:23:16 | [diff] [blame] | 97 | #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ |