From 861b4d0a0b0cf9e5224d004eb99ce768221000ed Mon Sep 17 00:00:00 2001 From: "asanka@chromium.org" Date: Fri, 13 Dec 2013 20:10:41 +0000 Subject: [Downloads] Make ChromeDownloadManagerDelegate owned by DownloadService. Currently ChromeDownloadManagerDelegate is reference counted. Since it also posts long running tasks, this causes it to outlive the associated profile on occasion. Since there are multiple references to Profile/BrowserContext owned objects from within CDMD, this can introduce subtle use-after-free errors. This change is to make CDMD owned by DownloadService so that it doesn't outlive the Profile. BUG=317913 Review URL: https://codereview.chromium.org/69793006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240726 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/lifetime/browser_close_manager_browsertest.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'chrome/browser/lifetime/browser_close_manager_browsertest.cc') diff --git a/chrome/browser/lifetime/browser_close_manager_browsertest.cc b/chrome/browser/lifetime/browser_close_manager_browsertest.cc index c6ba1ce..dd3e1fde 100644 --- a/chrome/browser/lifetime/browser_close_manager_browsertest.cc +++ b/chrome/browser/lifetime/browser_close_manager_browsertest.cc @@ -171,19 +171,20 @@ class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate { public: explicit TestDownloadManagerDelegate(Profile* profile) : ChromeDownloadManagerDelegate(profile) { - SetNextId(content::DownloadItem::kInvalidId + 1); + GetDownloadIdReceiverCallback().Run(content::DownloadItem::kInvalidId + 1); } + virtual ~TestDownloadManagerDelegate() {} virtual bool DetermineDownloadTarget( content::DownloadItem* item, const content::DownloadTargetCallback& callback) OVERRIDE { content::DownloadTargetCallback dangerous_callback = - base::Bind(&TestDownloadManagerDelegate::SetDangerous, this, callback); + base::Bind(&TestDownloadManagerDelegate::SetDangerous, callback); return ChromeDownloadManagerDelegate::DetermineDownloadTarget( item, dangerous_callback); } - void SetDangerous( + static void SetDangerous( const content::DownloadTargetCallback& callback, const base::FilePath& target_path, content::DownloadItem::TargetDisposition disp, @@ -194,9 +195,6 @@ class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate { content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, intermediate_path); } - - private: - virtual ~TestDownloadManagerDelegate() {} }; class FakeBackgroundModeManager : public BackgroundModeManager { @@ -700,10 +698,11 @@ IN_PROC_BROWSER_TEST_P(BrowserCloseManagerBrowserTest, ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); // Set up the fake delegate that forces the download to be malicious. - scoped_refptr test_delegate( + scoped_ptr test_delegate( new TestDownloadManagerDelegate(browser()->profile())); DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> - SetDownloadManagerDelegateForTesting(test_delegate.get()); + SetDownloadManagerDelegateForTesting( + test_delegate.PassAs()); // Run a dangerous download, but the user doesn't make a decision. // This .swf normally would be categorized as DANGEROUS_FILE, but -- cgit v1.1