summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-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
17 files changed, 80 insertions, 63 deletions
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;
}