blob: 5c3805988749674383db474d80a135663fcd3a8f [file] [log] [blame]
[email protected]db1d8f72012-07-13 19:23:161// 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
avib7348942015-12-25 20:57:108#include <stdint.h>
9
[email protected]18710a42a2012-10-17 19:50:4310#include "base/callback.h"
[email protected]57999812013-02-24 05:40:5211#include "base/files/file_path.h"
avib7348942015-12-25 20:57:1012#include "base/macros.h"
[email protected]db1d8f72012-07-13 19:23:1613#include "content/common/content_export.h"
[email protected]53ac00e82012-10-18 20:59:2014#include "content/public/browser/download_danger_type.h"
15#include "content/public/browser/download_item.h"
[email protected]8d68a3e02013-01-12 15:57:1016#include "content/public/browser/download_url_parameters.h"
[email protected]db1d8f72012-07-13 19:23:1617
[email protected]35869622012-10-26 23:23:5518namespace content {
[email protected]db1d8f72012-07-13 19:23:1619class DownloadItemImpl;
[email protected]db1d8f72012-07-13 19:23:1620class BrowserContext;
[email protected]db1d8f72012-07-13 19:23:1621
22// Delegate for operations that a DownloadItemImpl can't do for itself.
23// The base implementation of this class does nothing (returning false
24// on predicates) so interfaces not of interest to a derived class may
25// be left unimplemented.
26class CONTENT_EXPORT DownloadItemImplDelegate {
27 public:
[email protected]53ac00e82012-10-18 20:59:2028 typedef base::Callback<void(
[email protected]2dec8ec2013-02-07 19:20:3429 const base::FilePath&, // Target path
[email protected]35869622012-10-26 23:23:5530 DownloadItem::TargetDisposition, // overwrite/uniquify target
31 DownloadDangerType,
[email protected]2dec8ec2013-02-07 19:20:3432 const base::FilePath& // Intermediate file path
[email protected]53ac00e82012-10-18 20:59:2033 )> DownloadTargetCallback;
34
[email protected]bde0e4f2012-11-08 22:49:5935 // The boolean argument indicates whether or not the download was
36 // actually opened.
37 typedef base::Callback<void(bool)> ShouldOpenDownloadCallback;
38
[email protected]db1d8f72012-07-13 19:23:1639 DownloadItemImplDelegate();
40 virtual ~DownloadItemImplDelegate();
41
42 // Used for catching use-after-free errors.
43 void Attach();
44 void Detach();
45
[email protected]53ac00e82012-10-18 20:59:2046 // Request determination of the download target from the delegate.
47 virtual void DetermineDownloadTarget(
48 DownloadItemImpl* download, const DownloadTargetCallback& callback);
49
[email protected]18710a42a2012-10-17 19:50:4350 // Allows the delegate to delay completion of the download. This function
[email protected]98299622013-01-03 22:26:5051 // will either return true (if the download may complete now) or will return
52 // false and call the provided callback at some future point. This function
53 // may be called repeatedly.
54 virtual bool ShouldCompleteDownload(
[email protected]18710a42a2012-10-17 19:50:4355 DownloadItemImpl* download,
56 const base::Closure& complete_callback);
57
[email protected]db1d8f72012-07-13 19:23:1658 // Allows the delegate to override the opening of a download. If it returns
59 // true then it's reponsible for opening the item.
[email protected]bde0e4f2012-11-08 22:49:5960 virtual bool ShouldOpenDownload(
61 DownloadItemImpl* download, const ShouldOpenDownloadCallback& callback);
[email protected]db1d8f72012-07-13 19:23:1662
[email protected]53ac00e82012-10-18 20:59:2063 // Tests if a file type should be opened automatically.
[email protected]2dec8ec2013-02-07 19:20:3464 virtual bool ShouldOpenFileBasedOnExtension(const base::FilePath& path);
[email protected]53ac00e82012-10-18 20:59:2065
[email protected]db1d8f72012-07-13 19:23:1666 // Checks whether a downloaded file still exists and updates the
67 // file's state if the file is already removed.
68 // The check may or may not result in a later asynchronous call
69 // to OnDownloadedFileRemoved().
70 virtual void CheckForFileRemoval(DownloadItemImpl* download_item);
71
asanka4350f6a2016-03-15 02:40:5772 // Return a GUID string used for identifying the application to the system AV
asankabe2afd52016-10-05 14:29:0473 // function for scanning downloaded files. If no GUID is provided or if the
74 // provided GUID is invalid, then the appropriate quarantining will be
75 // performed manually without passing the download to the system AV function.
76 //
77 // This GUID is only used on Windows.
asanka4350f6a2016-03-15 02:40:5778 virtual std::string GetApplicationClientIdForFileScanning() const;
79
[email protected]8d68a3e02013-01-12 15:57:1080 // Called when an interrupted download is resumed.
81 virtual void ResumeInterruptedDownload(
dchengf6c40582016-04-09 00:05:1382 std::unique_ptr<content::DownloadUrlParameters> params,
avib7348942015-12-25 20:57:1083 uint32_t id);
[email protected]8d68a3e02013-01-12 15:57:1084
[email protected]db1d8f72012-07-13 19:23:1685 // For contextual issues like language and prefs.
[email protected]35869622012-10-26 23:23:5586 virtual BrowserContext* GetBrowserContext() const;
[email protected]db1d8f72012-07-13 19:23:1687
[email protected]18710a42a2012-10-17 19:50:4388 // Update the persistent store with our information.
89 virtual void UpdatePersistence(DownloadItemImpl* download);
90
[email protected]ffc0c2d2013-01-21 15:32:1291 // Opens the file associated with this download.
92 virtual void OpenDownload(DownloadItemImpl* download);
93
94 // Shows the download via the OS shell.
95 virtual void ShowDownloadInShell(DownloadItemImpl* download);
96
[email protected]db1d8f72012-07-13 19:23:1697 // Handle any delegate portions of a state change operation on the
98 // DownloadItem.
[email protected]db1d8f72012-07-13 19:23:1699 virtual void DownloadRemoved(DownloadItemImpl* download);
[email protected]3d95e542012-11-20 00:52:08100
[email protected]db1d8f72012-07-13 19:23:16101 // Assert consistent state for delgate object at various transitions.
102 virtual void AssertStateConsistent(DownloadItemImpl* download) const;
103
104 private:
105 // For "Outlives attached DownloadItemImpl" invariant assertion.
106 int count_;
107
108 DISALLOW_COPY_AND_ASSIGN(DownloadItemImplDelegate);
109};
110
[email protected]35869622012-10-26 23:23:55111} // namespace content
112
[email protected]db1d8f72012-07-13 19:23:16113#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_