diff options
Diffstat (limited to 'content')
33 files changed, 182 insertions, 142 deletions
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc index e49acb2..bfd23b4 100644 --- a/content/browser/browser_main_loop.cc +++ b/content/browser/browser_main_loop.cc @@ -13,11 +13,7 @@ #include "base/metrics/histogram.h" #include "base/threading/thread_restrictions.h" #include "content/browser/browser_thread_impl.h" -#include "content/browser/download/download_file_manager.h" -#include "content/browser/download/save_file_manager.h" #include "content/browser/in_process_webkit/webkit_thread.h" -#include "content/browser/plugin_service_impl.h" -#include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/trace_controller.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/sandbox_policy.h" @@ -294,12 +290,6 @@ void BrowserMainLoop::MainMessageLoopStart() { system_message_window_.reset(new SystemMessageWindowWin); #endif - // Prior to any processing happening on the io thread, we create the - // plugin service as it is predominantly used from the io thread, - // but must be created on the main thread. The service ctor is - // inexpensive and does not invoke the io_thread() accessor. - PluginService::GetInstance()->Init(); - if (parts_.get()) parts_->PostMainMessageLoopStart(); } @@ -368,6 +358,9 @@ void BrowserMainLoop::RunMainMessageLoopParts( BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); + if (parts_.get()) + parts_->PreStartThread(id); + if (thread_id == BrowserThread::WEBKIT_DEPRECATED) { webkit_thread_.reset(new WebKitThread); webkit_thread_->Initialize(); @@ -377,6 +370,9 @@ void BrowserMainLoop::RunMainMessageLoopParts( } else { NOTREACHED(); } + + if (parts_.get()) + parts_->PostStartThread(id); } if (parts_.get()) @@ -414,12 +410,6 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { if (parts_.get()) parts_->PostMainMessageLoopRun(); - // Cancel pending requests and prevent new requests. - ResourceDispatcherHost* rdh = ResourceDispatcherHost::IsCreated() ? - ResourceDispatcherHost::Get() : NULL; - if (rdh) - rdh->Shutdown(); - // Must be size_t so we can subtract from it. for (size_t thread_id = BrowserThread::ID_COUNT - 1; thread_id >= (BrowserThread::UI + 1); @@ -455,24 +445,12 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { case BrowserThread::WEBKIT_DEPRECATED: // Special case as WebKitThread is a separate // type. |thread_to_stop| is not used in this case. - - // Need to destroy ResourceDispatcherHost before PluginService - // and since it caches a pointer to it. - if (rdh) - delete rdh; break; case BrowserThread::FILE_USER_BLOCKING: thread_to_stop = &file_user_blocking_thread_; break; case BrowserThread::FILE: thread_to_stop = &file_thread_; - - // Clean up state that lives on or uses the file_thread_ before - // it goes away. - if (rdh) { - rdh->download_file_manager()->Shutdown(); - rdh->save_file_manager()->Shutdown(); - } break; case BrowserThread::PROCESS_LAUNCHER: thread_to_stop = &process_launcher_thread_; @@ -492,6 +470,9 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { BrowserThread::ID id = static_cast<BrowserThread::ID>(thread_id); + if (parts_.get()) + parts_->PreStopThread(id); + if (id == BrowserThread::WEBKIT_DEPRECATED) { webkit_thread_.reset(); } else if (thread_to_stop) { @@ -499,6 +480,9 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() { } else { NOTREACHED(); } + + if (parts_.get()) + parts_->PostStopThread(id); } if (parts_.get()) diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc index f3bb3b0..1487b19 100644 --- a/content/browser/download/download_manager_impl.cc +++ b/content/browser/download/download_manager_impl.cc @@ -86,18 +86,6 @@ void BeginDownload(const URLParams& url_params, } // namespace -namespace content { - -// static -DownloadManager* DownloadManager::Create( - content::DownloadManagerDelegate* delegate, - DownloadIdFactory* id_factory, - DownloadStatusUpdater* status_updater) { - return new DownloadManagerImpl(delegate, id_factory, status_updater); -} - -} // namespace content - DownloadManagerImpl::DownloadManagerImpl( content::DownloadManagerDelegate* delegate, DownloadIdFactory* id_factory, @@ -259,8 +247,15 @@ bool DownloadManagerImpl::Init(content::BrowserContext* browser_context) { browser_context_ = browser_context; - file_manager_ = ResourceDispatcherHost::Get()->download_file_manager(); - DCHECK(file_manager_); + // In test mode, there may be no ResourceDispatcherHost. In this case it's + // safe to avoid setting |file_manager_| because we only call a small set of + // functions, none of which need it. + ResourceDispatcherHost* rdh = + content::GetContentClient()->browser()->GetResourceDispatcherHost(); + if (rdh) { + file_manager_ = rdh->download_file_manager(); + DCHECK(file_manager_); + } return true; } @@ -786,7 +781,7 @@ void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, const DownloadSaveInfo& save_info, WebContents* web_contents) { ResourceDispatcherHost* resource_dispatcher_host = - ResourceDispatcherHost::Get(); + content::GetContentClient()->browser()->GetResourceDispatcherHost(); // We send a pointer to content::ResourceContext, instead of the usual // reference, so that a copy of the object isn't made. diff --git a/content/browser/download/download_manager_impl.h b/content/browser/download/download_manager_impl.h index 50fdf58..07bba75 100644 --- a/content/browser/download/download_manager_impl.h +++ b/content/browser/download/download_manager_impl.h @@ -7,6 +7,8 @@ #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ #pragma once +#include "content/public/browser/download_manager.h" + #include <map> #include <set> @@ -20,7 +22,6 @@ #include "content/browser/download/download_item_impl.h" #include "content/browser/download/download_status_updater_delegate.h" #include "content/common/content_export.h" -#include "content/public/browser/download_manager.h" class DownloadIdFactory; class DownloadStatusUpdater; diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc index 6095738..1ce1f21 100644 --- a/content/browser/download/save_package.cc +++ b/content/browser/download/save_package.cc @@ -241,7 +241,14 @@ void SavePackage::Cancel(bool user_action) { // Init() can be called directly, or indirectly via GetSaveInfo(). In both // cases, we need file_manager_ to be initialized, so we do this first. void SavePackage::InternalInit() { - file_manager_ = ResourceDispatcherHost::Get()->save_file_manager(); + ResourceDispatcherHost* rdh = + content::GetContentClient()->browser()->GetResourceDispatcherHost(); + if (!rdh) { + NOTREACHED(); + return; + } + + file_manager_ = rdh->save_file_manager(); DCHECK(file_manager_); download_manager_ = web_contents()->GetBrowserContext()->GetDownloadManager(); diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 0476f7d..a4ad86d 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -236,7 +236,8 @@ std::string MockContentBrowserClient::GetWorkerProcessTitle( return std::string(); } -void MockContentBrowserClient::ResourceDispatcherHostCreated() { +ResourceDispatcherHost* MockContentBrowserClient::GetResourceDispatcherHost() { + return NULL; } ui::Clipboard* MockContentBrowserClient::GetClipboard() { diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index 6e47710..14e9d4e17 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -125,7 +125,7 @@ class MockContentBrowserClient : public ContentBrowserClient { int render_process_id) OVERRIDE; virtual std::string GetWorkerProcessTitle( const GURL& url, const content::ResourceContext& context) OVERRIDE; - virtual void ResourceDispatcherHostCreated() OVERRIDE; + virtual ResourceDispatcherHost* GetResourceDispatcherHost() OVERRIDE; virtual ui::Clipboard* GetClipboard() OVERRIDE; virtual MHTMLGenerationManager* GetMHTMLGenerationManager() OVERRIDE; virtual net::NetLog* GetNetLog() OVERRIDE; diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc index dcfe740..a695441 100644 --- a/content/browser/plugin_process_host.cc +++ b/content/browser/plugin_process_host.cc @@ -164,7 +164,8 @@ PluginProcessHost::~PluginProcessHost() { CancelRequests(); } -bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { +bool PluginProcessHost::Init(const webkit::WebPluginInfo& info, + const std::string& locale) { info_ = info; set_name(info_.name); @@ -230,8 +231,6 @@ bool PluginProcessHost::Init(const webkit::WebPluginInfo& info) { if (!plugin_launcher.empty()) cmd_line->PrependWrapper(plugin_launcher); - std::string locale = - content::GetContentClient()->browser()->GetApplicationLocale(); if (!locale.empty()) { // Pass on the locale so the null plugin will use the right language in the // prompt to install the desired plugin. diff --git a/content/browser/plugin_process_host.h b/content/browser/plugin_process_host.h index 2fabe64..6ce5f08 100644 --- a/content/browser/plugin_process_host.h +++ b/content/browser/plugin_process_host.h @@ -67,7 +67,7 @@ class CONTENT_EXPORT PluginProcessHost : public BrowserChildProcessHost { // Initialize the new plugin process, returning true on success. This must // be called before the object can be used. - bool Init(const webkit::WebPluginInfo& info); + bool Init(const webkit::WebPluginInfo& info, const std::string& locale); // Force the plugin process to shutdown (cleanly). void ForceShutdown(); diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc index 4dcc47c..8cd4cbc 100644 --- a/content/browser/plugin_service_impl.cc +++ b/content/browser/plugin_service_impl.cc @@ -135,7 +135,10 @@ PluginServiceImpl* PluginServiceImpl::GetInstance() { } PluginServiceImpl::PluginServiceImpl() - : plugin_list_(NULL), filter_(NULL) { + : plugin_list_(NULL), + ui_locale_( + content::GetContentClient()->browser()->GetApplicationLocale()), + filter_(NULL) { } PluginServiceImpl::~PluginServiceImpl() { @@ -229,6 +232,10 @@ void PluginServiceImpl::StartWatchingPlugins() { #endif } +const std::string& PluginServiceImpl::GetUILocale() { + return ui_locale_; +} + PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( const FilePath& plugin_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -290,7 +297,7 @@ PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( // This plugin isn't loaded by any plugin process, so create a new process. scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); - if (!new_host->Init(info)) { + if (!new_host->Init(info, ui_locale_)) { NOTREACHED(); // Init is not expected to fail. return NULL; } diff --git a/content/browser/plugin_service_impl.h b/content/browser/plugin_service_impl.h index a9aee11..4a2c203 100644 --- a/content/browser/plugin_service_impl.h +++ b/content/browser/plugin_service_impl.h @@ -106,6 +106,9 @@ class CONTENT_EXPORT PluginServiceImpl virtual void SetPluginListForTesting( webkit::npapi::PluginList* plugin_list) OVERRIDE; + // Gets the browser's UI locale. + const std::string& GetUILocale(); + // Like FindNpapiPluginProcess but for Pepper. PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path); PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path); @@ -197,6 +200,9 @@ class CONTENT_EXPORT PluginServiceImpl // The plugin list instance. webkit::npapi::PluginList* plugin_list_; + // The browser's UI locale. + const std::string ui_locale_; + content::NotificationRegistrar registrar_; #if defined(OS_WIN) diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index 113fcae..37bc99e 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -271,7 +271,8 @@ RenderMessageFilter::RenderMessageFilter( content::BrowserContext* browser_context, net::URLRequestContextGetter* request_context, RenderWidgetHelper* render_widget_helper) - : resource_dispatcher_host_(ResourceDispatcherHost::Get()), + : resource_dispatcher_host_( + content::GetContentClient()->browser()->GetResourceDispatcherHost()), plugin_service_(plugin_service), browser_context_(browser_context), request_context_(request_context), diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index 319e9b9..1765526 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -85,6 +85,9 @@ class RenderMessageFilter : public content::BrowserMessageFilter { bool OffTheRecord() const; int render_process_id() const { return render_process_id_; } + ResourceDispatcherHost* resource_dispatcher_host() { + return resource_dispatcher_host_; + } // Returns the correct net::URLRequestContext depending on what type of url is // given. diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index e969c06..1e4124e 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -454,8 +454,10 @@ void RenderProcessHostImpl::CreateMessageFilters() { &browser_context->GetResourceContext(); ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( - GetID(), content::PROCESS_TYPE_RENDERER, resource_context, - new RendererURLRequestContextSelector(browser_context, GetID())); + GetID(), content::PROCESS_TYPE_RENDERER, + resource_context, + new RendererURLRequestContextSelector(browser_context, GetID()), + content::GetContentClient()->browser()->GetResourceDispatcherHost()); channel_->AddFilter(resource_message_filter); channel_->AddFilter(new AudioInputRendererHost(resource_context)); @@ -501,6 +503,7 @@ void RenderProcessHostImpl::CreateMessageFilters() { channel_->AddFilter(socket_stream_dispatcher_host); channel_->AddFilter(new WorkerMessageFilter(GetID(), resource_context, + content::GetContentClient()->browser()->GetResourceDispatcherHost(), base::Bind(&RenderWidgetHelper::GetNextRoutingID, base::Unretained(widget_helper_.get())))); diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc index c44c7c2..748f589 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.cc +++ b/content/browser/renderer_host/resource_dispatcher_host.cc @@ -95,8 +95,6 @@ using webkit_blob::DeletableFileReference; namespace { -static ResourceDispatcherHost* g_resource_dispatcher_host; - // The interval for calls to ResourceDispatcherHost::UpdateLoadStates const int kUpdateLoadStatesIntervalMsec = 100; @@ -296,20 +294,9 @@ void OnSwapOutACKHelper(int render_process_id, int render_view_id) { } // namespace -ResourceDispatcherHost* ResourceDispatcherHost::Get() { - if (!g_resource_dispatcher_host) - new ResourceDispatcherHost(); - DCHECK(g_resource_dispatcher_host); - return g_resource_dispatcher_host; -} - -bool ResourceDispatcherHost::IsCreated() { - return !!g_resource_dispatcher_host; -} - -ResourceDispatcherHost::ResourceDispatcherHost() - : temporarily_delegate_set_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( +ResourceDispatcherHost::ResourceDispatcherHost( + const ResourceQueue::DelegateSet& resource_queue_delegates) + : ALLOW_THIS_IN_INITIALIZER_LIST( download_file_manager_(new DownloadFileManager(this, NULL))), ALLOW_THIS_IN_INITIALIZER_LIST( save_file_manager_(new SaveFileManager(this))), @@ -321,27 +308,14 @@ ResourceDispatcherHost::ResourceDispatcherHost() filter_(NULL), delegate_(NULL), allow_cross_origin_auth_prompt_(false) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - g_resource_dispatcher_host = this; - - ResourceQueue::DelegateSet resource_queue_delegates; - temporarily_delegate_set_ = &resource_queue_delegates; - content::GetContentClient()->browser()->ResourceDispatcherHostCreated(); resource_queue_.Initialize(resource_queue_delegates); - temporarily_delegate_set_ = NULL; ANNOTATE_BENIGN_RACE( &last_user_gesture_time_, "We don't care about the precise value, see http://crbug.com/92889"); - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); } ResourceDispatcherHost::~ResourceDispatcherHost() { - DCHECK(g_resource_dispatcher_host); - g_resource_dispatcher_host = NULL; AsyncResourceHandler::GlobalCleanup(); for (PendingRequestList::const_iterator i = pending_requests_.begin(); i != pending_requests_.end(); ++i) { @@ -351,6 +325,13 @@ ResourceDispatcherHost::~ResourceDispatcherHost() { DCHECK(transferred_navigations_.empty()); } +void ResourceDispatcherHost::Initialize() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&appcache::AppCacheInterceptor::EnsureRegistered)); +} + void ResourceDispatcherHost::Shutdown() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); BrowserThread::PostTask(BrowserThread::IO, @@ -359,11 +340,6 @@ void ResourceDispatcherHost::Shutdown() { base::Unretained(this))); } -void ResourceDispatcherHost::AddResourceQueueDelegate( - ResourceQueueDelegate* delegate) { - temporarily_delegate_set_->insert(delegate); -} - void ResourceDispatcherHost::SetRequestInfo( net::URLRequest* request, ResourceDispatcherHostRequestInfo* info) { diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h index 535a68b..94f7fb5 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.h +++ b/content/browser/renderer_host/resource_dispatcher_host.h @@ -59,29 +59,16 @@ class DeletableFileReference; class CONTENT_EXPORT ResourceDispatcherHost : public net::URLRequest::Delegate { public: - ResourceDispatcherHost(); + explicit ResourceDispatcherHost( + const ResourceQueue::DelegateSet& resource_queue_delegates); virtual ~ResourceDispatcherHost(); - // Returns the current ResourceDispatcherHost, creating it if necessary. The - // first time this is called must be on the UI thread, but after that it can - // be called from the IO thread as well. - static ResourceDispatcherHost* Get(); - - // Returns true if the ResourceDispatcherHost has been created (i.e. Get() has - // been called). - static bool IsCreated(); + void Initialize(); // Puts the resource dispatcher host in an inactive state (unable to begin // new requests). Cancels all pending requests. void Shutdown(); - // Destructs the current ResourceDispatcherHost. - void Destruct(); - - // Adds a delegate that can delay requests. This should be called early, i.e. - // in the ContentBrowserClient::ResourceDispatcherHostCreated callback. - void AddResourceQueueDelegate(ResourceQueueDelegate* delegate); - // Returns true if the message was a resource message that was processed. // If it was, message_was_ok will be false iff the message was corrupt. bool OnMessageReceived(const IPC::Message& message, @@ -475,9 +462,6 @@ class CONTENT_EXPORT ResourceDispatcherHost : public net::URLRequest::Delegate { // Handles the resource requests from the moment we want to start them. ResourceQueue resource_queue_; - // Used temporarily during construction. - ResourceQueue::DelegateSet* temporarily_delegate_set_; - // We own the download file writing thread and manager scoped_refptr<DownloadFileManager> download_file_manager_; diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc index 08f54d5..53cc63f 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -174,7 +174,8 @@ class ForwardingFilter : public ResourceMessageFilter { content::PROCESS_TYPE_RENDERER, content::MockResourceContext::GetInstance(), new MockURLRequestContextSelector( - content::MockResourceContext::GetInstance()->request_context())), + content::MockResourceContext::GetInstance()->request_context()), + NULL), dest_(dest) { OnChannelConnected(base::GetCurrentProcId()); } @@ -276,6 +277,7 @@ class ResourceDispatcherHostTest : public testing::Test, : ui_thread_(BrowserThread::UI, &message_loop_), io_thread_(BrowserThread::IO, &message_loop_), ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))), + host_(ResourceQueue::DelegateSet()), old_factory_(NULL), resource_type_(ResourceType::SUB_RESOURCE) { } diff --git a/content/browser/renderer_host/resource_message_filter.cc b/content/browser/renderer_host/resource_message_filter.cc index 7c8497f..771008c 100644 --- a/content/browser/renderer_host/resource_message_filter.cc +++ b/content/browser/renderer_host/resource_message_filter.cc @@ -14,11 +14,13 @@ ResourceMessageFilter::ResourceMessageFilter( int child_id, content::ProcessType process_type, const content::ResourceContext* resource_context, - URLRequestContextSelector* url_request_context_selector) + URLRequestContextSelector* url_request_context_selector, + ResourceDispatcherHost* resource_dispatcher_host) : child_id_(child_id), process_type_(process_type), resource_context_(resource_context), - url_request_context_selector_(url_request_context_selector) { + url_request_context_selector_(url_request_context_selector), + resource_dispatcher_host_(resource_dispatcher_host) { DCHECK(resource_context); DCHECK(url_request_context_selector); } @@ -31,12 +33,12 @@ void ResourceMessageFilter::OnChannelClosing() { // Unhook us from all pending network requests so they don't get sent to a // deleted object. - ResourceDispatcherHost::Get()->CancelRequestsForProcess(child_id_); + resource_dispatcher_host_->CancelRequestsForProcess(child_id_); } bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message, bool* message_was_ok) { - return ResourceDispatcherHost::Get()->OnMessageReceived( + return resource_dispatcher_host_->OnMessageReceived( message, this, message_was_ok); } diff --git a/content/browser/renderer_host/resource_message_filter.h b/content/browser/renderer_host/resource_message_filter.h index c9f6d0d..96ef977 100644 --- a/content/browser/renderer_host/resource_message_filter.h +++ b/content/browser/renderer_host/resource_message_filter.h @@ -11,6 +11,8 @@ #include "content/public/common/process_type.h" #include "webkit/glue/resource_type.h" +class ResourceDispatcherHost; + namespace content { class ResourceContext; } // namespace content @@ -40,11 +42,11 @@ class CONTENT_EXPORT ResourceMessageFilter DISALLOW_COPY_AND_ASSIGN(URLRequestContextSelector); }; - ResourceMessageFilter( - int child_id, - content::ProcessType process_type, - const content::ResourceContext* resource_context, - URLRequestContextSelector* url_request_context_selector); + ResourceMessageFilter(int child_id, + content::ProcessType process_type, + const content::ResourceContext* resource_context, + URLRequestContextSelector* url_request_context_selector, + ResourceDispatcherHost* resource_dispatcher_host); // content::BrowserMessageFilter implementation. virtual void OnChannelClosing() OVERRIDE; @@ -77,6 +79,9 @@ class CONTENT_EXPORT ResourceMessageFilter const scoped_ptr<URLRequestContextSelector> url_request_context_selector_; + // Owned by BrowserProcess, which is guaranteed to outlive us. + ResourceDispatcherHost* resource_dispatcher_host_; + DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceMessageFilter); }; diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc index 60e2c6d..c3e53b5 100644 --- a/content/browser/tab_contents/interstitial_page.cc +++ b/content/browser/tab_contents/interstitial_page.cc @@ -569,17 +569,21 @@ void InterstitialPage::TakeActionOnResourceDispatcher( // The tab might not have a render_view_host if it was closed (in which case, // we have taken care of the blocked requests when processing // NOTIFY_RENDER_WIDGET_HOST_DESTROYED. + // Also we need to test there is a ResourceDispatcherHost, as when unit-tests + // we don't have one. RenderViewHost* rvh = RenderViewHost::FromID(original_child_id_, original_rvh_id_); - if (!rvh) + if (!rvh || + !content::GetContentClient()->browser()->GetResourceDispatcherHost()) { return; + } BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind( &ResourceRequestHelper, - ResourceDispatcherHost::Get(), + content::GetContentClient()->browser()->GetResourceDispatcherHost(), original_child_id_, original_rvh_id_, action)); diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index ce3abd1..56946f2 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -2059,7 +2059,10 @@ void TabContents::OnUserGesture() { // Notify observers. FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); - ResourceDispatcherHost::Get()->OnUserGesture(this); + ResourceDispatcherHost* rdh = + content::GetContentClient()->browser()->GetResourceDispatcherHost(); + if (rdh) // NULL in unittests. + rdh->OnUserGesture(this); } void TabContents::OnIgnoredUIEvent() { diff --git a/content/browser/worker_host/worker_message_filter.cc b/content/browser/worker_host/worker_message_filter.cc index f543eaa..3dc750a 100644 --- a/content/browser/worker_host/worker_message_filter.cc +++ b/content/browser/worker_host/worker_message_filter.cc @@ -17,9 +17,11 @@ using content::WorkerServiceImpl; WorkerMessageFilter::WorkerMessageFilter( int render_process_id, const content::ResourceContext* resource_context, + ResourceDispatcherHost* resource_dispatcher_host, const NextRoutingIDCallback& callback) : render_process_id_(render_process_id), resource_context_(resource_context), + resource_dispatcher_host_(resource_dispatcher_host), next_routing_id_(callback) { DCHECK(resource_context); } diff --git a/content/browser/worker_host/worker_message_filter.h b/content/browser/worker_host/worker_message_filter.h index c2dac0f..39bb567 100644 --- a/content/browser/worker_host/worker_message_filter.h +++ b/content/browser/worker_host/worker_message_filter.h @@ -25,6 +25,7 @@ class WorkerMessageFilter : public content::BrowserMessageFilter { WorkerMessageFilter( int render_process_id, const content::ResourceContext* resource_context, + ResourceDispatcherHost* resource_dispatcher_host, const NextRoutingIDCallback& callback); // content::BrowserMessageFilter implementation. @@ -34,6 +35,9 @@ class WorkerMessageFilter : public content::BrowserMessageFilter { int GetNextRoutingID(); int render_process_id() const { return render_process_id_; } + ResourceDispatcherHost* resource_dispatcher_host() const { + return resource_dispatcher_host_; + } private: virtual ~WorkerMessageFilter(); @@ -51,6 +55,7 @@ class WorkerMessageFilter : public content::BrowserMessageFilter { int render_process_id_; const content::ResourceContext* const resource_context_; + ResourceDispatcherHost* resource_dispatcher_host_; // This is guaranteed to be valid until OnChannelClosing is closed, and it's // not used after. diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index be99858..4988172 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -85,9 +85,11 @@ void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { } WorkerProcessHost::WorkerProcessHost( - const content::ResourceContext* resource_context) + const content::ResourceContext* resource_context, + ResourceDispatcherHost* resource_dispatcher_host) : BrowserChildProcessHost(content::PROCESS_TYPE_WORKER), - resource_context_(resource_context) { + resource_context_(resource_context), + resource_dispatcher_host_(resource_dispatcher_host) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(resource_context); } @@ -237,11 +239,12 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( id(), content::PROCESS_TYPE_WORKER, resource_context_, - new URLRequestContextSelector(request_context)); + new URLRequestContextSelector(request_context), + resource_dispatcher_host_); child_process_host()->AddFilter(resource_message_filter); worker_message_filter_ = new WorkerMessageFilter( - render_process_id, resource_context_, + render_process_id, resource_context_, resource_dispatcher_host_, base::Bind(&WorkerServiceImpl::next_worker_route_id, base::Unretained(WorkerServiceImpl::GetInstance()))); child_process_host()->AddFilter(worker_message_filter_); diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h index 6ccc137..3ec544aa 100644 --- a/content/browser/worker_host/worker_process_host.h +++ b/content/browser/worker_host/worker_process_host.h @@ -16,6 +16,8 @@ #include "content/browser/worker_host/worker_document_set.h" #include "googleurl/src/gurl.h" +class ResourceDispatcherHost; + namespace content { class ResourceContext; class WorkerServiceImpl; @@ -107,7 +109,9 @@ class WorkerProcessHost : public BrowserChildProcessHost { const content::ResourceContext* const resource_context_; }; - explicit WorkerProcessHost(const content::ResourceContext* resource_context); + WorkerProcessHost( + const content::ResourceContext* resource_context, + ResourceDispatcherHost* resource_dispatcher_host); virtual ~WorkerProcessHost(); // Starts the process. Returns true iff it succeeded. @@ -186,6 +190,8 @@ class WorkerProcessHost : public BrowserChildProcessHost { // process. scoped_refptr<WorkerMessageFilter> worker_message_filter_; + ResourceDispatcherHost* const resource_dispatcher_host_; + DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); }; diff --git a/content/browser/worker_host/worker_service_impl.cc b/content/browser/worker_host/worker_service_impl.cc index 4818fc9d..3d5acb3 100644 --- a/content/browser/worker_host/worker_service_impl.cc +++ b/content/browser/worker_host/worker_service_impl.cc @@ -284,7 +284,9 @@ bool WorkerServiceImpl::CreateWorkerFromInstance( if (!worker) { WorkerMessageFilter* first_filter = instance.filters().begin()->first; - worker = new WorkerProcessHost(instance.resource_context()); + worker = new WorkerProcessHost( + instance.resource_context(), + first_filter->resource_dispatcher_host()); // TODO(atwilson): This won't work if the message is from a worker process. // We don't support that yet though (this message is only sent from // renderers) but when we do, we'll need to add code to pass in the current diff --git a/content/public/browser/browser_main_parts.h b/content/public/browser/browser_main_parts.h index 09cf20a..4bce3cf 100644 --- a/content/public/browser/browser_main_parts.h +++ b/content/public/browser/browser_main_parts.h @@ -72,6 +72,15 @@ class CONTENT_EXPORT BrowserMainParts { // been run), and the toolkit has been initialized. virtual void PreCreateThreads() = 0; + // Called once for each thread owned by the content framework just + // before and just after the thread object is created and started. + // This happens in the order of the threads' appearence in the + // BrowserThread::ID enumeration. Note that there will be no such + // call for BrowserThread::UI, since it is the main thread of the + // application. + virtual void PreStartThread(BrowserThread::ID identifier) = 0; + virtual void PostStartThread(BrowserThread::ID identifier) = 0; + // This is called just before the main message loop is run. The // various browser threads have all been created at this point virtual void PreMainMessageLoopRun() = 0; @@ -85,6 +94,14 @@ class CONTENT_EXPORT BrowserMainParts { // threads are stopped. virtual void PostMainMessageLoopRun() = 0; + // Called once for each thread owned by the content framework just + // before and just after it is torn down. This is in reverse order + // of the threads' appearance in the BrowserThread::ID enumeration. + // Note that you will not receive such a call for BrowserThread::UI, + // since it is the main thread of the application. + virtual void PreStopThread(BrowserThread::ID identifier) = 0; + virtual void PostStopThread(BrowserThread::ID identifier) = 0; + // Called as the very last part of shutdown, after threads have been // stopped and destroyed. virtual void PostDestroyThreads() = 0; diff --git a/content/public/browser/browser_shutdown.h b/content/public/browser/browser_shutdown.h index abefc26..72a4ce0 100644 --- a/content/public/browser/browser_shutdown.h +++ b/content/public/browser/browser_shutdown.h @@ -17,7 +17,8 @@ namespace content { // This causes the shutdown sequence embodied by // BrowserMainParts::PostMainMessageLoopRun through // BrowserMainParts::PostDestroyThreads to occur, i.e. we pretend the -// message loop finished, all threads are stopped in sequence and then +// message loop finished, all threads are stopped in sequence and +// PreStopThread/PostStopThread gets called, and at least, // PostDestroyThreads is called. // // As this violates the normal order of shutdown, likely leaving the diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 9a9fda1..87900d3 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -291,11 +291,8 @@ class ContentBrowserClient { virtual std::string GetWorkerProcessTitle( const GURL& url, const content::ResourceContext& context) = 0; - // Notifies the embedder that the ResourceDispatcherHost has been created. - // This is when it can optionally add a delegate or ResourceQueueDelegates. - virtual void ResourceDispatcherHostCreated() = 0; - // Getters for common objects. + virtual ResourceDispatcherHost* GetResourceDispatcherHost() = 0; virtual ui::Clipboard* GetClipboard() = 0; virtual MHTMLGenerationManager* GetMHTMLGenerationManager() = 0; virtual net::NetLog* GetNetLog() = 0; diff --git a/content/public/browser/download_manager.h b/content/public/browser/download_manager.h index 13e717a5..41de9b2 100644 --- a/content/public/browser/download_manager.h +++ b/content/public/browser/download_manager.h @@ -43,10 +43,8 @@ #include "net/base/net_errors.h" class DownloadFileManager; -class DownloadIdFactory; class DownloadManagerTest; class DownloadRequestHandle; -class DownloadStatusUpdater; class GURL; class TabContents; struct DownloadCreateInfo; @@ -63,11 +61,6 @@ class CONTENT_EXPORT DownloadManager public: virtual ~DownloadManager() {} - static DownloadManager* Create( - DownloadManagerDelegate* delegate, - DownloadIdFactory* id_factory, - DownloadStatusUpdater* status_updater); - // Shutdown the download manager. Must be called before destruction. virtual void Shutdown() = 0; diff --git a/content/shell/shell_browser_main.cc b/content/shell/shell_browser_main.cc index 311b6a0..24d7149 100644 --- a/content/shell/shell_browser_main.cc +++ b/content/shell/shell_browser_main.cc @@ -13,6 +13,7 @@ #include "content/browser/download/download_file_manager.h" #include "content/browser/download/save_file_manager.h" #include "content/browser/plugin_service_impl.h" +#include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/shell/shell.h" #include "content/shell/shell_browser_context.h" #include "content/shell/shell_content_browser_client.h" @@ -47,6 +48,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { Shell::PlatformInitialize(); net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); + PluginService::GetInstance()->Init(); Shell::CreateNewWindow(browser_context_.get(), GetStartupURL(), @@ -57,12 +59,32 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { void ShellBrowserMainParts::PostMainMessageLoopRun() { browser_context_.reset(); + + resource_dispatcher_host_->download_file_manager()->Shutdown(); + resource_dispatcher_host_->save_file_manager()->Shutdown(); + resource_dispatcher_host_->Shutdown(); +} + +void ShellBrowserMainParts::PreStopThread(BrowserThread::ID id) { + if (id == BrowserThread::WEBKIT_DEPRECATED) { + resource_dispatcher_host_.reset(); + } } bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { return false; } +ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() { + if (!resource_dispatcher_host_.get()) { + ResourceQueue::DelegateSet resource_queue_delegates; + resource_dispatcher_host_.reset( + new ResourceDispatcherHost(resource_queue_delegates)); + resource_dispatcher_host_->Initialize(); + } + return resource_dispatcher_host_.get(); +} + ui::Clipboard* ShellBrowserMainParts::GetClipboard() { if (!clipboard_.get()) clipboard_.reset(new ui::Clipboard()); diff --git a/content/shell/shell_browser_main.h b/content/shell/shell_browser_main.h index 2451761..e842e21 100644 --- a/content/shell/shell_browser_main.h +++ b/content/shell/shell_browser_main.h @@ -10,6 +10,8 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" +class ResourceDispatcherHost; + namespace base { class Thread; } @@ -34,16 +36,22 @@ class ShellBrowserMainParts : public BrowserMainParts { virtual void ToolkitInitialized() OVERRIDE {} virtual void PostMainMessageLoopStart() OVERRIDE {} virtual void PreCreateThreads() OVERRIDE {} + virtual void PreStartThread(BrowserThread::ID id) OVERRIDE {} + virtual void PostStartThread(BrowserThread::ID id) OVERRIDE {} virtual void PreMainMessageLoopRun() OVERRIDE; virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; + virtual void PreStopThread(BrowserThread::ID id) OVERRIDE; + virtual void PostStopThread(BrowserThread::ID) OVERRIDE {} virtual void PostDestroyThreads() OVERRIDE {} + ResourceDispatcherHost* GetResourceDispatcherHost(); ui::Clipboard* GetClipboard(); private: scoped_ptr<ShellBrowserContext> browser_context_; + scoped_ptr<ResourceDispatcherHost> resource_dispatcher_host_; scoped_ptr<ui::Clipboard> clipboard_; DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts); diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 904e9ff..73e8a5c 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -245,7 +245,8 @@ std::string ShellContentBrowserClient::GetWorkerProcessTitle( return std::string(); } -void ShellContentBrowserClient::ResourceDispatcherHostCreated() { +ResourceDispatcherHost* ShellContentBrowserClient::GetResourceDispatcherHost() { + return shell_browser_main_parts_->GetResourceDispatcherHost(); } ui::Clipboard* ShellContentBrowserClient::GetClipboard() { diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index a81c445..44ee7c7 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -138,7 +138,7 @@ class ShellContentBrowserClient : public ContentBrowserClient int render_process_id) OVERRIDE; virtual std::string GetWorkerProcessTitle( const GURL& url, const content::ResourceContext& context) OVERRIDE; - virtual void ResourceDispatcherHostCreated() OVERRIDE; + virtual ResourceDispatcherHost* GetResourceDispatcherHost() OVERRIDE; virtual ui::Clipboard* GetClipboard() OVERRIDE; virtual MHTMLGenerationManager* GetMHTMLGenerationManager() OVERRIDE; virtual net::NetLog* GetNetLog() OVERRIDE; |