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