Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: content/browser/service_worker/service_worker_process_manager.cc

Issue 292903002: Save running SW instance info, including its SiteInstance, into the ProcessManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Dominic's comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_process_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_process_manager.cc
diff --git a/content/browser/service_worker/service_worker_process_manager.cc b/content/browser/service_worker/service_worker_process_manager.cc
index b6a2891e2d2254d718312c68c5daee83369051a3..fdc1aa63602088d2238177fad6dfd70ebabd337d 100644
--- a/content/browser/service_worker/service_worker_process_manager.cc
+++ b/content/browser/service_worker/service_worker_process_manager.cc
@@ -12,9 +12,20 @@
namespace content {
+static bool IncrementWorkerRefCountByPid(
+ int process_id) {
kinuko 2014/05/20 06:30:03 nit: line 15-16 would probably fit into single lin
Jeffrey Yasskin 2014/05/21 02:01:11 Done.
+ RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
+ if (!rph || rph->FastShutdownStarted())
+ return false;
+
+ static_cast<RenderProcessHostImpl*>(rph)->IncrementWorkerRefCount();
+ return true;
+}
+
ServiceWorkerProcessManager::ServiceWorkerProcessManager(
ServiceWorkerContextWrapper* context_wrapper)
: context_wrapper_(context_wrapper),
+ process_id_for_test_(-1),
weak_this_factory_(this),
weak_this_(weak_this_factory_.GetWeakPtr()) {
}
@@ -24,26 +35,43 @@ ServiceWorkerProcessManager::~ServiceWorkerProcessManager() {
}
void ServiceWorkerProcessManager::AllocateWorkerProcess(
+ int embedded_worker_id,
const std::vector<int>& process_ids,
const GURL& script_url,
const base::Callback<void(ServiceWorkerStatusCode, int process_id)>&
- callback) const {
+ callback) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&ServiceWorkerProcessManager::AllocateWorkerProcess,
weak_this_,
+ embedded_worker_id,
process_ids,
script_url,
callback));
return;
}
+ if (process_id_for_test_ != -1) {
+ // Let tests specify the returned process ID. Note: We may need to be able
+ // to specify the error code too.
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(callback, SERVICE_WORKER_OK, process_id_for_test_));
+ return;
+ }
+
+ DCHECK(!ContainsKey(instance_info_, embedded_worker_id))
+ << embedded_worker_id << " already has a process allocated";
+
for (std::vector<int>::const_iterator it = process_ids.begin();
it != process_ids.end();
++it) {
- if (IncrementWorkerRefcountByPid(*it)) {
+ if (IncrementWorkerRefCountByPid(*it)) {
+ instance_info_.insert(
+ std::make_pair(embedded_worker_id, ProcessInfo(*it)));
BrowserThread::PostTask(BrowserThread::IO,
FROM_HERE,
base::Bind(callback, SERVICE_WORKER_OK, *it));
@@ -75,6 +103,9 @@ void ServiceWorkerProcessManager::AllocateWorkerProcess(
return;
}
+ instance_info_.insert(
+ std::make_pair(embedded_worker_id, ProcessInfo(site_instance)));
+
static_cast<RenderProcessHostImpl*>(rph)->IncrementWorkerRefCount();
BrowserThread::PostTask(
BrowserThread::IO,
@@ -82,53 +113,49 @@ void ServiceWorkerProcessManager::AllocateWorkerProcess(
base::Bind(callback, SERVICE_WORKER_OK, rph->GetID()));
}
-void ServiceWorkerProcessManager::ReleaseWorkerProcess(int process_id) {
+void ServiceWorkerProcessManager::ReleaseWorkerProcess(int embedded_worker_id) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&ServiceWorkerProcessManager::ReleaseWorkerProcess,
weak_this_,
- process_id));
+ embedded_worker_id));
+ return;
+ }
+ if (process_id_for_test_ != -1) {
+ // Unittests don't increment or decrement the worker refcount of a
+ // RenderProcessHost.
return;
}
- if (!DecrementWorkerRefcountByPid(process_id)) {
- DCHECK(false) << "DecrementWorkerRef(" << process_id
- << ") doesn't match a previous IncrementWorkerRef";
+ std::map<int, ProcessInfo>::iterator info =
+ instance_info_.find(embedded_worker_id);
+ DCHECK(info != instance_info_.end());
+ RenderProcessHost* rph = NULL;
+ if (info->second.site_instance) {
+ rph = info->second.site_instance->GetProcess();
+ DCHECK_EQ(info->second.process_id, rph->GetID())
+ << "A SiteInstance's process shouldn't get destroyed while we're "
+ "holding a reference to it. Was the reference actually held?";
+ } else {
+ rph = RenderProcessHost::FromID(info->second.process_id);
+ DCHECK(rph)
+ << "Process " << info->second.process_id
+ << " was destroyed unexpectedly. Did we actually hold a reference?";
}
+ static_cast<RenderProcessHostImpl*>(rph)->DecrementWorkerRefCount();
+ instance_info_.erase(info);
}
-void ServiceWorkerProcessManager::SetProcessRefcountOpsForTest(
- const base::Callback<bool(int)>& increment_for_test,
- const base::Callback<bool(int)>& decrement_for_test) {
- increment_for_test_ = increment_for_test;
- decrement_for_test_ = decrement_for_test;
+ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(
kinuko 2014/05/20 06:30:03 nit: can these ProcessInfo definitions be placed b
Jeffrey Yasskin 2014/05/21 02:01:11 Done.
+ const scoped_refptr<SiteInstance>& site_instance)
+ : site_instance(site_instance),
+ process_id(site_instance->GetProcess()->GetID()) {
}
-
-bool ServiceWorkerProcessManager::IncrementWorkerRefcountByPid(
- int process_id) const {
- if (!increment_for_test_.is_null())
- return increment_for_test_.Run(process_id);
-
- RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
- if (rph && !rph->FastShutdownStarted()) {
- static_cast<RenderProcessHostImpl*>(rph)->IncrementWorkerRefCount();
- return true;
- }
-
- return false;
+ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id)
+ : process_id(process_id) {
}
-
-bool ServiceWorkerProcessManager::DecrementWorkerRefcountByPid(
- int process_id) const {
- if (!decrement_for_test_.is_null())
- return decrement_for_test_.Run(process_id);
-
- RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
- if (rph)
- static_cast<RenderProcessHostImpl*>(rph)->DecrementWorkerRefCount();
-
- return rph != NULL;
+ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() {
}
} // namespace content
« no previous file with comments | « content/browser/service_worker/service_worker_process_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698