summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 14:55:57 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 14:55:57 +0000
commitb441a849460cc2fca0ce9a18fe8e255cadc0656c (patch)
tree83610aa4039deac864b88cbc1c3df02b92e004f0
parent7a2dbfbf3cfea03bca0cfa79c639e0683dc11569 (diff)
downloadchromium_src-b441a849460cc2fca0ce9a18fe8e255cadc0656c.zip
chromium_src-b441a849460cc2fca0ce9a18fe8e255cadc0656c.tar.gz
chromium_src-b441a849460cc2fca0ce9a18fe8e255cadc0656c.tar.bz2
Move creation and ownership of DownloadManager from the embedder to content. This matches all the other objects that content depends on.
In a followup change, I'll make content support NULL DownloadManagerDelegates to match the rest of the delegate interfaces. BUG=98716 Review URL: https://chromiumcodereview.appspot.com/10535026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140761 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/app_controller_mac.mm3
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc15
-rw-r--r--chrome/browser/browsing_data_remover.cc2
-rw-r--r--chrome/browser/chromeos/gdata/gdata_system_service.cc6
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.cc14
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.h2
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate_unittest.cc5
-rw-r--r--chrome/browser/download/download_browsertest.cc10
-rw-r--r--chrome/browser/download/download_extension_api.cc11
-rw-r--r--chrome/browser/download/download_extension_test.cc5
-rw-r--r--chrome/browser/download/download_prefs.cc8
-rw-r--r--chrome/browser/download/download_service.cc79
-rw-r--r--chrome/browser/download/download_service.h16
-rw-r--r--chrome/browser/download/save_page_browsertest.cc4
-rw-r--r--chrome/browser/extensions/crx_installer_browsertest.cc3
-rw-r--r--chrome/browser/extensions/webstore_installer.cc9
-rw-r--r--chrome/browser/plugin_installer.cc9
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.cc7
-rw-r--r--chrome/browser/profiles/off_the_record_profile_impl.h3
-rw-r--r--chrome/browser/profiles/profile_impl.cc7
-rw-r--r--chrome/browser/profiles/profile_impl.h3
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc7
-rw-r--r--chrome/browser/ui/browser_close_browsertest.cc9
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc3
-rw-r--r--chrome/browser/ui/webui/downloads_dom_handler.cc5
-rw-r--r--chrome/browser/ui/webui/downloads_ui.cc4
-rw-r--r--chrome/browser/ui/webui/options2/browser_options_handler2.cc9
-rw-r--r--chrome/test/base/testing_profile.cc4
-rw-r--r--chrome/test/base/testing_profile.h3
-rw-r--r--content/browser/browser_context.cc22
-rw-r--r--content/browser/download/download_manager_impl.cc29
-rw-r--r--content/browser/download/download_manager_impl.h4
-rw-r--r--content/browser/download/download_manager_impl_unittest.cc16
-rw-r--r--content/browser/download/download_request_handle.cc3
-rw-r--r--content/browser/download/drag_download_file.cc4
-rw-r--r--content/browser/download/save_package.cc4
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_browsertest.cc5
-rw-r--r--content/browser/web_contents/web_contents_impl.cc12
-rw-r--r--content/public/browser/browser_context.h9
-rw-r--r--content/public/browser/content_browser_client.h3
-rw-r--r--content/public/browser/download_manager.h10
-rw-r--r--content/public/test/mock_download_manager.h1
-rw-r--r--content/public/test/test_browser_context.h2
-rw-r--r--content/shell/shell_browser_context.cc12
-rw-r--r--content/shell/shell_browser_context.h5
-rw-r--r--content/test/test_browser_context.cc2
46 files changed, 219 insertions, 189 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index d91752f..05fe908 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -74,6 +74,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
using content::UserMetricsAction;
@@ -676,7 +677,7 @@ const AEEventClass kAECloudPrintUninstallClass = 'GCPu';
DownloadServiceFactory::GetForProfile(profiles[i]);
DownloadManager* download_manager =
(download_service->HasCreatedDownloadManager() ?
- download_service->GetDownloadManager() : NULL);
+ BrowserContext::GetDownloadManager(profiles[i]) : NULL);
if (download_manager && download_manager->InProgressCount() > 0) {
int downloadCount = download_manager->InProgressCount();
if ([self userWillWaitForInProgressDownloads:downloadCount]) {
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index 4218dd1..09f277f 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -177,6 +177,7 @@ using automation::Error;
using automation::ErrorCode;
using automation_util::SendErrorIfModalDialogActive;
using content::BrowserChildProcessHostIterator;
+using content::BrowserContext;
using content::BrowserThread;
using content::ChildProcessHost;
using content::DownloadItem;
@@ -1148,7 +1149,8 @@ void TestingAutomationProvider::GetDownloadDirectory(
int handle, FilePath* download_directory) {
if (tab_tracker_->ContainsHandle(handle)) {
NavigationController* tab = tab_tracker_->GetResource(handle);
- DownloadManager* dlm = tab->GetBrowserContext()->GetDownloadManager();
+ DownloadManager* dlm =
+ BrowserContext::GetDownloadManager(tab->GetBrowserContext());
*download_directory =
DownloadPrefs::FromDownloadManager(dlm)->download_path();
}
@@ -2628,7 +2630,7 @@ void TestingAutomationProvider::GetDownloadsInfo(Browser* browser,
if (download_service->HasCreatedDownloadManager()) {
std::vector<DownloadItem*> downloads;
- download_service->GetDownloadManager()->
+ BrowserContext::GetDownloadManager(browser->profile())->
GetAllDownloads(FilePath(), &downloads);
for (std::vector<DownloadItem*>::iterator it = downloads.begin();
@@ -2663,7 +2665,8 @@ void TestingAutomationProvider::WaitForAllDownloadsToComplete(
// This observer will delete itself.
new AllDownloadsCompleteObserver(
- this, reply_message, download_service->GetDownloadManager(),
+ this, reply_message,
+ BrowserContext::GetDownloadManager(browser->profile()),
pre_download_ids);
}
@@ -2709,7 +2712,8 @@ void TestingAutomationProvider::PerformActionOnDownload(
return;
}
- DownloadManager* download_manager = download_service->GetDownloadManager();
+ DownloadManager* download_manager =
+ BrowserContext::GetDownloadManager(browser->profile());
DownloadItem* selected_item = GetDownloadItemFromId(id, download_manager);
if (!selected_item) {
AutomationJSONReply(this, reply_message)
@@ -3330,8 +3334,7 @@ void TestingAutomationProvider::SaveTabContents(
}
// The observer will delete itself when done.
new SavePackageNotificationObserver(
- DownloadServiceFactory::GetForProfile(
- browser->profile())->GetDownloadManager(),
+ BrowserContext::GetDownloadManager(browser->profile()),
this, reply_message);
}
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index b61f255..81d4b93 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -265,7 +265,7 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
if (remove_mask & REMOVE_DOWNLOADS) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager();
+ BrowserContext::GetDownloadManager(profile_);
download_manager->RemoveDownloadsBetween(delete_begin_, delete_end_);
download_manager->ClearLastDownloadPath();
}
diff --git a/chrome/browser/chromeos/gdata/gdata_system_service.cc b/chrome/browser/chromeos/gdata/gdata_system_service.cc
index ead6767..19f962a 100644
--- a/chrome/browser/chromeos/gdata/gdata_system_service.cc
+++ b/chrome/browser/chromeos/gdata/gdata_system_service.cc
@@ -15,9 +15,12 @@
#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
#include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
#include "chrome/browser/chromeos/gdata/gdata_uploader.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+using content::BrowserContext;
using content::BrowserThread;
namespace gdata {
@@ -48,8 +51,7 @@ void GDataSystemService::Initialize() {
content::DownloadManager* download_manager =
g_browser_process->download_status_updater() ?
- DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager() :
- NULL;
+ BrowserContext::GetDownloadManager(profile_) : NULL;
download_observer_->Initialize(
uploader_.get(),
download_manager,
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index 89f83e2..9f3ec30 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -57,6 +57,7 @@
#include "chrome/browser/download/save_package_file_picker_chromeos.h"
#endif
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadId;
using content::DownloadItem;
@@ -109,7 +110,13 @@ ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
}
+void ChromeDownloadManagerDelegate::ProfileShutdown() {
+ download_history_.reset();
+ download_prefs_.reset();
+}
+
void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
+ AddRef(); // Will be balanced in Shutdown().
download_manager_ = dm;
download_history_.reset(new DownloadHistory(profile_));
download_history_->Load(
@@ -118,16 +125,15 @@ void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
}
void ChromeDownloadManagerDelegate::Shutdown() {
- download_history_.reset();
- download_prefs_.reset();
+ Release(); // Balance the AddRef in SetDownloadManager.
}
DownloadId ChromeDownloadManagerDelegate::GetNextId() {
if (!profile_->IsOffTheRecord())
return DownloadId(this, next_download_id_++);
- return profile_->GetOriginalProfile()->GetDownloadManager()->delegate()->
- GetNextId();
+ return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())->
+ delegate()->GetNextId();
}
bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) {
diff --git a/chrome/browser/download/chrome_download_manager_delegate.h b/chrome/browser/download/chrome_download_manager_delegate.h
index 76e73f1..1773a5ae 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.h
+++ b/chrome/browser/download/chrome_download_manager_delegate.h
@@ -48,6 +48,8 @@ class ChromeDownloadManagerDelegate
void SetDownloadManager(content::DownloadManager* dm);
+ void ProfileShutdown();
+
// Should be called before the first call to ShouldCompleteDownload() to
// disable SafeBrowsing checks for |item|.
static void DisableSafeBrowsing(content::DownloadItem* item);
diff --git a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
index a84649f..83157ec 100644
--- a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc
@@ -201,6 +201,7 @@ class ChromeDownloadManagerDelegateTest : public ::testing::Test {
// ::testing::Test
virtual void SetUp() OVERRIDE;
+ virtual void TearDown() OVERRIDE;
// Verifies and clears test expectations for |delegate_| and
// |download_manager_|.
@@ -268,6 +269,10 @@ void ChromeDownloadManagerDelegateTest::SetUp() {
SetDefaultDownloadPath(test_download_dir_.path());
}
+void ChromeDownloadManagerDelegateTest::TearDown() {
+ delegate_->Shutdown();
+}
+
void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() {
::testing::Mock::VerifyAndClearExpectations(delegate_);
::testing::Mock::VerifyAndClearExpectations(download_manager_);
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index 61c4007..56e22d9 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -64,6 +64,7 @@
#include "net/test/test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -85,8 +86,6 @@ class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate {
public:
explicit PickSuggestedFileDelegate(Profile* profile)
: ChromeDownloadManagerDelegate(profile) {
- SetDownloadManager(
- DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager());
}
virtual void ChooseDownloadPath(WebContents* web_contents,
@@ -186,8 +185,7 @@ class MockAutoConfirmExtensionInstallUI : public ExtensionInstallUI {
};
static DownloadManager* DownloadManagerForBrowser(Browser* browser) {
- return DownloadServiceFactory::GetForProfile(browser->profile())
- ->GetDownloadManager();
+ return BrowserContext::GetDownloadManager(browser->profile());
}
class TestRenderViewContextMenu : public RenderViewContextMenu {
@@ -1401,7 +1399,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) {
observer1->WaitForFinished();
std::vector<DownloadItem*> downloads;
- browser()->profile()->GetDownloadManager()->SearchDownloads(
+ DownloadManagerForBrowser(browser())->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(1u, downloads.size());
ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
@@ -1416,7 +1414,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) {
// Should now have 2 items on the download shelf.
downloads.clear();
- browser()->profile()->GetDownloadManager()->SearchDownloads(
+ DownloadManagerForBrowser(browser())->SearchDownloads(
string16(), &downloads);
ASSERT_EQ(2u, downloads.size());
// We don't know the order of the downloads.
diff --git a/chrome/browser/download/download_extension_api.cc b/chrome/browser/download/download_extension_api.cc
index de5a5657..b19c22c 100644
--- a/chrome/browser/download/download_extension_api.cc
+++ b/chrome/browser/download/download_extension_api.cc
@@ -47,6 +47,7 @@
#include "net/http/http_util.h"
#include "net/url_request/url_request.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadId;
using content::DownloadItem;
@@ -313,12 +314,12 @@ void GetManagers(
Profile* profile,
bool include_incognito,
DownloadManager** manager, DownloadManager** incognito_manager) {
- *manager = DownloadServiceFactory::GetForProfile(profile)->
- GetDownloadManager();
+ *manager = BrowserContext::GetDownloadManager(profile);
*incognito_manager = NULL;
- if (include_incognito && profile->HasOffTheRecordProfile())
- *incognito_manager = DownloadServiceFactory::GetForProfile(profile->
- GetOffTheRecordProfile())->GetDownloadManager();
+ if (include_incognito && profile->HasOffTheRecordProfile()) {
+ *incognito_manager = BrowserContext::GetDownloadManager(
+ profile->GetOffTheRecordProfile());
+ }
}
DownloadItem* GetActiveItemInternal(
diff --git a/chrome/browser/download/download_extension_test.cc b/chrome/browser/download/download_extension_test.cc
index 02e2c4e..fb6ca46 100644
--- a/chrome/browser/download/download_extension_test.cc
+++ b/chrome/browser/download/download_extension_test.cc
@@ -28,6 +28,7 @@
#include "net/base/net_util.h"
#include "ui/gfx/codec/png_codec.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -75,9 +76,7 @@ class DownloadExtensionTest : public InProcessBrowserTest {
}
virtual DownloadManager* GetDownloadManager() {
- DownloadService* download_service =
- DownloadServiceFactory::GetForProfile(current_browser()->profile());
- return download_service->GetDownloadManager();
+ return BrowserContext::GetDownloadManager(current_browser()->profile());
}
// Creates a set of history downloads based on the provided |history_info|
diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc
index e8fbca5..1941c47 100644
--- a/chrome/browser/download/download_prefs.cc
+++ b/chrome/browser/download/download_prefs.cc
@@ -31,6 +31,7 @@
#include "chrome/browser/chromeos/gdata/gdata_util.h"
#endif
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
@@ -116,11 +117,8 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager(
// static
DownloadPrefs* DownloadPrefs::FromBrowserContext(
- content::BrowserContext* browser_context) {
- Profile* profile = static_cast<Profile*>(browser_context);
- DownloadService* download_service =
- DownloadServiceFactory::GetForProfile(profile);
- return FromDownloadManager(download_service->GetDownloadManager());
+ content::BrowserContext* context) {
+ return FromDownloadManager(BrowserContext::GetDownloadManager(context));
}
bool DownloadPrefs::PromptForDownload() const {
diff --git a/chrome/browser/download/download_service.cc b/chrome/browser/download/download_service.cc
index 1fd1908..278fac4 100644
--- a/chrome/browser/download/download_service.cc
+++ b/chrome/browser/download/download_service.cc
@@ -14,7 +14,9 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/download_manager.h"
+using content::BrowserContext;
using content::DownloadManager;
+using content::DownloadManagerDelegate;
DownloadService::DownloadService(Profile* profile)
: download_manager_created_(false),
@@ -25,37 +27,39 @@ DownloadService::~DownloadService() {}
void DownloadService::OnManagerCreated(
const DownloadService::OnManagerCreatedCallback& cb) {
+ DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
if (download_manager_created_) {
- cb.Run(manager_.get());
+ cb.Run(dm);
} else {
on_manager_created_callbacks_.push_back(cb);
}
}
-DownloadManager* DownloadService::GetDownloadManager() {
- if (!download_manager_created_) {
- // In case the delegate has already been set by
- // SetDownloadManagerDelegateForTesting.
- if (!manager_delegate_.get())
- manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
- manager_ = DownloadManager::Create(manager_delegate_.get(),
- g_browser_process->net_log());
- manager_->Init(profile_);
- manager_delegate_->SetDownloadManager(manager_);
-
- // Include this download manager in the set monitored by the
- // global status updater.
- g_browser_process->download_status_updater()->AddManager(manager_);
-
- download_manager_created_ = true;
- for (std::vector<OnManagerCreatedCallback>::iterator cb
- = on_manager_created_callbacks_.begin();
- cb != on_manager_created_callbacks_.end(); ++cb) {
- cb->Run(manager_.get());
- }
- on_manager_created_callbacks_.clear();
+DownloadManagerDelegate* DownloadService::GetDownloadManagerDelegate() {
+ DCHECK(!download_manager_created_);
+ download_manager_created_ = true;
+
+ // In case the delegate has already been set by
+ // SetDownloadManagerDelegateForTesting.
+ if (!manager_delegate_.get())
+ manager_delegate_ = new ChromeDownloadManagerDelegate(profile_);
+
+ DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
+ manager_delegate_->SetDownloadManager(dm);
+
+ // Include this download manager in the set monitored by the
+ // global status updater.
+ g_browser_process->download_status_updater()->AddManager(dm);
+
+ download_manager_created_ = true;
+ for (std::vector<OnManagerCreatedCallback>::iterator cb
+ = on_manager_created_callbacks_.begin();
+ cb != on_manager_created_callbacks_.end(); ++cb) {
+ cb->Run(dm);
}
- return manager_.get();
+ on_manager_created_callbacks_.clear();
+
+ return manager_delegate_.get();
}
bool DownloadService::HasCreatedDownloadManager() {
@@ -63,7 +67,8 @@ bool DownloadService::HasCreatedDownloadManager() {
}
int DownloadService::DownloadCount() const {
- return download_manager_created_ ? manager_->InProgressCount() : 0;
+ DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
+ return download_manager_created_ ? dm->InProgressCount() : 0;
}
// static
@@ -86,27 +91,15 @@ int DownloadService::DownloadCountAllProfiles() {
void DownloadService::SetDownloadManagerDelegateForTesting(
ChromeDownloadManagerDelegate* new_delegate) {
// Guarantee everything is properly initialized.
- GetDownloadManager();
-
- manager_->SetDownloadManagerDelegate(new_delegate);
- new_delegate->SetDownloadManager(manager_);
+ DownloadManager* dm = BrowserContext::GetDownloadManager(profile_);
+ dm->SetDownloadManagerDelegate(new_delegate);
+ new_delegate->SetDownloadManager(dm);
manager_delegate_ = new_delegate;
}
void DownloadService::Shutdown() {
- if (manager_.get()) {
- manager_->Shutdown();
-
- // The manager reference can be released any time after shutdown;
- // it will be destroyed when the last reference is released on the
- // FILE thread.
- // Resetting here will guarantee that any attempts to get the
- // DownloadManager after shutdown will return null.
- //
- // TODO(rdsmith): Figure out how to guarantee when the last reference
- // will be released and make DownloadManager not RefCountedThreadSafe<>.
- manager_.release();
- }
- if (manager_delegate_.get())
+ if (manager_delegate_.get()) {
+ manager_delegate_->ProfileShutdown();
manager_delegate_.release();
+ }
}
diff --git a/chrome/browser/download/download_service.h b/chrome/browser/download/download_service.h
index 4e15771..78613d8 100644
--- a/chrome/browser/download/download_service.h
+++ b/chrome/browser/download/download_service.h
@@ -18,10 +18,10 @@ class Profile;
namespace content {
class DownloadManager;
+class DownloadManagerDelegate;
}
-// Owning class for DownloadManager (content) and
-// ChromeDownloadManagerDelegate (chrome)
+// Owning class for ChromeDownloadManagerDelegate.
class DownloadService : public ProfileKeyedService {
public:
explicit DownloadService(Profile* profile);
@@ -32,11 +32,10 @@ class DownloadService : public ProfileKeyedService {
OnManagerCreatedCallback;
void OnManagerCreated(const OnManagerCreatedCallback& cb);
- // Get the download manager. Creates the download manager if
- // it does not already exist.
- content::DownloadManager* GetDownloadManager();
+ // Get the download manager delegate, creating it if it doesn't already exist.
+ content::DownloadManagerDelegate* GetDownloadManagerDelegate();
- // Has a download manager been created? (By calling above function.)
+ // Has a download manager been created?
bool HasCreatedDownloadManager();
// Number of downloads associated with this instance of the service.
@@ -59,14 +58,9 @@ class DownloadService : public ProfileKeyedService {
bool download_manager_created_;
Profile* profile_;
- // Both of these objects are owned by this class.
- // DownloadManager is RefCountedThreadSafe because of references
- // from DownloadFile objects on the FILE thread, and may need to be
- // kept alive until those objects are deleted.
// ChromeDownloadManagerDelegate may be the target of callbacks from
// the history service/DB thread and must be kept alive for those
// callbacks.
- scoped_refptr<content::DownloadManager> manager_;
scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_;
std::vector<OnManagerCreatedCallback> on_manager_created_callbacks_;
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc
index 28a0847..ec727d1 100644
--- a/chrome/browser/download/save_page_browsertest.cc
+++ b/chrome/browser/download/save_page_browsertest.cc
@@ -43,6 +43,7 @@
#include "chrome/browser/download/save_package_file_picker.h"
#endif
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -115,8 +116,7 @@ class SavePageBrowserTest : public InProcessBrowserTest {
DownloadManager* GetDownloadManager() const {
DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(
- browser()->profile())->GetDownloadManager();
+ BrowserContext::GetDownloadManager(browser()->profile());
EXPECT_TRUE(download_manager);
return download_manager;
}
diff --git a/chrome/browser/extensions/crx_installer_browsertest.cc b/chrome/browser/extensions/crx_installer_browsertest.cc
index 41a51f5..01f16d2 100644
--- a/chrome/browser/extensions/crx_installer_browsertest.cc
+++ b/chrome/browser/extensions/crx_installer_browsertest.cc
@@ -164,8 +164,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
LOG(ERROR) << "PackAndInstallExtension: Getting download manager";
content::DownloadManager* download_manager =
- DownloadServiceFactory::GetForProfile(
- browser()->profile())->GetDownloadManager();
+ content::BrowserContext::GetDownloadManager(browser()->profile());
LOG(ERROR) << "PackAndInstallExtension: Setting observer";
scoped_ptr<DownloadTestObserver> observer(
diff --git a/chrome/browser/extensions/webstore_installer.cc b/chrome/browser/extensions/webstore_installer.cc
index d119341..e78da83 100644
--- a/chrome/browser/extensions/webstore_installer.cc
+++ b/chrome/browser/extensions/webstore_installer.cc
@@ -38,9 +38,11 @@
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadId;
using content::DownloadItem;
+using content::DownloadManager;
using content::NavigationController;
using content::DownloadUrlParameters;
@@ -191,7 +193,7 @@ void WebstoreInstaller::Start() {
}
FilePath download_path = DownloadPrefs::FromDownloadManager(
- profile_->GetDownloadManager())->download_path();
+ BrowserContext::GetDownloadManager(profile_))->download_path();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&GetDownloadFilePath, download_path, id_,
@@ -264,7 +266,8 @@ void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) {
CHECK(id.IsValid());
- content::DownloadManager* download_manager = profile_->GetDownloadManager();
+ DownloadManager* download_manager =
+ BrowserContext::GetDownloadManager(profile_);
download_item_ = download_manager->GetActiveDownloadItem(id.local());
download_item_->AddObserver(this);
if (approval_.get())
@@ -323,7 +326,7 @@ void WebstoreInstaller::StartDownload(const FilePath& file) {
content::Referrer(controller_->GetActiveEntry()->GetURL(),
WebKit::WebReferrerPolicyDefault));
params->set_callback(base::Bind(&WebstoreInstaller::OnDownloadStarted, this));
- profile_->GetDownloadManager()->DownloadUrl(params.Pass());
+ BrowserContext::GetDownloadManager(profile_)->DownloadUrl(params.Pass());
}
void WebstoreInstaller::ReportFailure(const std::string& error) {
diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc
index 9e83746..7bb8849 100644
--- a/chrome/browser/plugin_installer.cc
+++ b/chrome/browser/plugin_installer.cc
@@ -27,8 +27,10 @@
#include "net/url_request/url_request.h"
#include "webkit/plugins/npapi/plugin_group.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
+using content::DownloadManager;
using content::ResourceDispatcherHost;
namespace {
@@ -192,8 +194,8 @@ void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) {
state_ = INSTALLER_STATE_DOWNLOADING;
FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted());
content::WebContents* web_contents = wrapper->web_contents();
- DownloadService* download_service =
- DownloadServiceFactory::GetForProfile(wrapper->profile());
+ DownloadManager* download_manager =
+ BrowserContext::GetDownloadManager(wrapper->profile());
download_util::RecordDownloadSource(
download_util::INITIATED_BY_PLUGIN_INSTALLER);
BrowserThread::PostTask(
@@ -205,8 +207,7 @@ void PluginInstaller::StartInstalling(TabContentsWrapper* wrapper) {
web_contents->GetRenderViewHost()->GetRoutingID(),
base::Bind(&PluginInstaller::DownloadStarted,
base::Unretained(this),
- make_scoped_refptr(
- download_service->GetDownloadManager()))));
+ make_scoped_refptr(download_manager))));
}
void PluginInstaller::DownloadStarted(
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc
index 7c92c21..96564a6 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.cc
+++ b/chrome/browser/profiles/off_the_record_profile_impl.cc
@@ -57,7 +57,7 @@
#endif
using content::BrowserThread;
-using content::DownloadManager;
+using content::DownloadManagerDelegate;
using content::HostZoomMap;
namespace {
@@ -258,8 +258,9 @@ PrefService* OffTheRecordProfileImpl::GetOffTheRecordPrefs() {
return prefs_;
}
-DownloadManager* OffTheRecordProfileImpl::GetDownloadManager() {
- return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager();
+DownloadManagerDelegate* OffTheRecordProfileImpl::GetDownloadManagerDelegate() {
+ return DownloadServiceFactory::GetForProfile(this)->
+ GetDownloadManagerDelegate();
}
net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() {
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h
index 91b9059..f7c1a66 100644
--- a/chrome/browser/profiles/off_the_record_profile_impl.h
+++ b/chrome/browser/profiles/off_the_record_profile_impl.h
@@ -92,7 +92,8 @@ class OffTheRecordProfileImpl : public Profile,
// content::BrowserContext implementation:
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
- virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual content::DownloadManagerDelegate*
+ GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index ba2e92d..c85ecbe 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -107,7 +107,7 @@
using base::Time;
using base::TimeDelta;
using content::BrowserThread;
-using content::DownloadManager;
+using content::DownloadManagerDelegate;
using content::HostZoomMap;
using content::UserMetricsAction;
@@ -831,8 +831,9 @@ history::ShortcutsBackend* ProfileImpl::GetShortcutsBackend() {
return shortcuts_backend_.get();
}
-DownloadManager* ProfileImpl::GetDownloadManager() {
- return DownloadServiceFactory::GetForProfile(this)->GetDownloadManager();
+DownloadManagerDelegate* ProfileImpl::GetDownloadManagerDelegate() {
+ return DownloadServiceFactory::GetForProfile(this)->
+ GetDownloadManagerDelegate();
}
bool ProfileImpl::DidLastSessionExitCleanly() {
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index e84c561..5797daa 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -54,7 +54,8 @@ class ProfileImpl : public Profile,
// content::BrowserContext implementation:
virtual FilePath GetPath() OVERRIDE;
- virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual content::DownloadManagerDelegate*
+ GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index cbd934d..33188d7 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -93,6 +93,7 @@ using WebKit::WebMediaPlayerAction;
using WebKit::WebPluginAction;
using WebKit::WebString;
using WebKit::WebURL;
+using content::BrowserContext;
using content::ChildProcessSecurityPolicy;
using content::DownloadManager;
using content::DownloadUrlParameters;
@@ -1520,8 +1521,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
const GURL& url = params_.link_url;
content::DownloadSaveInfo save_info;
save_info.prompt_for_save_location = true;
- DownloadManager* dlm =
- DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager();
+ DownloadManager* dlm = BrowserContext::GetDownloadManager(profile_);
scoped_ptr<DownloadUrlParameters> dl_params(
DownloadUrlParameters::FromWebContents(
source_web_contents_, url, save_info));
@@ -1548,8 +1548,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
if (entry)
post_id = entry->GetPostID();
}
- DownloadManager* dlm =
- DownloadServiceFactory::GetForProfile(profile_)->GetDownloadManager();
+ DownloadManager* dlm = BrowserContext::GetDownloadManager(profile_);
scoped_ptr<DownloadUrlParameters> dl_params(
DownloadUrlParameters::FromWebContents(
source_web_contents_, url, save_info));
diff --git a/chrome/browser/ui/browser_close_browsertest.cc b/chrome/browser/ui/browser_close_browsertest.cc
index 97f8e89..cbbf3ce 100644
--- a/chrome/browser/ui/browser_close_browsertest.cc
+++ b/chrome/browser/ui/browser_close_browsertest.cc
@@ -25,6 +25,7 @@
#include "content/public/common/page_transition_types.h"
#include "content/test/net/url_request_slow_download_job.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -112,7 +113,7 @@ class BrowserCloseTest : public InProcessBrowserTest {
// Setup an observer waiting for the given number of downloads
// to get to IN_PROGRESS.
DownloadManager* download_manager =
- browser->profile()->GetDownloadManager();
+ BrowserContext::GetDownloadManager(browser->profile());
scoped_ptr<DownloadTestObserver> observer(
new DownloadTestObserverInProgress(download_manager,
num_downloads,
@@ -146,7 +147,7 @@ class BrowserCloseTest : public InProcessBrowserTest {
DownloadService* download_service =
DownloadServiceFactory::GetForProfile(*pit);
if (download_service->HasCreatedDownloadManager()) {
- DownloadManager *mgr = download_service->GetDownloadManager();
+ DownloadManager *mgr = BrowserContext::GetDownloadManager(*pit);
scoped_refptr<DownloadTestFlushObserver> observer(
new DownloadTestFlushObserver(mgr));
observer->WaitForFlush();
@@ -156,8 +157,8 @@ class BrowserCloseTest : public InProcessBrowserTest {
DownloadServiceFactory::GetForProfile(
(*pit)->GetOffTheRecordProfile());
if (incognito_download_service->HasCreatedDownloadManager()) {
- DownloadManager *mgr =
- incognito_download_service->GetDownloadManager();
+ DownloadManager *mgr = BrowserContext::GetDownloadManager(
+ (*pit)->GetOffTheRecordProfile());
scoped_refptr<DownloadTestFlushObserver> observer(
new DownloadTestFlushObserver(mgr));
observer->WaitForFlush();
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index 0595764..e5b7d65 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -39,6 +39,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/screen.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -1598,7 +1599,7 @@ class DownloadObserver : public content::DownloadManager::Observer {
public:
explicit DownloadObserver(Profile* profile)
: download_manager_(
- DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager()),
+ BrowserContext::GetDownloadManager(profile)),
saw_download_(false),
waiting_(false) {
download_manager_->AddObserver(this);
diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc
index 8d04503..bad5ef5 100644
--- a/chrome/browser/ui/webui/downloads_dom_handler.cc
+++ b/chrome/browser/ui/webui/downloads_dom_handler.cc
@@ -45,6 +45,7 @@
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
#endif
+using content::BrowserContext;
using content::BrowserThread;
using content::UserMetricsAction;
@@ -101,8 +102,8 @@ DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm)
// Figure out our parent DownloadManager, if any.
Profile* original_profile = profile->GetOriginalProfile();
if (original_profile != profile) {
- original_profile_download_manager_ = DownloadServiceFactory::GetForProfile(
- original_profile)->GetDownloadManager();
+ original_profile_download_manager_ =
+ BrowserContext::GetDownloadManager(original_profile);
}
}
diff --git a/chrome/browser/ui/webui/downloads_ui.cc b/chrome/browser/ui/webui/downloads_ui.cc
index cfd7183..098e9c1 100644
--- a/chrome/browser/ui/webui/downloads_ui.cc
+++ b/chrome/browser/ui/webui/downloads_ui.cc
@@ -27,6 +27,7 @@
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
+using content::BrowserContext;
using content::DownloadManager;
using content::WebContents;
@@ -89,8 +90,7 @@ ChromeWebUIDataSource* CreateDownloadsUIHTMLSource() {
DownloadsUI::DownloadsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
Profile* profile = Profile::FromWebUI(web_ui);
- DownloadManager* dlm =
- DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager();
+ DownloadManager* dlm = BrowserContext::GetDownloadManager(profile);
DownloadsDOMHandler* handler = new DownloadsDOMHandler(dlm);
web_ui->AddMessageHandler(handler);
diff --git a/chrome/browser/ui/webui/options2/browser_options_handler2.cc b/chrome/browser/ui/webui/options2/browser_options_handler2.cc
index 195f8a2..b5f272e 100644
--- a/chrome/browser/ui/webui/options2/browser_options_handler2.cc
+++ b/chrome/browser/ui/webui/options2/browser_options_handler2.cc
@@ -98,6 +98,7 @@
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#endif // defined(TOOLKIT_GTK)
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
using content::OpenURLParams;
@@ -1058,8 +1059,8 @@ void BrowserOptionsHandler::MouseExists(bool exists) {
void BrowserOptionsHandler::HandleAutoOpenButton(const ListValue* args) {
content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
- DownloadManager* manager =
- web_ui()->GetWebContents()->GetBrowserContext()->GetDownloadManager();
+ DownloadManager* manager = BrowserContext::GetDownloadManager(
+ web_ui()->GetWebContents()->GetBrowserContext());
if (manager)
DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
}
@@ -1369,8 +1370,8 @@ void BrowserOptionsHandler::SetupPageZoomSelector() {
void BrowserOptionsHandler::SetupAutoOpenFileTypes() {
// Set the hidden state for the AutoOpenFileTypesResetToDefault button.
// We show the button if the user has any auto-open file types registered.
- DownloadManager* manager =
- web_ui()->GetWebContents()->GetBrowserContext()->GetDownloadManager();
+ DownloadManager* manager = BrowserContext::GetDownloadManager(
+ web_ui()->GetWebContents()->GetBrowserContext());
bool display = manager &&
DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed();
base::FundamentalValue value(display);
diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc
index 565babc..348f212 100644
--- a/chrome/test/base/testing_profile.cc
+++ b/chrome/test/base/testing_profile.cc
@@ -68,7 +68,7 @@
using base::Time;
using content::BrowserThread;
-using content::DownloadManager;
+using content::DownloadManagerDelegate;
using testing::NiceMock;
using testing::Return;
@@ -541,7 +541,7 @@ history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
return top_sites_.get();
}
-DownloadManager* TestingProfile::GetDownloadManager() {
+DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
return NULL;
}
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index e05a446..48cf6ca 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -128,7 +128,8 @@ class TestingProfile : public Profile {
// content::BrowserContext
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
- virtual content::DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual content::DownloadManagerDelegate*
+ GetDownloadManagerDelegate() OVERRIDE;
// Returns a testing ContextGetter (if one has been created via
// CreateRequestContext) or NULL. This is not done on-demand for two reasons:
// (1) Some tests depend on GetRequestContext() returning NULL. (2) Because
diff --git a/content/browser/browser_context.cc b/content/browser/browser_context.cc
index 5bda8e2..17e60d9 100644
--- a/content/browser/browser_context.cc
+++ b/content/browser/browser_context.cc
@@ -6,10 +6,12 @@
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/dom_storage/dom_storage_context_impl.h"
+#include "content/browser/download/download_manager_impl.h"
#include "content/browser/fileapi/browser_file_system_helper.h"
#include "content/browser/in_process_webkit/indexed_db_context_impl.h"
#include "content/browser/resource_context_impl.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_constants.h"
#include "net/base/server_bound_cert_service.h"
#include "net/base/server_bound_cert_store.h"
@@ -30,6 +32,7 @@ using webkit_database::DatabaseTracker;
static const char* kAppCacheServicKeyName = "content_appcache_service_tracker";
static const char* kDatabaseTrackerKeyName = "content_database_tracker";
static const char* kDOMStorageContextKeyName = "content_dom_storage_context";
+static const char* kDownloadManagerKeyName = "download_manager";
static const char* kFileSystemContextKeyName = "content_file_system_context";
static const char* kIndexedDBContextKeyName = "content_indexed_db_context";
static const char* kQuotaManagerKeyName = "content_quota_manager";
@@ -136,6 +139,22 @@ DOMStorageContextImpl* GetDOMStorageContextImpl(BrowserContext* context) {
} // namespace
+DownloadManager* BrowserContext::GetDownloadManager(
+ BrowserContext* context) {
+ if (!context->GetUserData(kDownloadManagerKeyName)) {
+ scoped_refptr<DownloadManager> download_manager = new DownloadManagerImpl(
+ GetContentClient()->browser()->GetNetLog());
+ context->SetUserData(
+ kDownloadManagerKeyName,
+ new UserDataAdapter<DownloadManager>(download_manager));
+ download_manager->SetDelegate(context->GetDownloadManagerDelegate());
+ download_manager->Init(context);
+ }
+
+ return UserDataAdapter<DownloadManager>::Get(
+ context, kDownloadManagerKeyName);
+}
+
QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) {
CreateQuotaManagerAndClients(context);
return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName);
@@ -229,6 +248,9 @@ BrowserContext::~BrowserContext() {
if (GetUserData(kDOMStorageContextKeyName))
GetDOMStorageContextImpl(this)->Shutdown();
+
+ if (GetUserData(kDownloadManagerKeyName))
+ GetDownloadManager(this)->Shutdown();
}
} // namespace content
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 3296daa..45e2c98 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -140,13 +140,6 @@ void EnsureNoPendingDownloadJobsOnIO(bool* result) {
namespace content {
-// static
-DownloadManager* DownloadManager::Create(
- content::DownloadManagerDelegate* delegate,
- net::NetLog* net_log) {
- return new DownloadManagerImpl(delegate, net_log);
-}
-
bool DownloadManager::EnsureNoPendingDownloadsForTesting() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
bool result = true;
@@ -159,14 +152,12 @@ bool DownloadManager::EnsureNoPendingDownloadsForTesting() {
} // namespace content
-DownloadManagerImpl::DownloadManagerImpl(
- content::DownloadManagerDelegate* delegate,
- net::NetLog* net_log)
- : shutdown_needed_(false),
- browser_context_(NULL),
- file_manager_(NULL),
- delegate_(delegate),
- net_log_(net_log) {
+DownloadManagerImpl::DownloadManagerImpl(net::NetLog* net_log)
+ : shutdown_needed_(false),
+ browser_context_(NULL),
+ file_manager_(NULL),
+ delegate_(NULL),
+ net_log_(net_log) {
}
DownloadManagerImpl::~DownloadManagerImpl() {
@@ -185,6 +176,11 @@ bool DownloadManagerImpl::ShouldOpenFileBasedOnExtension(const FilePath& path) {
return delegate_->ShouldOpenFileBasedOnExtension(path);
}
+void DownloadManagerImpl::SetDelegate(
+ content::DownloadManagerDelegate* delegate) {
+ delegate_ = delegate;
+}
+
void DownloadManagerImpl::Shutdown() {
VLOG(20) << __FUNCTION__ << "()"
<< " shutdown_needed_ = " << shutdown_needed_;
@@ -249,7 +245,8 @@ void DownloadManagerImpl::Shutdown() {
DCHECK(save_page_downloads_.empty());
file_manager_ = NULL;
- delegate_->Shutdown();
+ if (delegate_)
+ delegate_->Shutdown();
}
void DownloadManagerImpl::GetTemporaryDownloads(
diff --git a/content/browser/download/download_manager_impl.h b/content/browser/download/download_manager_impl.h
index ad1a027..1539d5b 100644
--- a/content/browser/download/download_manager_impl.h
+++ b/content/browser/download/download_manager_impl.h
@@ -25,10 +25,10 @@ class CONTENT_EXPORT DownloadManagerImpl
: public content::DownloadManager,
public DownloadItemImpl::Delegate {
public:
- DownloadManagerImpl(content::DownloadManagerDelegate* delegate,
- net::NetLog* net_log);
+ explicit DownloadManagerImpl(net::NetLog* net_log);
// content::DownloadManager functions.
+ virtual void SetDelegate(content::DownloadManagerDelegate* delegate) OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void GetTemporaryDownloads(const FilePath& dir_path,
DownloadVector* result) OVERRIDE;
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc
index 1be540f..325f914 100644
--- a/content/browser/download/download_manager_impl_unittest.cc
+++ b/content/browser/download/download_manager_impl_unittest.cc
@@ -104,21 +104,17 @@ DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain";
class TestDownloadManagerDelegate : public content::DownloadManagerDelegate {
public:
- TestDownloadManagerDelegate()
+ explicit TestDownloadManagerDelegate(content::DownloadManager* dm)
: mark_content_dangerous_(false),
prompt_user_for_save_location_(false),
should_complete_download_(true),
- download_manager_(NULL) {
+ download_manager_(dm) {
}
void set_download_directory(const FilePath& path) {
download_directory_ = path;
}
- void set_download_manager(content::DownloadManager* dm) {
- download_manager_ = dm;
- }
-
void set_prompt_user_for_save_location(bool value) {
prompt_user_for_save_location_ = value;
}
@@ -262,13 +258,13 @@ class DownloadManagerTest : public testing::Test {
DownloadManagerTest()
: browser_context(new content::TestBrowserContext()),
- download_manager_delegate_(new TestDownloadManagerDelegate()),
- download_manager_(new DownloadManagerImpl(
- download_manager_delegate_.get(), NULL)),
+ download_manager_(new DownloadManagerImpl(NULL)),
ui_thread_(BrowserThread::UI, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_) {
+ download_manager_delegate_.reset(
+ new TestDownloadManagerDelegate(download_manager_.get()));
+ download_manager_->SetDelegate(download_manager_delegate_.get());
download_manager_->Init(browser_context.get());
- download_manager_delegate_->set_download_manager(download_manager_);
}
~DownloadManagerTest() {
diff --git a/content/browser/download/download_request_handle.cc b/content/browser/download/download_request_handle.cc
index 31158305..43682e4 100644
--- a/content/browser/download/download_request_handle.cc
+++ b/content/browser/download/download_request_handle.cc
@@ -11,6 +11,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
using content::RenderViewHostImpl;
@@ -56,7 +57,7 @@ DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
content::BrowserContext* context = rph->GetBrowserContext();
if (context == NULL)
return NULL;
- return context->GetDownloadManager();
+ return BrowserContext::GetDownloadManager(context);
}
void DownloadRequestHandle::PauseRequest() const {
diff --git a/content/browser/download/drag_download_file.cc b/content/browser/download/drag_download_file.cc
index cbb4cab..38f0df0 100644
--- a/content/browser/download/drag_download_file.cc
+++ b/content/browser/download/drag_download_file.cc
@@ -16,6 +16,7 @@
#include "content/public/browser/download_url_parameters.h"
#include "net/base/file_stream.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::DownloadManager;
@@ -127,7 +128,8 @@ void DragDownloadFile::InitiateDownload() {
}
#endif
- download_manager_ = web_contents_->GetBrowserContext()->GetDownloadManager();
+ download_manager_ = BrowserContext::GetDownloadManager(
+ web_contents_->GetBrowserContext());
download_manager_observer_added_ = true;
download_manager_->AddObserver(this);
diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc
index a473292..5537747 100644
--- a/content/browser/download/save_package.cc
+++ b/content/browser/download/save_package.cc
@@ -45,6 +45,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializerClient.h"
using base::Time;
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadItem;
using content::NavigationEntry;
@@ -263,7 +264,8 @@ void SavePackage::InternalInit() {
file_manager_ = rdh->save_file_manager();
DCHECK(file_manager_);
- download_manager_ = web_contents()->GetBrowserContext()->GetDownloadManager();
+ download_manager_ = BrowserContext::GetDownloadManager(
+ web_contents()->GetBrowserContext());
DCHECK(download_manager_);
download_stats::RecordSavePackageEvent(download_stats::SAVE_PACKAGE_STARTED);
diff --git a/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc b/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc
index 23cf9f7..4bda0a53 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc
@@ -25,6 +25,7 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
+using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
@@ -190,7 +191,7 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
SniffNoContentTypeNoData) {
// Make sure no downloads start.
- GetBrowserContext()->GetDownloadManager()->AddObserver(this);
+ BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this);
CheckTitleTest(GetMockURL("content-sniffer-test3.html"),
"Content Sniffer Test 3", 1);
EXPECT_EQ(1, browser()->tab_count());
@@ -248,7 +249,7 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
SyncXMLHttpRequest_DuringUnload) {
ASSERT_TRUE(test_server()->Start());
- GetBrowserContext()->GetDownloadManager()->AddObserver(this);
+ BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this);
CheckTitleTest(
test_server()->GetURL("files/sync_xmlhttprequest_during_unload.html"),
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 0872c9e..7fbe843 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -122,6 +122,7 @@
// the user goes back. The process only stays live if another tab is using
// it, but if so, the existing frame relationships will be maintained.
+using content::BrowserContext;
using content::DevToolsAgentHost;
using content::DevToolsAgentHostRegistry;
using content::DevToolsManagerImpl;
@@ -1154,10 +1155,10 @@ void WebContentsImpl::CreateNewWindow(
// WebContentsView. In the future, we may want to create the view separately.
WebContentsImpl* new_contents = new WebContentsImpl(
GetBrowserContext(),
- site_instance,
- route_id,
- this,
- params.opener_suppressed ? NULL : this,
+ site_instance,
+ route_id,
+ this,
+ params.opener_suppressed ? NULL : this,
static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
@@ -3044,7 +3045,8 @@ void WebContentsImpl::SetEncoding(const std::string& encoding) {
void WebContentsImpl::SaveURL(const GURL& url,
const content::Referrer& referrer,
bool is_main_frame) {
- DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
+ DownloadManager* dlm =
+ BrowserContext::GetDownloadManager(GetBrowserContext());
if (!dlm)
return;
int64 post_id = -1;
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index 7b0103b..4fff026 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -37,6 +37,7 @@ namespace content {
class DOMStorageContext;
class DownloadManager;
+class DownloadManagerDelegate;
class GeolocationPermissionContext;
class IndexedDBContext;
class ResourceContext;
@@ -46,6 +47,7 @@ class SpeechRecognitionPreferences;
// It lives on the UI thread.
class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
public:
+ static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
static quota::QuotaManager* GetQuotaManager(BrowserContext* browser_context);
static DOMStorageContext* GetDOMStorageContext(
BrowserContext* browser_context);
@@ -80,9 +82,6 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
// This doesn't belong here; http://crbug.com/89628
virtual bool IsOffTheRecord() const = 0;
- // Returns the DownloadManager associated with this context.
- virtual content::DownloadManager* GetDownloadManager() = 0;
-
// Returns the request context information associated with this context. Call
// this only on the UI thread, since it can send notifications that should
// happen on the UI thread.
@@ -104,6 +103,10 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
// Returns the resource context.
virtual ResourceContext* GetResourceContext() = 0;
+ // Returns the DownloadManagerDelegate for this context. This will be called
+ // once per context. It's valid to return NULL.
+ virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
+
// Returns the geolocation permission context for this context.
virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 3a0a825..81fed12 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -20,7 +20,6 @@ class CommandLine;
class FilePath;
class GURL;
class PluginProcessHost;
-class ResourceDispatcherHost;
namespace webkit_glue {
struct WebPreferences;
@@ -353,7 +352,7 @@ class CONTENT_EXPORT ContentBrowserClient {
ResourceContext* context);
// Notifies the embedder that the ResourceDispatcherHost has been created.
- // This is when it can optionally add a delegate or ResourceQueueDelegates.
+ // This is when it can optionally add a delegate.
virtual void ResourceDispatcherHostCreated() {}
// Allows the embedder to return a delegate for the SpeechRecognitionManager.
diff --git a/content/public/browser/download_manager.h b/content/public/browser/download_manager.h
index b029c28..01b601c 100644
--- a/content/public/browser/download_manager.h
+++ b/content/public/browser/download_manager.h
@@ -60,15 +60,15 @@ class DownloadUrlParameters;
class CONTENT_EXPORT DownloadManager
: public base::RefCountedThreadSafe<DownloadManager> {
public:
- static DownloadManager* Create(
- DownloadManagerDelegate* delegate,
- net::NetLog* net_log);
-
// A method that can be used in tests to ensure that all the internal download
// classes have no pending downloads.
static bool EnsureNoPendingDownloadsForTesting();
- // Shutdown the download manager. Must be called before destruction.
+ // Sets the delegate for this DownloadManager. The delegate has to live past
+ // its Shutdown method being called.
+ virtual void SetDelegate(DownloadManagerDelegate* delegate) = 0;
+
+ // Shutdown the download manager. Called by content before destruction.
virtual void Shutdown() = 0;
// Interface to implement for observers that wish to be informed of changes
diff --git a/content/public/test/mock_download_manager.h b/content/public/test/mock_download_manager.h
index 5db35c2..42a9845 100644
--- a/content/public/test/mock_download_manager.h
+++ b/content/public/test/mock_download_manager.h
@@ -23,6 +23,7 @@ class MockDownloadManager : public content::DownloadManager {
MockDownloadManager();
// DownloadManager:
+ MOCK_METHOD1(SetDelegate, void(DownloadManagerDelegate* delegate));
MOCK_METHOD0(Shutdown, void());
MOCK_METHOD2(GetTemporaryDownloads, void(const FilePath& dir_path,
DownloadVector* result));
diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h
index 3a73a69..633df5a 100644
--- a/content/public/test/test_browser_context.h
+++ b/content/public/test/test_browser_context.h
@@ -30,7 +30,7 @@ class TestBrowserContext : public BrowserContext {
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
- virtual DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc
index 678edfc..92f618b 100644
--- a/content/shell/shell_browser_context.cc
+++ b/content/shell/shell_browser_context.cc
@@ -126,15 +126,9 @@ bool ShellBrowserContext::IsOffTheRecord() const {
return false;
}
-DownloadManager* ShellBrowserContext::GetDownloadManager() {
- if (!download_manager_.get()) {
- download_manager_delegate_ = new ShellDownloadManagerDelegate();
- download_manager_ = DownloadManager::Create(download_manager_delegate_,
- NULL);
- download_manager_delegate_->SetDownloadManager(download_manager_.get());
- download_manager_->Init(this);
- }
- return download_manager_.get();
+DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
+ download_manager_delegate_ = new ShellDownloadManagerDelegate();
+ return download_manager_delegate_.get();
}
net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h
index c2eaadc..d363d3e 100644
--- a/content/shell/shell_browser_context.h
+++ b/content/shell/shell_browser_context.h
@@ -12,8 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_context.h"
-class DownloadManager;
-
namespace content {
class DownloadManagerDelegate;
@@ -29,7 +27,7 @@ class ShellBrowserContext : public BrowserContext {
// BrowserContext implementation.
virtual FilePath GetPath() OVERRIDE;
virtual bool IsOffTheRecord() const OVERRIDE;
- virtual DownloadManager* GetDownloadManager() OVERRIDE;
+ virtual DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
int renderer_child_id) OVERRIDE;
@@ -50,7 +48,6 @@ class ShellBrowserContext : public BrowserContext {
FilePath path_;
scoped_ptr<ResourceContext> resource_context_;
scoped_refptr<ShellDownloadManagerDelegate> download_manager_delegate_;
- scoped_refptr<DownloadManager> download_manager_;
scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
scoped_refptr<SpeechRecognitionPreferences> speech_recognition_preferences_;
diff --git a/content/test/test_browser_context.cc b/content/test/test_browser_context.cc
index 2596732..556b2d8 100644
--- a/content/test/test_browser_context.cc
+++ b/content/test/test_browser_context.cc
@@ -36,7 +36,7 @@ bool TestBrowserContext::IsOffTheRecord() const {
return false;
}
-DownloadManager* TestBrowserContext::GetDownloadManager() {
+DownloadManagerDelegate* TestBrowserContext::GetDownloadManagerDelegate() {
return NULL;
}