blob: efc232673de2930f18e5a03275a03f5efd13d3ec [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]47665442012-07-27 02:31:2215class DownloadFileManager;
[email protected]db1d8f72012-07-13 19:23:1616class DownloadItemImpl;
[email protected]db1d8f72012-07-13 19:23:1617class BrowserContext;
[email protected]db1d8f72012-07-13 19:23:1618
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.
23class CONTENT_EXPORT DownloadItemImplDelegate {
24 public:
[email protected]53ac00e82012-10-18 20:59:2025 typedef base::Callback<void(
26 const FilePath&, // Target path
[email protected]35869622012-10-26 23:23:5527 DownloadItem::TargetDisposition, // overwrite/uniquify target
28 DownloadDangerType,
[email protected]53ac00e82012-10-18 20:59:2029 const FilePath& // Intermediate file path
30 )> DownloadTargetCallback;
31
[email protected]db1d8f72012-07-13 19:23:1632 DownloadItemImplDelegate();
33 virtual ~DownloadItemImplDelegate();
34
35 // Used for catching use-after-free errors.
36 void Attach();
37 void Detach();
38
[email protected]53ac00e82012-10-18 20:59:2039 // Request determination of the download target from the delegate.
40 virtual void DetermineDownloadTarget(
41 DownloadItemImpl* download, const DownloadTargetCallback& callback);
42
[email protected]18710a42a2012-10-17 19:50:4343 // 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]db1d8f72012-07-13 19:23:1652 // 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]53ac00e82012-10-18 20:59:2056 // Tests if a file type should be opened automatically.
57 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path);
58
[email protected]db1d8f72012-07-13 19:23:1659 // 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]db1d8f72012-07-13 19:23:1665 // For contextual issues like language and prefs.
[email protected]35869622012-10-26 23:23:5566 virtual BrowserContext* GetBrowserContext() const;
[email protected]db1d8f72012-07-13 19:23:1667
[email protected]47665442012-07-27 02:31:2268 // Get the DownloadFileManager to use for this download.
69 virtual DownloadFileManager* GetDownloadFileManager();
70
[email protected]18710a42a2012-10-17 19:50:4371 // Update the persistent store with our information.
72 virtual void UpdatePersistence(DownloadItemImpl* download);
73
[email protected]db1d8f72012-07-13 19:23:1674 // 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]35869622012-10-26 23:23:5594} // namespace content
95
[email protected]db1d8f72012-07-13 19:23:1696#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_