blob: 4d6beb792ea789e6b62ac040d8afe5a846fe218f [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
[email protected]18710a42a2012-10-17 19:50:438#include "base/callback.h"
[email protected]db1d8f72012-07-13 19:23:169#include "base/file_path.h"
10#include "content/common/content_export.h"
[email protected]53ac00e82012-10-18 20:59:2011#include "content/public/browser/download_danger_type.h"
12#include "content/public/browser/download_item.h"
[email protected]db1d8f72012-07-13 19:23:1613
[email protected]35869622012-10-26 23:23:5514namespace content {
[email protected]db1d8f72012-07-13 19:23:1615class DownloadItemImpl;
[email protected]db1d8f72012-07-13 19:23:1616class BrowserContext;
[email protected]db1d8f72012-07-13 19:23:1617
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.
22class CONTENT_EXPORT DownloadItemImplDelegate {
23 public:
[email protected]53ac00e82012-10-18 20:59:2024 typedef base::Callback<void(
25 const FilePath&, // Target path
[email protected]35869622012-10-26 23:23:5526 DownloadItem::TargetDisposition, // overwrite/uniquify target
27 DownloadDangerType,
[email protected]53ac00e82012-10-18 20:59:2028 const FilePath& // Intermediate file path
29 )> DownloadTargetCallback;
30
[email protected]bde0e4f2012-11-08 22:49:5931 // The boolean argument indicates whether or not the download was
32 // actually opened.
33 typedef base::Callback<void(bool)> ShouldOpenDownloadCallback;
34
[email protected]db1d8f72012-07-13 19:23:1635 DownloadItemImplDelegate();
36 virtual ~DownloadItemImplDelegate();
37
38 // Used for catching use-after-free errors.
39 void Attach();
40 void Detach();
41
[email protected]53ac00e82012-10-18 20:59:2042 // Request determination of the download target from the delegate.
43 virtual void DetermineDownloadTarget(
44 DownloadItemImpl* download, const DownloadTargetCallback& callback);
45
[email protected]18710a42a2012-10-17 19:50:4346 // 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]db1d8f72012-07-13 19:23:1655 // 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]bde0e4f2012-11-08 22:49:5957 virtual bool ShouldOpenDownload(
58 DownloadItemImpl* download, const ShouldOpenDownloadCallback& callback);
[email protected]db1d8f72012-07-13 19:23:1659
[email protected]53ac00e82012-10-18 20:59:2060 // Tests if a file type should be opened automatically.
61 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path);
62
[email protected]db1d8f72012-07-13 19:23:1663 // 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]db1d8f72012-07-13 19:23:1669 // For contextual issues like language and prefs.
[email protected]35869622012-10-26 23:23:5570 virtual BrowserContext* GetBrowserContext() const;
[email protected]db1d8f72012-07-13 19:23:1671
[email protected]18710a42a2012-10-17 19:50:4372 // Update the persistent store with our information.
73 virtual void UpdatePersistence(DownloadItemImpl* download);
74
[email protected]db1d8f72012-07-13 19:23:1675 // 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]3d95e542012-11-20 00:52:0881
82 // Show the download in the browser.
83 virtual void ShowDownloadInBrowser(DownloadItemImpl* download);
[email protected]db1d8f72012-07-13 19:23:1684
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]35869622012-10-26 23:23:5595} // namespace content
96
[email protected]db1d8f72012-07-13 19:23:1697#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_