diff options
author | simonhatch@chromium.org <simonhatch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-20 16:00:42 +0000 |
---|---|---|
committer | simonhatch@chromium.org <simonhatch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-20 16:00:42 +0000 |
commit | 57e1d686b05277bc5d96b948d028d2ea951bcb7b (patch) | |
tree | 7b99b631084252f61a73e3477676ddfb303a668d | |
parent | 7b3af0d0003a441d9f50bfaf63eb75ca07a7ef7f (diff) | |
download | chromium_src-57e1d686b05277bc5d96b948d028d2ea951bcb7b.zip chromium_src-57e1d686b05277bc5d96b948d028d2ea951bcb7b.tar.gz chromium_src-57e1d686b05277bc5d96b948d028d2ea951bcb7b.tar.bz2 |
Revert 200932 "Lower the priority of shared workers that aren't ..."
> Lower the priority of shared workers that aren't associated with the foreground tab.
>
> This should help out less powerful devices in the case where there's a shared worker in another tab and a cpu intensive page in the foreground.
>
> BUG=
> TEST=Open a doc, see webworker running, switch tabs and check webworker's priority by outputting contents of /sys/fs/cgroup/cpu/chrome_renderers/background/cgroup.proc on ChromeOS. With an open doc in a background tab, run 720p video (ie. youtube) at fullscreen, should stay fairly smooth.
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=199840
>
> Review URL: https://chromiumcodereview.appspot.com/14137016
TBR=simonhatch@chromium.org
Review URL: https://codereview.chromium.org/15465006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201090 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 3 insertions, 234 deletions
diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc index 9851e8c..6a2218f 100644 --- a/content/browser/browser_child_process_host_impl.cc +++ b/content/browser/browser_child_process_host_impl.cc @@ -205,10 +205,6 @@ void BrowserChildProcessHostImpl::ForceShutdown() { child_process_host_->ForceShutdown(); } -void BrowserChildProcessHostImpl::SetBackgrounded(bool backgrounded) { - child_process_->SetProcessBackgrounded(backgrounded); -} - void BrowserChildProcessHostImpl::SetTerminateChildOnShutdown( bool terminate_on_shutdown) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/content/browser/browser_child_process_host_impl.h b/content/browser/browser_child_process_host_impl.h index 9933ca3..e3fdcb5 100644 --- a/content/browser/browser_child_process_host_impl.h +++ b/content/browser/browser_child_process_host_impl.h @@ -61,9 +61,6 @@ class CONTENT_EXPORT BrowserChildProcessHostImpl // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown void ForceShutdown(); - // Callers can reduce the BrowserChildProcess' priority. - void SetBackgrounded(bool backgrounded); - // Controls whether the child process should be terminated on browser // shutdown. Default is to always terminate. void SetTerminateChildOnShutdown(bool terminate_on_shutdown); diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 27d51e2..b818b9d 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -114,8 +114,7 @@ WorkerProcessHost::WorkerProcessHost( ResourceContext* resource_context, const WorkerStoragePartition& partition) : resource_context_(resource_context), - partition_(partition), - process_launched_(false) { + partition_(partition) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(resource_context_); process_.reset( @@ -319,9 +318,6 @@ bool WorkerProcessHost::FilterMessage(const IPC::Message& message, } void WorkerProcessHost::OnProcessLaunched() { - process_launched_ = true; - - WorkerServiceImpl::GetInstance()->NotifyWorkerProcessCreated(); } bool WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { @@ -542,18 +538,10 @@ void WorkerProcessHost::TerminateWorker(int worker_route_id) { Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); } -void WorkerProcessHost::SetBackgrounded(bool backgrounded) { - process_->SetBackgrounded(backgrounded); -} - const ChildProcessData& WorkerProcessHost::GetData() { return process_->GetData(); } -bool WorkerProcessHost::process_launched() const { - return process_launched_; -} - std::vector<std::pair<int, int> > WorkerProcessHost::GetRenderViewIDsForWorker( int worker_route_id) { std::vector<std::pair<int, int> > result; diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h index 715e38c..dd1d58f 100644 --- a/content/browser/worker_host/worker_process_host.h +++ b/content/browser/worker_host/worker_process_host.h @@ -158,9 +158,6 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate, // Terminates the given worker, i.e. based on a UI action. CONTENT_EXPORT void TerminateWorker(int worker_route_id); - // Callers can reduce the WorkerProcess' priority. - void SetBackgrounded(bool backgrounded); - CONTENT_EXPORT const ChildProcessData& GetData(); typedef std::list<WorkerInstance> Instances; @@ -170,8 +167,6 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate, return resource_context_; } - bool process_launched() const; - protected: friend class WorkerServiceImpl; @@ -226,7 +221,6 @@ class WorkerProcessHost : public BrowserChildProcessHostDelegate, scoped_refptr<WorkerMessageFilter> worker_message_filter_; scoped_ptr<BrowserChildProcessHostImpl> process_; - bool process_launched_; 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 2299500..703b31f 100644 --- a/content/browser/worker_host/worker_service_impl.cc +++ b/content/browser/worker_host/worker_service_impl.cc @@ -10,20 +10,12 @@ #include "base/logging.h" #include "base/threading/thread.h" #include "content/browser/devtools/worker_devtools_manager.h" -#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/worker_host/worker_message_filter.h" #include "content/browser/worker_host/worker_process_host.h" #include "content/common/view_messages.h" #include "content/common/worker_messages.h" #include "content/public/browser/child_process_data.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/render_widget_host.h" -#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/resource_context.h" -#include "content/public/browser/web_contents.h" #include "content/public/browser/worker_service_observer.h" #include "content/public/common/content_switches.h" #include "content/public/common/process_type.h" @@ -33,192 +25,6 @@ namespace content { const int WorkerServiceImpl::kMaxWorkersWhenSeparate = 64; const int WorkerServiceImpl::kMaxWorkersPerTabWhenSeparate = 16; -class WorkerPrioritySetter - : public NotificationObserver, - public base::RefCountedThreadSafe<WorkerPrioritySetter, - BrowserThread::DeleteOnUIThread> { - public: - WorkerPrioritySetter(); - - // Posts a task to the UI thread to register to receive notifications. - void Initialize(); - - // Invoked by WorkerServiceImpl when a worker process is created. - void NotifyWorkerProcessCreated(); - - private: - friend class base::RefCountedThreadSafe<WorkerPrioritySetter>; - friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; - friend class base::DeleteHelper<WorkerPrioritySetter>; - virtual ~WorkerPrioritySetter(); - - // Posts a task to perform a worker priority update. - void PostTaskToGatherAndUpdateWorkerPriorities(); - - // Gathers up a list of the visible tabs and then updates priorities for - // all the shared workers. - void GatherVisibleIDsAndUpdateWorkerPriorities(); - - // Registers as an observer to receive notifications about - // widgets being shown. - void RegisterObserver(); - - // Sets priorities for shared workers given a set of visible tabs (as a - // std::set of std::pair<render_process, render_view> ids. - void UpdateWorkerPrioritiesFromVisibleSet( - const std::set<std::pair<int, int> >* visible); - - // Called to refresh worker priorities when focus changes between tabs. - void OnRenderWidgetVisibilityChanged(std::pair<int, int>); - - // NotificationObserver implementation. - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details) OVERRIDE; - - NotificationRegistrar registrar_; -}; - -WorkerPrioritySetter::WorkerPrioritySetter() { -} - -WorkerPrioritySetter::~WorkerPrioritySetter() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - -void WorkerPrioritySetter::Initialize() { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&WorkerPrioritySetter::RegisterObserver, this)); -} - -void WorkerPrioritySetter::NotifyWorkerProcessCreated() { - PostTaskToGatherAndUpdateWorkerPriorities(); -} - -void WorkerPrioritySetter::PostTaskToGatherAndUpdateWorkerPriorities() { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind( - &WorkerPrioritySetter::GatherVisibleIDsAndUpdateWorkerPriorities, - this)); -} - -void WorkerPrioritySetter::GatherVisibleIDsAndUpdateWorkerPriorities() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::set<std::pair<int, int> >* visible_renderer_ids = - new std::set<std::pair<int, int> >(); - - // Gather up all the visible renderer process/view pairs - for (RenderProcessHost::iterator it = - RenderProcessHost::AllHostsIterator(); - !it.IsAtEnd(); it.Advance()) { - RenderProcessHost* render_process_host = it.GetCurrentValue(); - if (render_process_host->VisibleWidgetCount()) { - for (RenderProcessHost::RenderWidgetHostsIterator rit = - render_process_host->GetRenderWidgetHostsIterator(); !rit.IsAtEnd(); - rit.Advance()) { - RenderWidgetHost* render_widget = - render_process_host->GetRenderWidgetHostByID(rit.GetCurrentKey()); - if (render_widget) { - RenderWidgetHostView* render_view = render_widget->GetView(); - if (render_view && render_view->IsShowing()) { - visible_renderer_ids->insert( - std::pair<int, int>(render_process_host->GetID(), - render_widget->GetRoutingID())); - } - } - } - } - } - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&WorkerPrioritySetter::UpdateWorkerPrioritiesFromVisibleSet, - this, base::Owned(visible_renderer_ids))); -} - -void WorkerPrioritySetter::UpdateWorkerPrioritiesFromVisibleSet( - const std::set<std::pair<int, int> >* visible_renderer_ids) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { - if (!iter->process_launched()) - continue; - bool throttle = true; - - for (WorkerProcessHost::Instances::const_iterator instance = - iter->instances().begin(); instance != iter->instances().end(); - ++instance) { - - // This code assumes one worker per process - WorkerProcessHost::Instances::const_iterator first_instance = - iter->instances().begin(); - if (first_instance == iter->instances().end()) - continue; - - WorkerDocumentSet::DocumentInfoSet::const_iterator info = - first_instance->worker_document_set()->documents().begin(); - - for (; info != first_instance->worker_document_set()->documents().end(); - ++info) { - std::pair<int, int> id( - info->render_process_id(), info->render_view_id()); - if (visible_renderer_ids->find(id) != visible_renderer_ids->end()) { - throttle = false; - break; - } - } - - if (!throttle ) { - break; - } - } - - iter->SetBackgrounded(throttle); - } -} - -void WorkerPrioritySetter::OnRenderWidgetVisibilityChanged( - std::pair<int, int> id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - std::set<std::pair<int, int> > visible_renderer_ids; - - visible_renderer_ids.insert(id); - - UpdateWorkerPrioritiesFromVisibleSet(&visible_renderer_ids); -} - -void WorkerPrioritySetter::RegisterObserver() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, - NotificationService::AllBrowserContextsAndSources()); - registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CREATED, - NotificationService::AllBrowserContextsAndSources()); -} - -void WorkerPrioritySetter::Observe(int type, - const NotificationSource& source, const NotificationDetails& details) { - if (type == NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { - bool visible = *Details<bool>(details).ptr(); - - if (visible) { - int render_widget_id = - Source<RenderWidgetHost>(source).ptr()->GetRoutingID(); - int render_process_pid = - Source<RenderWidgetHost>(source).ptr()->GetProcess()->GetID(); - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&WorkerPrioritySetter::OnRenderWidgetVisibilityChanged, - this, std::pair<int, int>(render_process_pid, render_widget_id))); - } - } - else if (type == NOTIFICATION_RENDERER_PROCESS_CREATED) { - PostTaskToGatherAndUpdateWorkerPriorities(); - } -} - WorkerService* WorkerService::GetInstance() { return WorkerServiceImpl::GetInstance(); } @@ -228,10 +34,7 @@ WorkerServiceImpl* WorkerServiceImpl::GetInstance() { return Singleton<WorkerServiceImpl>::get(); } -WorkerServiceImpl::WorkerServiceImpl() - : priority_setter_(new WorkerPrioritySetter()), - next_worker_route_id_(0) { - priority_setter_->Initialize(); +WorkerServiceImpl::WorkerServiceImpl() : next_worker_route_id_(0) { } WorkerServiceImpl::~WorkerServiceImpl() { @@ -654,10 +457,6 @@ void WorkerServiceImpl::NotifyWorkerDestroyed( WorkerDestroyed(process->GetData().id, worker_route_id)); } -void WorkerServiceImpl::NotifyWorkerProcessCreated() { - priority_setter_->NotifyWorkerProcessCreated(); -} - WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindSharedWorkerInstance( const GURL& url, const string16& name, diff --git a/content/browser/worker_host/worker_service_impl.h b/content/browser/worker_host/worker_service_impl.h index aed05b8..845f433 100644 --- a/content/browser/worker_host/worker_service_impl.h +++ b/content/browser/worker_host/worker_service_impl.h @@ -11,7 +11,6 @@ #include "base/observer_list.h" #include "base/threading/non_thread_safe.h" #include "content/browser/worker_host/worker_process_host.h" -#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/worker_service.h" @@ -22,7 +21,6 @@ namespace content { class ResourceContext; class WorkerServiceObserver; class WorkerStoragePartition; -class WorkerPrioritySetter; class CONTENT_EXPORT WorkerServiceImpl : public NON_EXPORTED_BASE(WorkerService) { @@ -74,8 +72,6 @@ class CONTENT_EXPORT WorkerServiceImpl WorkerProcessHost* process, int worker_route_id); - void NotifyWorkerProcessCreated(); - // Used when we run each worker in a separate process. static const int kMaxWorkersWhenSeparate; static const int kMaxWorkersPerTabWhenSeparate; @@ -126,8 +122,7 @@ class CONTENT_EXPORT WorkerServiceImpl const WorkerStoragePartition& worker_partition, ResourceContext* resource_context); - scoped_refptr<WorkerPrioritySetter> priority_setter_; - + NotificationRegistrar registrar_; int next_worker_route_id_; WorkerProcessHost::Instances queued_workers_; |