15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_danger_type.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/download_item.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/download_url_parameters.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DownloadItemImpl; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserContext; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Delegate for operations that a DownloadItemImpl can't do for itself. 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The base implementation of this class does nothing (returning false 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// on predicates) so interfaces not of interest to a derived class may 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// be left unimplemented. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CONTENT_EXPORT DownloadItemImplDelegate { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void( 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath&, // Target path 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadItem::TargetDisposition, // overwrite/uniquify target 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadDangerType, 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& // Intermediate file path 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) )> DownloadTargetCallback; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The boolean argument indicates whether or not the download was 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // actually opened. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef base::Callback<void(bool)> ShouldOpenDownloadCallback; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadItemImplDelegate(); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DownloadItemImplDelegate(); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used for catching use-after-free errors. 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Attach(); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Detach(); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Request determination of the download target from the delegate. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DetermineDownloadTarget( 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadItemImpl* download, const DownloadTargetCallback& callback); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allows the delegate to delay completion of the download. This function 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // will either return true (if the download may complete now) or will return 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // false and call the provided callback at some future point. This function 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // may be called repeatedly. 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool ShouldCompleteDownload( 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadItemImpl* download, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Closure& complete_callback); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allows the delegate to override the opening of a download. If it returns 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true then it's reponsible for opening the item. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool ShouldOpenDownload( 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DownloadItemImpl* download, const ShouldOpenDownloadCallback& callback); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tests if a file type should be opened automatically. 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool ShouldOpenFileBasedOnExtension(const base::FilePath& path); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks whether a downloaded file still exists and updates the 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file's state if the file is already removed. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The check may or may not result in a later asynchronous call 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to OnDownloadedFileRemoved(). 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void CheckForFileRemoval(DownloadItemImpl* download_item); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when an interrupted download is resumed. 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ResumeInterruptedDownload( 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<content::DownloadUrlParameters> params, 727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch uint32 id); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For contextual issues like language and prefs. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual BrowserContext* GetBrowserContext() const; 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the persistent store with our information. 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void UpdatePersistence(DownloadItemImpl* download); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Opens the file associated with this download. 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OpenDownload(DownloadItemImpl* download); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Shows the download via the OS shell. 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void ShowDownloadInShell(DownloadItemImpl* download); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Handle any delegate portions of a state change operation on the 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // DownloadItem. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DownloadRemoved(DownloadItemImpl* download); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Assert consistent state for delgate object at various transitions. 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AssertStateConsistent(DownloadItemImpl* download) const; 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For "Outlives attached DownloadItemImpl" invariant assertion. 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int count_; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DownloadItemImplDelegate); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_DELEGATE_H_ 103