diff options
20 files changed, 172 insertions, 114 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index aa8a766..fa6a8ca 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -32,6 +32,7 @@ include_rules = [ "-content/browser/notification_service_impl.h", "-content/browser/tab_contents/navigation_entry_impl.h", "-content/browser/plugin_service_impl.h", + "-content/browser/worker_service_impl.h", "-content/common", # TODO(jam): remove all the exceptions. BUG=98716 diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc index fef4634..1279f02 100644 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ b/chrome/browser/debugger/devtools_sanity_unittest.cc @@ -26,20 +26,22 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/browser/worker_host/worker_service.h" -#include "content/browser/worker_host/worker_service_observer.h" #include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" +#include "content/public/browser/worker_service.h" +#include "content/public/browser/worker_service_observer.h" #include "net/test/test_server.h" using content::BrowserThread; using content::DevToolsManager; using content::DevToolsAgentHost; using content::DevToolsAgentHostRegistry; +using content::WorkerService; +using content::WorkerServiceObserver; namespace { diff --git a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc index efa7ae3..28ca236 100644 --- a/chrome/browser/task_manager/task_manager_worker_resource_provider.cc +++ b/chrome/browser/task_manager/task_manager_worker_resource_provider.cc @@ -13,13 +13,12 @@ #include "chrome/browser/profiles/profile_manager.h" #include "content/browser/browser_child_process_host.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/browser/worker_host/worker_service.h" -#include "content/browser/worker_host/worker_service_observer.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/devtools_agent_host_registry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" +#include "content/public/browser/worker_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources_standard.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -29,6 +28,7 @@ using content::BrowserThread; using content::DevToolsAgentHost; using content::DevToolsAgentHostRegistry; +using content::WorkerService; // Objects of this class are created on the IO thread and then passed to the UI // thread where they are passed to the task manager. All methods must be called diff --git a/chrome/browser/task_manager/task_manager_worker_resource_provider.h b/chrome/browser/task_manager/task_manager_worker_resource_provider.h index 0e7d5f4..b6e8b5b 100644 --- a/chrome/browser/task_manager/task_manager_worker_resource_provider.h +++ b/chrome/browser/task_manager/task_manager_worker_resource_provider.h @@ -11,15 +11,15 @@ #include "base/basictypes.h" #include "chrome/browser/task_manager/task_manager.h" -#include "content/browser/worker_host/worker_service_observer.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "content/public/browser/worker_service_observer.h" class TaskManagerSharedWorkerResource; class TaskManagerWorkerResourceProvider : public TaskManager::ResourceProvider, - private WorkerServiceObserver, + private content::WorkerServiceObserver, private content::NotificationObserver { public: explicit TaskManagerWorkerResourceProvider(TaskManager* task_manager); @@ -39,7 +39,7 @@ class TaskManagerWorkerResourceProvider virtual void StartUpdating() OVERRIDE; virtual void StopUpdating() OVERRIDE; - // WorkerServiceObserver implementation. + // content::WorkerServiceObserver implementation. virtual void WorkerCreated( WorkerProcessHost* process, const WorkerProcessHost::WorkerInstance& instance) OVERRIDE; diff --git a/chrome/browser/ui/webui/workers_ui.cc b/chrome/browser/ui/webui/workers_ui.cc index a0b0a3c..9a702e3 100644 --- a/chrome/browser/ui/webui/workers_ui.cc +++ b/chrome/browser/ui/webui/workers_ui.cc @@ -19,9 +19,9 @@ #include "content/public/browser/devtools_agent_host_registry.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/browser/worker_host/worker_service.h" -#include "content/browser/worker_host/worker_service_observer.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/worker_service.h" +#include "content/public/browser/worker_service_observer.h" #include "content/public/common/process_type.h" #include "grit/generated_resources.h" #include "grit/workers_resources.h" @@ -30,6 +30,8 @@ using content::BrowserThread; using content::DevToolsAgentHost; using content::DevToolsAgentHostRegistry; +using content::WorkerService; +using content::WorkerServiceObserver; static const char kWorkersDataFile[] = "workers_data.json"; diff --git a/content/browser/debugger/worker_devtools_manager.cc b/content/browser/debugger/worker_devtools_manager.cc index 2029648..0411fcc 100644 --- a/content/browser/debugger/worker_devtools_manager.cc +++ b/content/browser/debugger/worker_devtools_manager.cc @@ -12,7 +12,7 @@ #include "content/browser/debugger/devtools_manager_impl.h" #include "content/browser/debugger/worker_devtools_message_filter.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include "content/common/devtools_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/devtools_agent_host_registry.h" @@ -277,7 +277,7 @@ DevToolsAgentHost* WorkerDevToolsManager::GetDevToolsAgentHostForWorker( } WorkerDevToolsManager::WorkerDevToolsManager() { - WorkerService::GetInstance()->AddObserver(this); + WorkerServiceImpl::GetInstance()->AddObserver(this); } WorkerDevToolsManager::~WorkerDevToolsManager() { diff --git a/content/browser/debugger/worker_devtools_manager.h b/content/browser/debugger/worker_devtools_manager.h index 9cc55e5..8ee9c1c 100644 --- a/content/browser/debugger/worker_devtools_manager.h +++ b/content/browser/debugger/worker_devtools_manager.h @@ -13,7 +13,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "content/common/content_export.h" -#include "content/browser/worker_host/worker_service_observer.h" +#include "content/public/browser/worker_service_observer.h" namespace IPC { class Message; @@ -53,7 +53,7 @@ class WorkerDevToolsManager : private WorkerServiceObserver { WorkerDevToolsManager(); virtual ~WorkerDevToolsManager(); - // WorkerServiceOberver implementation. + // WorkerServiceObserver implementation. virtual void WorkerCreated( WorkerProcessHost* process, const WorkerProcessHost::WorkerInstance& instance) OVERRIDE; diff --git a/content/browser/debugger/worker_devtools_message_filter.cc b/content/browser/debugger/worker_devtools_message_filter.cc index 6cc0bc0..5a1fba5 100644 --- a/content/browser/debugger/worker_devtools_message_filter.cc +++ b/content/browser/debugger/worker_devtools_message_filter.cc @@ -5,7 +5,6 @@ #include "content/browser/debugger/worker_devtools_message_filter.h" #include "content/browser/debugger/worker_devtools_manager.h" -#include "content/browser/worker_host/worker_service.h" #include "content/common/devtools_messages.h" #include "content/common/worker_messages.h" diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc index 120f09e..e09aa3e 100644 --- a/content/browser/renderer_host/resource_dispatcher_host.cc +++ b/content/browser/renderer_host/resource_dispatcher_host.cc @@ -47,7 +47,7 @@ #include "content/browser/resource_context.h" #include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/ssl/ssl_manager.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include "content/common/resource_messages.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" @@ -88,6 +88,7 @@ using content::BrowserThread; using content::GlobalRequestID; using content::ResourceResponse; using content::WebContents; +using content::WorkerServiceImpl; using webkit_blob::DeletableFileReference; // ---------------------------------------------------------------------------- @@ -1909,7 +1910,7 @@ bool ResourceDispatcherHost::RenderViewForRequest( if (info->process_type() == content::PROCESS_TYPE_WORKER) { // Need to display some related UI for this network request - pick an // arbitrary parent to do so. - if (!WorkerService::GetInstance()->GetRendererForWorker( + if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker( info->child_id(), render_process_host_id, render_view_host_id)) { *render_process_host_id = -1; *render_view_host_id = -1; diff --git a/content/browser/renderer_host/resource_request_details.cc b/content/browser/renderer_host/resource_request_details.cc index 2569c17..414f761 100644 --- a/content/browser/renderer_host/resource_request_details.cc +++ b/content/browser/renderer_host/resource_request_details.cc @@ -6,7 +6,9 @@ #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" + +using content::WorkerServiceImpl; ResourceRequestDetails::ResourceRequestDetails(const net::URLRequest* request, int cert_id) @@ -32,7 +34,7 @@ ResourceRequestDetails::ResourceRequestDetails(const net::URLRequest* request, // the first one (works for dedicated workers and shared workers with // a single process). int temp; - if (!WorkerService::GetInstance()->GetRendererForWorker( + if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker( info->child_id(), &origin_child_id_, &temp)) { origin_child_id_ = info->child_id(); } diff --git a/content/browser/worker_host/worker_message_filter.cc b/content/browser/worker_host/worker_message_filter.cc index e5f8314..3dc750a 100644 --- a/content/browser/worker_host/worker_message_filter.cc +++ b/content/browser/worker_host/worker_message_filter.cc @@ -6,12 +6,13 @@ #include "content/browser/resource_context.h" #include "content/browser/worker_host/message_port_service.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include "content/common/view_messages.h" #include "content/common/worker_messages.h" using content::BrowserMessageFilter; using content::BrowserThread; +using content::WorkerServiceImpl; WorkerMessageFilter::WorkerMessageFilter( int render_process_id, @@ -33,7 +34,7 @@ void WorkerMessageFilter::OnChannelClosing() { BrowserMessageFilter::OnChannelClosing(); MessagePortService::GetInstance()->OnWorkerMessageFilterClosing(this); - WorkerService::GetInstance()->OnWorkerMessageFilterClosing(this); + WorkerServiceImpl::GetInstance()->OnWorkerMessageFilterClosing(this); } bool WorkerMessageFilter::OnMessageReceived(const IPC::Message& message, @@ -81,7 +82,7 @@ void WorkerMessageFilter::OnCreateWorker( int* route_id) { *route_id = params.route_id != MSG_ROUTING_NONE ? params.route_id : next_routing_id_.Run(); - WorkerService::GetInstance()->CreateWorker( + WorkerServiceImpl::GetInstance()->CreateWorker( params, *route_id, this, *resource_context_); } @@ -92,16 +93,16 @@ void WorkerMessageFilter::OnLookupSharedWorker( bool* url_error) { *route_id = next_routing_id_.Run(); - WorkerService::GetInstance()->LookupSharedWorker( + WorkerServiceImpl::GetInstance()->LookupSharedWorker( params, *route_id, this, resource_context_, exists, url_error); } void WorkerMessageFilter::OnForwardToWorker(const IPC::Message& message) { - WorkerService::GetInstance()->ForwardToWorker(message, this); + WorkerServiceImpl::GetInstance()->ForwardToWorker(message, this); } void WorkerMessageFilter::OnDocumentDetached(unsigned long long document_id) { - WorkerService::GetInstance()->DocumentDetached(document_id, this); + WorkerServiceImpl::GetInstance()->DocumentDetached(document_id, this); } void WorkerMessageFilter::OnCreateMessagePort(int *route_id, diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 494fb02..c8f1b9d 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -29,7 +29,7 @@ #include "content/browser/resource_context.h" #include "content/browser/worker_host/message_port_service.h" #include "content/browser/worker_host/worker_message_filter.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include "content/common/child_process_host_impl.h" #include "content/common/debug_flags.h" #include "content/common/view_messages.h" @@ -51,6 +51,7 @@ using content::BrowserThread; using content::ChildProcessHost; using content::UserMetricsAction; +using content::WorkerServiceImpl; namespace { @@ -106,8 +107,8 @@ WorkerProcessHost::~WorkerProcessHost() { base::Bind(&WorkerCrashCallback, parent_iter->render_process_id(), parent_iter->render_view_id())); } - WorkerService::GetInstance()->NotifyWorkerDestroyed(this, - i->worker_route_id()); + WorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed( + this, i->worker_route_id()); } ChildProcessSecurityPolicy::GetInstance()->Remove(id()); @@ -245,8 +246,8 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { worker_message_filter_ = new WorkerMessageFilter( render_process_id, resource_context_, resource_dispatcher_host_, - base::Bind(&WorkerService::next_worker_route_id, - base::Unretained(WorkerService::GetInstance()))); + base::Bind(&WorkerServiceImpl::next_worker_route_id, + base::Unretained(WorkerServiceImpl::GetInstance()))); child_process_host()->AddFilter(worker_message_filter_); child_process_host()->AddFilter(new AppCacheDispatcherHost( resource_context_->appcache_service(), id())); @@ -329,8 +330,8 @@ bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { return true; if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { - WorkerService::GetInstance()->NotifyWorkerDestroyed(this, - message.routing_id()); + WorkerServiceImpl::GetInstance()->NotifyWorkerDestroyed( + this, message.routing_id()); } for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { @@ -432,8 +433,10 @@ void WorkerProcessHost::RelayMessage( IPC::Message* new_message = new IPC::Message(message); new_message->set_routing_id(route_id); filter->Send(new_message); - if (message.type() == WorkerMsg_StartWorkerContext::ID) - WorkerService::GetInstance()->NotifyWorkerContextStarted(this, route_id); + if (message.type() == WorkerMsg_StartWorkerContext::ID) { + WorkerServiceImpl::GetInstance()->NotifyWorkerContextStarted( + this, route_id); + } return; } } diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h index e82e3d2..3ec544aa 100644 --- a/content/browser/worker_host/worker_process_host.h +++ b/content/browser/worker_host/worker_process_host.h @@ -20,6 +20,7 @@ class ResourceDispatcherHost; namespace content { class ResourceContext; +class WorkerServiceImpl; } // namespace content // The WorkerProcessHost is the interface that represents the browser side of @@ -143,7 +144,7 @@ class WorkerProcessHost : public BrowserChildProcessHost { } protected: - friend class WorkerService; + friend class content::WorkerServiceImpl; Instances& mutable_instances() { return instances_; } diff --git a/content/browser/worker_host/worker_service.cc b/content/browser/worker_host/worker_service_impl.cc index 27b0f2b..3d5acb3 100644 --- a/content/browser/worker_host/worker_service.cc +++ b/content/browser/worker_host/worker_service_impl.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include <string> @@ -13,33 +13,38 @@ #include "content/browser/resource_context.h" #include "content/browser/worker_host/worker_message_filter.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/browser/worker_host/worker_service_observer.h" #include "content/common/view_messages.h" #include "content/common/worker_messages.h" +#include "content/public/browser/worker_service_observer.h" #include "content/public/common/content_switches.h" #include "content/public/common/process_type.h" #include "net/base/registry_controlled_domain.h" -using content::BrowserThread; +namespace content { -const int WorkerService::kMaxWorkerProcessesWhenSharing = 10; -const int WorkerService::kMaxWorkersWhenSeparate = 64; -const int WorkerService::kMaxWorkersPerTabWhenSeparate = 16; +const int WorkerServiceImpl::kMaxWorkerProcessesWhenSharing = 10; +const int WorkerServiceImpl::kMaxWorkersWhenSeparate = 64; +const int WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate = 16; WorkerService* WorkerService::GetInstance() { + return WorkerServiceImpl::GetInstance(); +} + +WorkerServiceImpl* WorkerServiceImpl::GetInstance() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return Singleton<WorkerService>::get(); + return Singleton<WorkerServiceImpl>::get(); } -WorkerService::WorkerService() : next_worker_route_id_(0) { +WorkerServiceImpl::WorkerServiceImpl() : next_worker_route_id_(0) { } -WorkerService::~WorkerService() { +WorkerServiceImpl::~WorkerServiceImpl() { // The observers in observers_ can't be used here because they might be // gone already. } -void WorkerService::OnWorkerMessageFilterClosing(WorkerMessageFilter* filter) { +void WorkerServiceImpl::OnWorkerMessageFilterClosing( + WorkerMessageFilter* filter) { for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); @@ -76,7 +81,7 @@ void WorkerService::OnWorkerMessageFilterClosing(WorkerMessageFilter* filter) { TryStartingQueuedWorker(); } -void WorkerService::CreateWorker( +void WorkerServiceImpl::CreateWorker( const ViewHostMsg_CreateWorker_Params& params, int route_id, WorkerMessageFilter* filter, @@ -100,7 +105,7 @@ void WorkerService::CreateWorker( CreateWorkerFromInstance(instance); } -void WorkerService::LookupSharedWorker( +void WorkerServiceImpl::LookupSharedWorker( const ViewHostMsg_CreateWorker_Params& params, int route_id, WorkerMessageFilter* filter, @@ -142,15 +147,15 @@ void WorkerService::LookupSharedWorker( } } -void WorkerService::CancelCreateDedicatedWorker( +void WorkerServiceImpl::CancelCreateDedicatedWorker( int route_id, WorkerMessageFilter* filter) { NOTREACHED(); } -void WorkerService::ForwardToWorker(const IPC::Message& message, - WorkerMessageFilter* filter) { +void WorkerServiceImpl::ForwardToWorker(const IPC::Message& message, + WorkerMessageFilter* filter) { for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); @@ -161,8 +166,8 @@ void WorkerService::ForwardToWorker(const IPC::Message& message, // TODO(jabdelmalek): tell filter that callee is gone } -void WorkerService::DocumentDetached(unsigned long long document_id, - WorkerMessageFilter* filter) { +void WorkerServiceImpl::DocumentDetached(unsigned long long document_id, + WorkerMessageFilter* filter) { // Any associated shared workers can be shut down. for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { @@ -195,7 +200,7 @@ void WorkerService::DocumentDetached(unsigned long long document_id, } } -bool WorkerService::CreateWorkerFromInstance( +bool WorkerServiceImpl::CreateWorkerFromInstance( WorkerProcessHost::WorkerInstance instance) { // TODO(michaeln): We need to ensure that a process is working // on behalf of a single browser context. The process sharing logic below @@ -302,7 +307,7 @@ bool WorkerService::CreateWorkerFromInstance( return true; } -WorkerProcessHost* WorkerService::GetProcessForDomain(const GURL& url) { +WorkerProcessHost* WorkerServiceImpl::GetProcessForDomain(const GURL& url) { int num_processes = 0; std::string domain = net::RegistryControlledDomainService::GetDomainAndRegistry(url); @@ -326,7 +331,7 @@ WorkerProcessHost* WorkerService::GetProcessForDomain(const GURL& url) { return NULL; } -WorkerProcessHost* WorkerService::GetProcessToFillUpCores() { +WorkerProcessHost* WorkerServiceImpl::GetProcessToFillUpCores() { int num_processes = 0; BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); for (; !iter.Done(); ++iter) @@ -338,7 +343,7 @@ WorkerProcessHost* WorkerService::GetProcessToFillUpCores() { return NULL; } -WorkerProcessHost* WorkerService::GetLeastLoadedWorker() { +WorkerProcessHost* WorkerServiceImpl::GetLeastLoadedWorker() { WorkerProcessHost* smallest = NULL; for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { @@ -350,7 +355,7 @@ WorkerProcessHost* WorkerService::GetLeastLoadedWorker() { return smallest; } -bool WorkerService::CanCreateWorkerProcess( +bool WorkerServiceImpl::CanCreateWorkerProcess( const WorkerProcessHost::WorkerInstance& instance) { // Worker can be fired off if *any* parent has room. const WorkerDocumentSet::DocumentInfoSet& parents = @@ -375,9 +380,10 @@ bool WorkerService::CanCreateWorkerProcess( return false; } -bool WorkerService::TabCanCreateWorkerProcess(int render_process_id, - int render_view_id, - bool* hit_total_worker_limit) { +bool WorkerServiceImpl::TabCanCreateWorkerProcess( + int render_process_id, + int render_view_id, + bool* hit_total_worker_limit) { int total_workers = 0; int workers_per_tab = 0; *hit_total_worker_limit = false; @@ -403,7 +409,7 @@ bool WorkerService::TabCanCreateWorkerProcess(int render_process_id, return true; } -void WorkerService::TryStartingQueuedWorker() { +void WorkerServiceImpl::TryStartingQueuedWorker() { if (queued_workers_.empty()) return; @@ -426,9 +432,9 @@ void WorkerService::TryStartingQueuedWorker() { } } -bool WorkerService::GetRendererForWorker(int worker_process_id, - int* render_process_id, - int* render_view_id) const { +bool WorkerServiceImpl::GetRendererForWorker(int worker_process_id, + int* render_process_id, + int* render_view_id) const { for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { if (iter->id() != worker_process_id) @@ -450,7 +456,7 @@ bool WorkerService::GetRendererForWorker(int worker_process_id, return false; } -const WorkerProcessHost::WorkerInstance* WorkerService::FindWorkerInstance( +const WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindWorkerInstance( int worker_process_id) { for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); !iter.Done(); ++iter) { @@ -465,31 +471,30 @@ const WorkerProcessHost::WorkerInstance* WorkerService::FindWorkerInstance( return NULL; } -void WorkerService::AddObserver(WorkerServiceObserver* observer) { +void WorkerServiceImpl::AddObserver(WorkerServiceObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); observers_.AddObserver(observer); } -void WorkerService::RemoveObserver(WorkerServiceObserver* observer) { +void WorkerServiceImpl::RemoveObserver(WorkerServiceObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); observers_.RemoveObserver(observer); } -void WorkerService::NotifyWorkerDestroyed( +void WorkerServiceImpl::NotifyWorkerDestroyed( WorkerProcessHost* process, int worker_route_id) { FOR_EACH_OBSERVER(WorkerServiceObserver, observers_, WorkerDestroyed(process, worker_route_id)); } -void WorkerService::NotifyWorkerContextStarted(WorkerProcessHost* process, - int worker_route_id) { +void WorkerServiceImpl::NotifyWorkerContextStarted(WorkerProcessHost* process, + int worker_route_id) { FOR_EACH_OBSERVER(WorkerServiceObserver, observers_, WorkerContextStarted(process, worker_route_id)); } -WorkerProcessHost::WorkerInstance* -WorkerService::FindSharedWorkerInstance( +WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindSharedWorkerInstance( const GURL& url, const string16& name, const content::ResourceContext* resource_context) { @@ -507,8 +512,7 @@ WorkerService::FindSharedWorkerInstance( return NULL; } -WorkerProcessHost::WorkerInstance* -WorkerService::FindPendingInstance( +WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindPendingInstance( const GURL& url, const string16& name, const content::ResourceContext* resource_context) { @@ -525,7 +529,7 @@ WorkerService::FindPendingInstance( } -void WorkerService::RemovePendingInstances( +void WorkerServiceImpl::RemovePendingInstances( const GURL& url, const string16& name, const content::ResourceContext* resource_context) { @@ -541,8 +545,7 @@ void WorkerService::RemovePendingInstances( } } -WorkerProcessHost::WorkerInstance* -WorkerService::CreatePendingInstance( +WorkerProcessHost::WorkerInstance* WorkerServiceImpl::CreatePendingInstance( const GURL& url, const string16& name, const content::ResourceContext* resource_context) { @@ -557,3 +560,5 @@ WorkerService::CreatePendingInstance( pending_shared_workers_.push_back(pending); return &pending_shared_workers_.back(); } + +} // namespace content diff --git a/content/browser/worker_host/worker_service.h b/content/browser/worker_host/worker_service_impl.h index f520600..2ec243a 100644 --- a/content/browser/worker_host/worker_service.h +++ b/content/browser/worker_host/worker_service_impl.h @@ -7,36 +7,40 @@ #pragma once #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/memory/singleton.h" #include "base/observer_list.h" #include "base/threading/non_thread_safe.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/common/content_export.h" #include "content/public/browser/notification_registrar.h" -#include "googleurl/src/gurl.h" +#include "content/public/browser/worker_service.h" +class GURL; struct ViewHostMsg_CreateWorker_Params; -class WorkerServiceObserver; namespace content { class ResourceContext; -} // namespace content +class WorkerServiceObserver; -// A singleton for managing HTML5 web workers. -class CONTENT_EXPORT WorkerService { +class CONTENT_EXPORT WorkerServiceImpl + : public NON_EXPORTED_BASE(WorkerService) { public: - // Returns the WorkerService singleton. - static WorkerService* GetInstance(); + // Returns the WorkerServiceImpl singleton. + static WorkerServiceImpl* GetInstance(); + + // WorkerService implementation: + virtual void AddObserver(WorkerServiceObserver* observer) OVERRIDE; + virtual void RemoveObserver(WorkerServiceObserver* observer) OVERRIDE; // These methods correspond to worker related IPCs. void CreateWorker(const ViewHostMsg_CreateWorker_Params& params, int route_id, WorkerMessageFilter* filter, - const content::ResourceContext& resource_context); + const ResourceContext& resource_context); void LookupSharedWorker(const ViewHostMsg_CreateWorker_Params& params, int route_id, WorkerMessageFilter* filter, - const content::ResourceContext* resource_context, + const ResourceContext* resource_context, bool* exists, bool* url_error); void CancelCreateDedicatedWorker(int route_id, WorkerMessageFilter* filter); @@ -60,9 +64,6 @@ class CONTENT_EXPORT WorkerService { const WorkerProcessHost::WorkerInstance* FindWorkerInstance( int worker_process_id); - void AddObserver(WorkerServiceObserver* observer); - void RemoveObserver(WorkerServiceObserver* observer); - void NotifyWorkerDestroyed( WorkerProcessHost* process, int worker_route_id); @@ -78,10 +79,10 @@ class CONTENT_EXPORT WorkerService { static const int kMaxWorkersPerTabWhenSeparate; private: - friend struct DefaultSingletonTraits<WorkerService>; + friend struct DefaultSingletonTraits<WorkerServiceImpl>; - WorkerService(); - ~WorkerService(); + WorkerServiceImpl(); + virtual ~WorkerServiceImpl(); // Given a WorkerInstance, create an associated worker process. bool CreateWorkerFromInstance(WorkerProcessHost::WorkerInstance instance); @@ -116,22 +117,22 @@ class CONTENT_EXPORT WorkerService { WorkerProcessHost::WorkerInstance* CreatePendingInstance( const GURL& url, const string16& name, - const content::ResourceContext* resource_context); + const ResourceContext* resource_context); WorkerProcessHost::WorkerInstance* FindPendingInstance( const GURL& url, const string16& name, - const content::ResourceContext* resource_context); + const ResourceContext* resource_context); void RemovePendingInstances( const GURL& url, const string16& name, - const content::ResourceContext* resource_context); + const ResourceContext* resource_context); WorkerProcessHost::WorkerInstance* FindSharedWorkerInstance( const GURL& url, const string16& name, - const content::ResourceContext* resource_context); + const ResourceContext* resource_context); - content::NotificationRegistrar registrar_; + NotificationRegistrar registrar_; int next_worker_route_id_; WorkerProcessHost::Instances queued_workers_; @@ -143,7 +144,9 @@ class CONTENT_EXPORT WorkerService { ObserverList<WorkerServiceObserver> observers_; - DISALLOW_COPY_AND_ASSIGN(WorkerService); + DISALLOW_COPY_AND_ASSIGN(WorkerServiceImpl); }; +} // namespace content + #endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 08a7419..b1a5ed8 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -85,6 +85,8 @@ 'public/browser/web_contents_observer.cc', 'public/browser/web_contents_observer.h', 'public/browser/web_intents_dispatcher.h', + 'public/browser/worker_service.h', + 'public/browser/worker_service_observer.h', 'browser/accessibility/browser_accessibility.cc', 'browser/accessibility/browser_accessibility.h', 'browser/accessibility/browser_accessibility_cocoa.h', @@ -640,9 +642,8 @@ 'browser/worker_host/worker_message_filter.h', 'browser/worker_host/worker_process_host.cc', 'browser/worker_host/worker_process_host.h', - 'browser/worker_host/worker_service.cc', - 'browser/worker_host/worker_service.h', - 'browser/worker_host/worker_service_observer.h', + 'browser/worker_host/worker_service_impl.cc', + 'browser/worker_host/worker_service_impl.h', 'browser/zygote_host_linux.cc', 'browser/zygote_host_linux.h', 'browser/zygote_main_linux.cc', diff --git a/content/public/browser/DEPS b/content/public/browser/DEPS index 8302958..753ae54 100644 --- a/content/public/browser/DEPS +++ b/content/public/browser/DEPS @@ -11,4 +11,5 @@ include_rules = [ "+content/browser/tab_contents/page_navigator.h", "+content/browser/tab_contents/tab_contents.h", "+content/browser/webui/web_ui.h", + "+content/browser/worker_host/worker_process_host.h", ] diff --git a/content/public/browser/worker_service.h b/content/public/browser/worker_service.h new file mode 100644 index 0000000..c672753 --- /dev/null +++ b/content/public/browser/worker_service.h @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_WORKER_SERVICE_H_ +#define CONTENT_PUBLIC_BROWSER_WORKER_SERVICE_H_ +#pragma once + +#include "content/common/content_export.h" + +namespace content { + +class WorkerServiceObserver; + +// A singleton for managing HTML5 shared web workers. These are run in a +// separate process, since multiple renderer processes can be talking to a +// single shared worker. +class WorkerService { + public: + virtual ~WorkerService() {} + + // Returns the WorkerService singleton. + CONTENT_EXPORT static WorkerService* GetInstance(); + + virtual void AddObserver(WorkerServiceObserver* observer) = 0; + virtual void RemoveObserver(WorkerServiceObserver* observer) = 0; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_PLUGIN_SERVICE_H_ diff --git a/content/browser/worker_host/worker_service_observer.h b/content/public/browser/worker_service_observer.h index ae52edd..f4b1255 100644 --- a/content/browser/worker_host/worker_service_observer.h +++ b/content/public/browser/worker_service_observer.h @@ -2,14 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_OBSERVER_H_ -#define CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_OBSERVER_H_ +#ifndef CONTENT_PUBLIC_BROWSER_WORKER_SERVICE_OBSERVER_H_ +#define CONTENT_PUBLIC_BROWSER_WORKER_SERVICE_OBSERVER_H_ #pragma once #include "content/browser/worker_host/worker_process_host.h" +namespace content { + class WorkerServiceObserver { public: + virtual ~WorkerServiceObserver() {} + virtual void WorkerCreated( WorkerProcessHost* process, const WorkerProcessHost::WorkerInstance& instance) = 0; @@ -19,9 +23,8 @@ class WorkerServiceObserver { virtual void WorkerContextStarted( WorkerProcessHost* process, int worker_route_id) = 0; - - protected: - virtual ~WorkerServiceObserver() {} }; -#endif // CONTENT_BROWSER_WORKER_HOST_WORKER_SERVICE_OBSERVER_H_ +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_WORKER_SERVICE_OBSERVER_H_ diff --git a/content/worker/test/worker_uitest.cc b/content/worker/test/worker_uitest.cc index 698062c..ed22c52 100644 --- a/content/worker/test/worker_uitest.cc +++ b/content/worker/test/worker_uitest.cc @@ -13,10 +13,12 @@ #include "chrome/test/base/layout_test_http_server.h" #include "chrome/test/base/ui_test_utils.h" #include "chrome/test/ui/ui_layout_test.h" -#include "content/browser/worker_host/worker_service.h" +#include "content/browser/worker_host/worker_service_impl.h" #include "content/public/common/url_constants.h" #include "net/test/test_server.h" +using content::WorkerServiceImpl; + namespace { const char kTestCompleteCookie[] = "status"; @@ -586,7 +588,7 @@ TEST_F(WorkerTest, FLAKY_MessagePorts) { #define MAYBE_LimitPerPage FLAKY_LimitPerPage #endif TEST_F(WorkerTest, MAYBE_LimitPerPage) { - int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; + int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), FilePath(kManyWorkersFile)); url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab + 1)); @@ -601,8 +603,8 @@ TEST_F(WorkerTest, MAYBE_LimitPerPage) { // Possibly causing ui_tests to hang on Mac: http://crbug.com/88958 // Times out consistently on all platforms. TEST_F(WorkerTest, DISABLED_LimitTotal) { - int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; - int total_workers = WorkerService::kMaxWorkersWhenSeparate; + int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; + int total_workers = WorkerServiceImpl::kMaxWorkersWhenSeparate; int tab_count = (total_workers / max_workers_per_tab) + 1; GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), @@ -647,7 +649,7 @@ TEST_F(WorkerTest, FLAKY_WorkerClose) { TEST_F(WorkerTest, FLAKY_QueuedSharedWorkerShutdown) { // Tests to make sure that queued shared workers are started up when // shared workers shut down. - int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; + int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), FilePath(kQuerySharedWorkerShutdownFile)); url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab)); @@ -665,7 +667,7 @@ TEST_F(WorkerTest, FLAKY_QueuedSharedWorkerShutdown) { TEST_F(WorkerTest, FLAKY_MultipleTabsQueuedSharedWorker) { // Tests to make sure that only one instance of queued shared workers are // started up even when those instances are on multiple tabs. - int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; + int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), FilePath(kManySharedWorkersFile)); url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); @@ -699,7 +701,7 @@ TEST_F(WorkerTest, FLAKY_MultipleTabsQueuedSharedWorker) { TEST_F(WorkerTest, FLAKY_QueuedSharedWorkerStartedFromOtherTab) { // Tests to make sure that queued shared workers are started up when // an instance is launched from another tab. - int max_workers_per_tab = WorkerService::kMaxWorkersPerTabWhenSeparate; + int max_workers_per_tab = WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate; GURL url = ui_test_utils::GetTestUrl(FilePath(kTestDir), FilePath(kManySharedWorkersFile)); url = GURL(url.spec() + StringPrintf("?count=%d", max_workers_per_tab+1)); |