summaryrefslogtreecommitdiffstats
path: root/chrome/browser/worker_host
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-23 00:25:04 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-23 00:25:04 +0000
commitcb5b58c021e7fbcf3f377697870401cdd159ff6d (patch)
tree48e4845d5c8f984765a869f085eefd1d2fc5d2ed /chrome/browser/worker_host
parent4225cbbd34cb72a87dc24be6e87537ba8c1b8505 (diff)
downloadchromium_src-cb5b58c021e7fbcf3f377697870401cdd159ff6d.zip
chromium_src-cb5b58c021e7fbcf3f377697870401cdd159ff6d.tar.gz
chromium_src-cb5b58c021e7fbcf3f377697870401cdd159ff6d.tar.bz2
Revert 36888 - Refactored code to allow associating workers with multiple renderers.
SharedWorkers now gracefully handle http auth requests after their initial window has closed. BUG=27660 TEST=WorkerHttpAuth,SharedWorkerHttpAuth uitests Review URL: http://codereview.chromium.org/509016 TBR=atwilson@chromium.org Review URL: http://codereview.chromium.org/549138 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/worker_host')
-rw-r--r--chrome/browser/worker_host/worker_document_set.cc64
-rw-r--r--chrome/browser/worker_host/worker_document_set.h85
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc117
-rw-r--r--chrome/browser/worker_host/worker_process_host.h53
-rw-r--r--chrome/browser/worker_host/worker_service.cc64
-rw-r--r--chrome/browser/worker_host/worker_service.h9
6 files changed, 119 insertions, 273 deletions
diff --git a/chrome/browser/worker_host/worker_document_set.cc b/chrome/browser/worker_host/worker_document_set.cc
deleted file mode 100644
index 2e4d9aa..0000000
--- a/chrome/browser/worker_host/worker_document_set.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (c) 2009 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.
-
-#include "chrome/browser/worker_host/worker_document_set.h"
-
-WorkerDocumentSet::WorkerDocumentSet() {
-}
-
-void WorkerDocumentSet::Add(IPC::Message::Sender* parent,
- unsigned long long document_id,
- int renderer_id,
- int render_view_route_id) {
- DocumentInfo info(parent, document_id, renderer_id, render_view_route_id);
- document_set_.insert(info);
-}
-
-bool WorkerDocumentSet::Contains(IPC::Message::Sender* parent,
- unsigned long long document_id) const {
- for (DocumentInfoSet::const_iterator i = document_set_.begin();
- i != document_set_.end(); ++i) {
- if (i->sender() == parent && i->document_id() == document_id)
- return true;
- }
- return false;
-}
-
-void WorkerDocumentSet::Remove(IPC::Message::Sender* parent,
- unsigned long long document_id) {
- for (DocumentInfoSet::iterator i = document_set_.begin();
- i != document_set_.end(); i++) {
- if (i->sender() == parent && i->document_id() == document_id) {
- document_set_.erase(i);
- break;
- }
- }
- // Should not be duplicate copies in the document set.
- DCHECK(!Contains(parent, document_id));
-}
-
-void WorkerDocumentSet::RemoveAll(IPC::Message::Sender* parent) {
- for (DocumentInfoSet::iterator i = document_set_.begin();
- i != document_set_.end();) {
-
- // Note this idiom is somewhat tricky - calling document_set_.erase(iter)
- // invalidates any iterators that point to the element being removed, so
- // bump the iterator beyond the item being removed before calling erase.
- if (i->sender() == parent) {
- DocumentInfoSet::iterator item_to_delete = i++;
- document_set_.erase(item_to_delete);
- } else {
- ++i;
- }
- }
-}
-
-WorkerDocumentSet::DocumentInfo::DocumentInfo(
- IPC::Message::Sender* sender, unsigned long long document_id,
- int renderer_id, int render_view_route_id)
- : sender_(sender),
- document_id_(document_id),
- renderer_id_(renderer_id),
- render_view_route_id_(render_view_route_id) {
-}
diff --git a/chrome/browser/worker_host/worker_document_set.h b/chrome/browser/worker_host/worker_document_set.h
deleted file mode 100644
index 57c1669..0000000
--- a/chrome/browser/worker_host/worker_document_set.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2009 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 CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
-#define CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
-
-#include <set>
-
-#include "base/basictypes.h"
-#include "base/ref_counted.h"
-#include "ipc/ipc_message.h"
-
-// The WorkerDocumentSet tracks all of the DOM documents associated with a
-// set of workers. With nested workers, multiple workers can share the same
-// WorkerDocumentSet (meaning that they all share the same lifetime, and will
-// all exit when the last document in that set exits, per the WebWorkers spec).
-class WorkerDocumentSet : public base::RefCounted<WorkerDocumentSet> {
- public:
- WorkerDocumentSet();
-
- // The information we track for each document
- class DocumentInfo {
- public:
- DocumentInfo(IPC::Message::Sender* sender, unsigned long long document_id,
- int renderer_id, int render_view_route_id);
- IPC::Message::Sender* sender() const { return sender_; }
- unsigned long long document_id() const { return document_id_; }
- int renderer_id() const { return renderer_id_; }
- int render_view_route_id() const { return render_view_route_id_; }
-
- // Define operator "<", which is used to determine uniqueness within
- // the set.
- bool operator <(DocumentInfo other) const {
- // Items are identical if the sender and document_id are identical,
- // otherwise create an arbitrary stable ordering based on the document
- // id/sender.
- if (sender() == other.sender()) {
- return document_id() < other.document_id();
- } else {
- return reinterpret_cast<unsigned long long>(sender()) <
- reinterpret_cast<unsigned long long>(other.sender());
- }
- }
-
- private:
- IPC::Message::Sender* sender_;
- unsigned long long document_id_;
- int renderer_id_;
- int render_view_route_id_;
- };
-
- // Adds a document to a shared worker's document set. Also includes the
- // associated renderer_id the document is associated with, to enable
- // communication with the parent tab for things like http auth dialogs.
- void Add(IPC::Message::Sender* parent,
- unsigned long long document_id,
- int renderer_id,
- int render_view_route_id);
-
- // Checks to see if a document is in a shared worker's document set.
- bool Contains(IPC::Message::Sender* parent,
- unsigned long long document_id) const;
-
- // Removes a specific document from a worker's document set when that document
- // is detached.
- void Remove(IPC::Message::Sender* parent, unsigned long long document_id);
-
- // Invoked when a render process exits, to remove all associated documents
- // from a worker's document set.
- void RemoveAll(IPC::Message::Sender* parent);
-
- bool IsEmpty() const { return document_set_.empty(); }
-
- // Define a typedef for convenience here when declaring iterators, etc.
- typedef std::set<DocumentInfo> DocumentInfoSet;
-
- // Returns the set of documents associated with this worker.
- const DocumentInfoSet& documents() { return document_set_; }
-
- private:
- DocumentInfoSet document_set_;
-};
-
-#endif // CHROME_BROWSER_WORKER_HOST_WORKER_DOCUMENT_SET_H_
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index 59f8149..3373e2f 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -65,17 +65,11 @@ WorkerProcessHost::~WorkerProcessHost() {
Source<WorkerProcessHost>(this),
NotificationService::NoDetails());
- // If we crashed, tell the RenderViewHosts.
+ // If we crashed, tell the RenderViewHost.
for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
- const WorkerDocumentSet::DocumentInfoSet& parents =
- i->worker_document_set()->documents();
- for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
- parents.begin(); parent_iter != parents.end(); ++parent_iter) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- new WorkerCrashTask(parent_iter->renderer_id(),
- parent_iter->render_view_route_id()));
- }
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ new WorkerCrashTask(i->renderer_id(), i->render_view_route_id()));
}
ChildProcessSecurityPolicy::GetInstance()->Remove(id());
@@ -336,8 +330,8 @@ void WorkerProcessHost::SenderShutdown(IPC::Message::Sender* sender) {
bool shutdown = false;
i->RemoveSenders(sender);
if (i->shared()) {
- i->worker_document_set()->RemoveAll(sender);
- if (i->worker_document_set()->IsEmpty()) {
+ i->RemoveAllAssociatedDocuments(sender);
+ if (i->IsDocumentSetEmpty()) {
shutdown = true;
}
} else if (i->NumSenders() == 0) {
@@ -380,37 +374,28 @@ void WorkerProcessHost::UpdateTitle() {
void WorkerProcessHost::OnLookupSharedWorker(const GURL& url,
const string16& name,
unsigned long long document_id,
- int render_view_route_id,
int* route_id,
bool* url_mismatch) {
int new_route_id = WorkerService::GetInstance()->next_worker_route_id();
- // TODO(atwilson): Add code to pass in the current worker's document set for
- // these nested workers. Code below will not work for SharedWorkers as it
- // only looks at a single parent.
- DCHECK(instances_.front().worker_document_set()->documents().size() == 1);
- WorkerDocumentSet::DocumentInfoSet::const_iterator first_parent =
- instances_.front().worker_document_set()->documents().begin();
+ // TODO(atwilson): Add code to merge document sets for nested shared workers.
bool worker_found = WorkerService::GetInstance()->LookupSharedWorker(
- url, name, instances_.front().off_the_record(), document_id,
- first_parent->renderer_id(), first_parent->render_view_route_id(), this,
+ url, name, instances_.front().off_the_record(), document_id, this,
new_route_id, url_mismatch);
*route_id = worker_found ? new_route_id : MSG_ROUTING_NONE;
}
-void WorkerProcessHost::OnCreateWorker(
- const ViewHostMsg_CreateWorker_Params& params, int* route_id) {
+void WorkerProcessHost::OnCreateWorker(const GURL& url,
+ bool shared,
+ const string16& name,
+ int render_view_route_id,
+ int* route_id) {
DCHECK(instances_.size() == 1); // Only called when one process per worker.
- // TODO(atwilson): Add code to pass in the current worker's document set for
- // these nested workers. Code below will not work for SharedWorkers as it
- // only looks at a single parent.
- DCHECK(instances_.front().worker_document_set()->documents().size() == 1);
- WorkerDocumentSet::DocumentInfoSet::const_iterator first_parent =
- instances_.front().worker_document_set()->documents().begin();
*route_id = WorkerService::GetInstance()->next_worker_route_id();
WorkerService::GetInstance()->CreateWorker(
- params.url, params.is_shared, instances_.front().off_the_record(),
- params.name, params.document_id, first_parent->renderer_id(),
- first_parent->render_view_route_id(), this, *route_id);
+ url, shared, instances_.front().off_the_record(), name,
+ instances_.front().renderer_id(),
+ instances_.front().render_view_route_id(), this, *route_id);
+ // TODO(atwilson): Add code to merge document sets for nested shared workers.
}
void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) {
@@ -429,8 +414,8 @@ void WorkerProcessHost::DocumentDetached(IPC::Message::Sender* parent,
if (!i->shared()) {
++i;
} else {
- i->worker_document_set()->Remove(parent, document_id);
- if (i->worker_document_set()->IsEmpty()) {
+ i->RemoveFromDocumentSet(parent, document_id);
+ if (i->IsDocumentSetEmpty()) {
// This worker has no more associated documents - shut it down.
Send(new WorkerMsg_TerminateWorkerContext(i->worker_route_id()));
i = instances_.erase(i);
@@ -445,14 +430,17 @@ WorkerProcessHost::WorkerInstance::WorkerInstance(const GURL& url,
bool shared,
bool off_the_record,
const string16& name,
+ int renderer_id,
+ int render_view_route_id,
int worker_route_id)
: url_(url),
shared_(shared),
off_the_record_(off_the_record),
closed_(false),
name_(name),
- worker_route_id_(worker_route_id),
- worker_document_set_(new WorkerDocumentSet()) {
+ renderer_id_(renderer_id),
+ render_view_route_id_(render_view_route_id),
+ worker_route_id_(worker_route_id) {
}
// Compares an instance based on the algorithm in the WebWorkers spec - an
@@ -480,6 +468,48 @@ bool WorkerProcessHost::WorkerInstance::Matches(
return name_ == match_name;
}
+void WorkerProcessHost::WorkerInstance::AddToDocumentSet(
+ IPC::Message::Sender* parent, unsigned long long document_id) {
+ if (!IsInDocumentSet(parent, document_id)) {
+ DocumentInfo info(parent, document_id);
+ document_set_.push_back(info);
+ }
+}
+
+bool WorkerProcessHost::WorkerInstance::IsInDocumentSet(
+ IPC::Message::Sender* parent, unsigned long long document_id) const {
+ for (DocumentSet::const_iterator i = document_set_.begin();
+ i != document_set_.end(); ++i) {
+ if (i->first == parent && i->second == document_id)
+ return true;
+ }
+ return false;
+}
+
+void WorkerProcessHost::WorkerInstance::RemoveFromDocumentSet(
+ IPC::Message::Sender* parent, unsigned long long document_id) {
+ for (DocumentSet::iterator i = document_set_.begin();
+ i != document_set_.end(); i++) {
+ if (i->first == parent && i->second == document_id) {
+ document_set_.erase(i);
+ break;
+ }
+ }
+ // Should not be duplicate copies in the document set.
+ DCHECK(!IsInDocumentSet(parent, document_id));
+}
+
+void WorkerProcessHost::WorkerInstance::RemoveAllAssociatedDocuments(
+ IPC::Message::Sender* parent) {
+ for (DocumentSet::iterator i = document_set_.begin();
+ i != document_set_.end();) {
+ if (i->first == parent)
+ i = document_set_.erase(i);
+ else
+ ++i;
+ }
+}
+
void WorkerProcessHost::WorkerInstance::AddSender(IPC::Message::Sender* sender,
int sender_route_id) {
if (!HasSender(sender, sender_route_id)) {
@@ -522,21 +552,6 @@ bool WorkerProcessHost::WorkerInstance::HasSender(
return false;
}
-bool WorkerProcessHost::WorkerInstance::RendererIsParent(
- int renderer_id, int render_view_route_id) const {
- const WorkerDocumentSet::DocumentInfoSet& parents =
- worker_document_set()->documents();
- for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
- parents.begin();
- parent_iter != parents.end(); ++parent_iter) {
- if (parent_iter->renderer_id() == renderer_id &&
- parent_iter->render_view_route_id() == render_view_route_id) {
- return true;
- }
- }
- return false;
-}
-
WorkerProcessHost::WorkerInstance::SenderInfo
WorkerProcessHost::WorkerInstance::GetSender() const {
DCHECK(NumSenders() == 1);
diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h
index b5a8d74f..1834725 100644
--- a/chrome/browser/worker_host/worker_process_host.h
+++ b/chrome/browser/worker_host/worker_process_host.h
@@ -9,16 +9,12 @@
#include "base/basictypes.h"
#include "base/task.h"
-#include "chrome/browser/worker_host/worker_document_set.h"
#include "chrome/common/child_process_host.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
-struct ViewHostMsg_CreateWorker_Params;
-
class WorkerProcessHost : public ChildProcessHost {
public:
-
// Contains information about each worker instance, needed to forward messages
// between the renderer and worker processes.
class WorkerInstance {
@@ -27,6 +23,8 @@ class WorkerProcessHost : public ChildProcessHost {
bool shared,
bool off_the_record,
const string16& name,
+ int renderer_id,
+ int render_view_route_id,
int worker_route_id);
// Unique identifier for a worker client.
@@ -37,7 +35,6 @@ class WorkerProcessHost : public ChildProcessHost {
void RemoveSender(IPC::Message::Sender* sender, int sender_route_id);
void RemoveSenders(IPC::Message::Sender* sender);
bool HasSender(IPC::Message::Sender* sender, int sender_route_id) const;
- bool RendererIsParent(int renderer_id, int render_view_route_id) const;
int NumSenders() const { return senders_.size(); }
// Returns the single sender (must only be one).
SenderInfo GetSender() const;
@@ -48,13 +45,31 @@ class WorkerProcessHost : public ChildProcessHost {
bool Matches(
const GURL& url, const string16& name, bool off_the_record) const;
- // Shares the passed instance's WorkerDocumentSet with this instance. This
- // instance's current WorkerDocumentSet is dereferenced (and freed if this
- // is the only reference) as a result.
- void ShareDocumentSet(const WorkerInstance& instance) {
- worker_document_set_ = instance.worker_document_set_;
+ // Adds a document to a shared worker's document set.
+ void AddToDocumentSet(IPC::Message::Sender* parent,
+ unsigned long long document_id);
+
+ // Checks to see if a document is in a shared worker's document set.
+ bool IsInDocumentSet(IPC::Message::Sender* parent,
+ unsigned long long document_id) const;
+
+ // Removes a specific document from a shared worker's document set when
+ // that document is detached.
+ void RemoveFromDocumentSet(IPC::Message::Sender* parent,
+ unsigned long long document_id);
+
+ // Copies the document set from one instance to another
+ void CopyDocumentSet(const WorkerInstance& instance) {
+ document_set_ = instance.document_set_;
};
+ // Invoked when a render process exits, to remove all associated documents
+ // from a shared worker's document set.
+ void RemoveAllAssociatedDocuments(IPC::Message::Sender* parent);
+
+ bool IsDocumentSetEmpty() const { return document_set_.empty(); }
+
+
// Accessors
bool shared() const { return shared_; }
bool off_the_record() const { return off_the_record_; }
@@ -62,12 +77,14 @@ class WorkerProcessHost : public ChildProcessHost {
void set_closed(bool closed) { closed_ = closed; }
const GURL& url() const { return url_; }
const string16 name() const { return name_; }
+ int renderer_id() const { return renderer_id_; }
+ int render_view_route_id() const { return render_view_route_id_; }
int worker_route_id() const { return worker_route_id_; }
- WorkerDocumentSet* worker_document_set() const {
- return worker_document_set_;
- }
private:
+ // Unique identifier for an associated document.
+ typedef std::pair<IPC::Message::Sender*, unsigned long long> DocumentInfo;
+ typedef std::list<DocumentInfo> DocumentSet;
// Set of all senders (clients) associated with this worker.
typedef std::list<SenderInfo> SenderList;
GURL url_;
@@ -75,9 +92,11 @@ class WorkerProcessHost : public ChildProcessHost {
bool off_the_record_;
bool closed_;
string16 name_;
+ int renderer_id_;
+ int render_view_route_id_;
int worker_route_id_;
SenderList senders_;
- scoped_refptr<WorkerDocumentSet> worker_document_set_;
+ DocumentSet document_set_;
};
explicit WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host);
@@ -123,7 +142,6 @@ class WorkerProcessHost : public ChildProcessHost {
void OnLookupSharedWorker(const GURL& url,
const string16& name,
unsigned long long document_id,
- int render_view_route_id,
int* route_id,
bool* url_error);
@@ -143,7 +161,10 @@ class WorkerProcessHost : public ChildProcessHost {
// Updates the title shown in the task manager.
void UpdateTitle();
- void OnCreateWorker(const ViewHostMsg_CreateWorker_Params& params,
+ void OnCreateWorker(const GURL& url,
+ bool shared,
+ const string16& name,
+ int render_view_route_id,
int* route_id);
void OnCancelCreateDedicatedWorker(int route_id);
void OnForwardToWorker(const IPC::Message& message);
diff --git a/chrome/browser/worker_host/worker_service.cc b/chrome/browser/worker_host/worker_service.cc
index ffdbb1d..fe768c3 100644
--- a/chrome/browser/worker_host/worker_service.cc
+++ b/chrome/browser/worker_host/worker_service.cc
@@ -49,7 +49,6 @@ bool WorkerService::CreateWorker(const GURL &url,
bool is_shared,
bool off_the_record,
const string16& name,
- unsigned long long document_id,
int renderer_id,
int render_view_route_id,
IPC::Message::Sender* sender,
@@ -62,10 +61,10 @@ bool WorkerService::CreateWorker(const GURL &url,
is_shared,
off_the_record,
name,
+ renderer_id,
+ render_view_route_id,
next_worker_route_id());
instance.AddSender(sender, sender_route_id);
- instance.worker_document_set()->Add(
- sender, document_id, renderer_id, render_view_route_id);
WorkerProcessHost* worker = NULL;
if (CommandLine::ForCurrentProcess()->HasSwitch(
@@ -90,7 +89,6 @@ bool WorkerService::CreateWorker(const GURL &url,
// If this worker is already running, no need to create a new copy. Just
// inform the caller that the worker has been created.
if (existing_instance) {
- // TODO(atwilson): Change this to scan the sender list (crbug.com/29243).
existing_instance->AddSender(sender, sender_route_id);
sender->Send(new ViewMsg_WorkerCreated(sender_route_id));
return true;
@@ -110,8 +108,8 @@ bool WorkerService::CreateWorker(const GURL &url,
// Assign the accumulated document set and sender list for this pending
// worker to the new instance.
- DCHECK(!pending->worker_document_set()->IsEmpty());
- instance.ShareDocumentSet(*pending);
+ DCHECK(!pending->IsDocumentSetEmpty());
+ instance.CopyDocumentSet(*pending);
RemovePendingInstance(url, name, off_the_record);
}
@@ -131,8 +129,6 @@ bool WorkerService::LookupSharedWorker(const GURL &url,
const string16& name,
bool off_the_record,
unsigned long long document_id,
- int renderer_id,
- int render_view_route_id,
IPC::Message::Sender* sender,
int sender_route_id,
bool* url_mismatch) {
@@ -164,8 +160,7 @@ bool WorkerService::LookupSharedWorker(const GURL &url,
instance->AddSender(sender, sender_route_id);
// Add the passed sender/document_id to the worker instance.
- instance->worker_document_set()->Add(
- sender, document_id, renderer_id, render_view_route_id);
+ instance->AddToDocumentSet(sender, document_id);
return found_instance;
}
@@ -181,8 +176,8 @@ void WorkerService::DocumentDetached(IPC::Message::Sender* sender,
for (WorkerProcessHost::Instances::iterator iter = queued_workers_.begin();
iter != queued_workers_.end();) {
if (iter->shared()) {
- iter->worker_document_set()->Remove(sender, document_id);
- if (iter->worker_document_set()->IsEmpty()) {
+ iter->RemoveFromDocumentSet(sender, document_id);
+ if (iter->IsDocumentSetEmpty()) {
iter = queued_workers_.erase(iter);
continue;
}
@@ -194,8 +189,8 @@ void WorkerService::DocumentDetached(IPC::Message::Sender* sender,
for (WorkerProcessHost::Instances::iterator iter =
pending_shared_workers_.begin();
iter != pending_shared_workers_.end(); ) {
- iter->worker_document_set()->Remove(sender, document_id);
- if (iter->worker_document_set()->IsEmpty()) {
+ iter->RemoveFromDocumentSet(sender, document_id);
+ if (iter->IsDocumentSetEmpty()) {
iter = pending_shared_workers_.erase(iter);
} else {
++iter;
@@ -299,35 +294,8 @@ WorkerProcessHost* WorkerService::GetLeastLoadedWorker() {
bool WorkerService::CanCreateWorkerProcess(
const WorkerProcessHost::WorkerInstance& instance) {
- // Worker can be fired off if *any* parent has room.
- const WorkerDocumentSet::DocumentInfoSet& parents =
- instance.worker_document_set()->documents();
-
- for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
- parents.begin();
- parent_iter != parents.end(); ++parent_iter) {
- bool hit_total_worker_limit = false;
- if (TabCanCreateWorkerProcess(parent_iter->renderer_id(),
- parent_iter->render_view_route_id(),
- &hit_total_worker_limit)) {
- return true;
- }
- // Return false if already at the global worker limit (no need to continue
- // checking parent tabs).
- if (hit_total_worker_limit)
- return false;
- }
- // If we've reached here, none of the parent tabs is allowed to create an
- // instance.
- return false;
-}
-
-bool WorkerService::TabCanCreateWorkerProcess(int renderer_id,
- int render_view_route_id,
- bool* hit_total_worker_limit) {
int total_workers = 0;
int workers_per_tab = 0;
- *hit_total_worker_limit = false;
for (ChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS);
!iter.Done(); ++iter) {
WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
@@ -335,11 +303,11 @@ bool WorkerService::TabCanCreateWorkerProcess(int renderer_id,
worker->instances().begin();
cur_instance != worker->instances().end(); ++cur_instance) {
total_workers++;
- if (total_workers >= kMaxWorkersWhenSeparate) {
- *hit_total_worker_limit = true;
+ if (total_workers >= kMaxWorkersWhenSeparate)
return false;
- }
- if (cur_instance->RendererIsParent(renderer_id, render_view_route_id)) {
+ if (cur_instance->renderer_id() == instance.renderer_id() &&
+ cur_instance->render_view_route_id() ==
+ instance.render_view_route_id()) {
workers_per_tab++;
if (workers_per_tab >= kMaxWorkersPerTabWhenSeparate)
return false;
@@ -387,8 +355,8 @@ void WorkerService::SenderShutdown(IPC::Message::Sender* sender) {
for (WorkerProcessHost::Instances::iterator iter =
pending_shared_workers_.begin();
iter != pending_shared_workers_.end(); ) {
- iter->worker_document_set()->RemoveAll(sender);
- if (iter->worker_document_set()->IsEmpty()) {
+ iter->RemoveAllAssociatedDocuments(sender);
+ if (iter->IsDocumentSetEmpty()) {
iter = pending_shared_workers_.erase(iter);
} else {
++iter;
@@ -493,7 +461,7 @@ WorkerService::CreatePendingInstance(const GURL& url,
// No existing pending worker - create a new one.
WorkerProcessHost::WorkerInstance pending(
- url, true, off_the_record, name, MSG_ROUTING_NONE);
+ url, true, off_the_record, name, 0, MSG_ROUTING_NONE, MSG_ROUTING_NONE);
pending_shared_workers_.push_back(pending);
return &pending_shared_workers_.back();
}
diff --git a/chrome/browser/worker_host/worker_service.h b/chrome/browser/worker_host/worker_service.h
index eec45a0..5db6eee 100644
--- a/chrome/browser/worker_host/worker_service.h
+++ b/chrome/browser/worker_host/worker_service.h
@@ -30,7 +30,6 @@ class WorkerService : public NotificationObserver {
bool is_shared,
bool is_off_the_record,
const string16& name,
- unsigned long long document_id,
int renderer_pid,
int render_view_route_id,
IPC::Message::Sender* sender,
@@ -44,8 +43,6 @@ class WorkerService : public NotificationObserver {
const string16& name,
bool off_the_record,
unsigned long long document_id,
- int renderer_pid,
- int render_view_route_id,
IPC::Message::Sender* sender,
int sender_route_id,
bool* url_mismatch);
@@ -104,12 +101,6 @@ class WorkerService : public NotificationObserver {
bool CanCreateWorkerProcess(
const WorkerProcessHost::WorkerInstance& instance);
- // Checks if the tab associated with the passed RenderView can create a
- // worker process based on the process limit when we're using a strategy of
- // one worker per process.
- bool TabCanCreateWorkerProcess(
- int renderer_id, int render_view_route_id, bool* hit_total_worker_limit);
-
// NotificationObserver interface.
void Observe(NotificationType type,
const NotificationSource& source,