| Index: trunk/src/content/browser/service_worker/service_worker_process_manager.cc
|
| ===================================================================
|
| --- trunk/src/content/browser/service_worker/service_worker_process_manager.cc (revision 272148)
|
| +++ trunk/src/content/browser/service_worker/service_worker_process_manager.cc (working copy)
|
| @@ -12,32 +12,9 @@
|
|
|
| namespace content {
|
|
|
| -static bool IncrementWorkerRefCountByPid(int process_id) {
|
| - RenderProcessHost* rph = RenderProcessHost::FromID(process_id);
|
| - if (!rph || rph->FastShutdownStarted())
|
| - return false;
|
| -
|
| - static_cast<RenderProcessHostImpl*>(rph)->IncrementWorkerRefCount();
|
| - return true;
|
| -}
|
| -
|
| -ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(
|
| - const scoped_refptr<SiteInstance>& site_instance)
|
| - : site_instance(site_instance),
|
| - process_id(site_instance->GetProcess()->GetID()) {
|
| -}
|
| -
|
| -ServiceWorkerProcessManager::ProcessInfo::ProcessInfo(int process_id)
|
| - : process_id(process_id) {
|
| -}
|
| -
|
| -ServiceWorkerProcessManager::ProcessInfo::~ProcessInfo() {
|
| -}
|
| -
|
| ServiceWorkerProcessManager::ServiceWorkerProcessManager(
|
| ServiceWorkerContextWrapper* context_wrapper)
|
| : context_wrapper_(context_wrapper),
|
| - process_id_for_test_(-1),
|
| weak_this_factory_(this),
|
| weak_this_(weak_this_factory_.GetWeakPtr()) {
|
| }
|
| @@ -47,43 +24,26 @@
|
| }
|
|
|
| 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) {
|
| + callback) const {
|
| 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)) {
|
| - instance_info_.insert(
|
| - std::make_pair(embedded_worker_id, ProcessInfo(*it)));
|
| + if (IncrementWorkerRefcountByPid(*it)) {
|
| BrowserThread::PostTask(BrowserThread::IO,
|
| FROM_HERE,
|
| base::Bind(callback, SERVICE_WORKER_OK, *it));
|
| @@ -115,9 +75,6 @@
|
| return;
|
| }
|
|
|
| - instance_info_.insert(
|
| - std::make_pair(embedded_worker_id, ProcessInfo(site_instance)));
|
| -
|
| static_cast<RenderProcessHostImpl*>(rph)->IncrementWorkerRefCount();
|
| BrowserThread::PostTask(
|
| BrowserThread::IO,
|
| @@ -125,40 +82,55 @@
|
| base::Bind(callback, SERVICE_WORKER_OK, rph->GetID()));
|
| }
|
|
|
| -void ServiceWorkerProcessManager::ReleaseWorkerProcess(int embedded_worker_id) {
|
| +void ServiceWorkerProcessManager::ReleaseWorkerProcess(int process_id) {
|
| if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
| BrowserThread::PostTask(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| base::Bind(&ServiceWorkerProcessManager::ReleaseWorkerProcess,
|
| weak_this_,
|
| - embedded_worker_id));
|
| + process_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?";
|
| +}
|
| +
|
| +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;
|
| +}
|
| +
|
| +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;
|
| }
|
| - static_cast<RenderProcessHostImpl*>(rph)->DecrementWorkerRefCount();
|
| - instance_info_.erase(info);
|
| +
|
| + return false;
|
| }
|
|
|
| +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;
|
| +}
|
| +
|
| } // namespace content
|
|
|
| namespace base {
|
|
|