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

Side by Side Diff: content/browser/service_worker/service_worker_process_manager.cc

Issue 2318443002: service worker: Add CHECKs to catch if SWProcessManager isn't releasing ref counts. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_process_manager.h" 5 #include "content/browser/service_worker/service_worker_process_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 187
188 if (IsShutdown()) { 188 if (IsShutdown()) {
189 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 189 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
190 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT, 190 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT,
191 ChildProcessHost::kInvalidUniqueID, 191 ChildProcessHost::kInvalidUniqueID,
192 false /* is_new_process */, settings)); 192 false /* is_new_process */, settings));
193 return; 193 return;
194 } 194 }
195 195
196 DCHECK(!base::ContainsKey(instance_info_, embedded_worker_id)) 196 // TODO(falken): Revert to DCHECK. Temporary check for debugging
197 // crbug.com/639193
198 CHECK(!base::ContainsKey(instance_info_, embedded_worker_id))
197 << embedded_worker_id << " already has a process allocated"; 199 << embedded_worker_id << " already has a process allocated";
198 200
199 if (can_use_existing_process) { 201 if (can_use_existing_process) {
200 int process_id = FindAvailableProcess(pattern); 202 int process_id = FindAvailableProcess(pattern);
201 if (process_id != ChildProcessHost::kInvalidUniqueID) { 203 if (process_id != ChildProcessHost::kInvalidUniqueID) {
202 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount(); 204 RenderProcessHost::FromID(process_id)->IncrementServiceWorkerRefCount();
203 instance_info_.insert( 205 instance_info_.insert(
204 std::make_pair(embedded_worker_id, ProcessInfo(process_id))); 206 std::make_pair(embedded_worker_id, ProcessInfo(process_id)));
205 BrowserThread::PostTask( 207 BrowserThread::PostTask(
206 BrowserThread::IO, FROM_HERE, 208 BrowserThread::IO, FROM_HERE,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 251 }
250 252
251 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) { 253 if (process_id_for_test_ != ChildProcessHost::kInvalidUniqueID) {
252 // Unittests don't increment or decrement the worker refcount of a 254 // Unittests don't increment or decrement the worker refcount of a
253 // RenderProcessHost. 255 // RenderProcessHost.
254 return; 256 return;
255 } 257 }
256 258
257 if (IsShutdown()) { 259 if (IsShutdown()) {
258 // Shutdown already released all instances. 260 // Shutdown already released all instances.
259 DCHECK(instance_info_.empty()); 261 // TODO(falken): Revert to DCHECK. Temporary check for debugging
262 // crbug.com/639193
263 CHECK(instance_info_.empty());
260 return; 264 return;
261 } 265 }
262 266
263 std::map<int, ProcessInfo>::iterator info = 267 std::map<int, ProcessInfo>::iterator info =
264 instance_info_.find(embedded_worker_id); 268 instance_info_.find(embedded_worker_id);
265 // ReleaseWorkerProcess could be called for a nonexistent worker id, for 269 // ReleaseWorkerProcess could be called for a nonexistent worker id, for
266 // example, when request to start a worker is aborted on the IO thread during 270 // example, when request to start a worker is aborted on the IO thread during
267 // process allocation that is failed on the UI thread. 271 // process allocation that is failed on the UI thread.
268 if (info == instance_info_.end()) 272 if (info == instance_info_.end())
269 return; 273 return;
270 274
271 RenderProcessHost* rph = NULL; 275 RenderProcessHost* rph = NULL;
272 if (info->second.site_instance.get()) { 276 if (info->second.site_instance.get()) {
273 rph = info->second.site_instance->GetProcess(); 277 rph = info->second.site_instance->GetProcess();
274 DCHECK_EQ(info->second.process_id, rph->GetID()) 278 // TODO(falken): Revert to DCHECK. Temporary check for debugging
279 // crbug.com/639193
280 CHECK_EQ(info->second.process_id, rph->GetID())
275 << "A SiteInstance's process shouldn't get destroyed while we're " 281 << "A SiteInstance's process shouldn't get destroyed while we're "
276 "holding a reference to it. Was the reference actually held?"; 282 "holding a reference to it. Was the reference actually held?";
277 } else { 283 } else {
284 // TODO(falken): Revert to DCHECK. Temporary check for debugging
285 // crbug.com/639193
278 rph = RenderProcessHost::FromID(info->second.process_id); 286 rph = RenderProcessHost::FromID(info->second.process_id);
279 DCHECK(rph) 287 CHECK(rph)
280 << "Process " << info->second.process_id 288 << "Process " << info->second.process_id
281 << " was destroyed unexpectedly. Did we actually hold a reference?"; 289 << " was destroyed unexpectedly. Did we actually hold a reference?";
282 } 290 }
283 rph->DecrementServiceWorkerRefCount(); 291 rph->DecrementServiceWorkerRefCount();
284 instance_info_.erase(info); 292 instance_info_.erase(info);
285 } 293 }
286 294
287 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern( 295 std::vector<int> ServiceWorkerProcessManager::SortProcessesForPattern(
288 const GURL& pattern) const { 296 const GURL& pattern) const {
289 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern); 297 PatternProcessRefMap::const_iterator it = pattern_processes_.find(pattern);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 namespace std { 342 namespace std {
335 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the 343 // Destroying ServiceWorkerProcessManagers only on the UI thread allows the
336 // member WeakPtr to safely guard the object's lifetime when used on that 344 // member WeakPtr to safely guard the object's lifetime when used on that
337 // thread. 345 // thread.
338 void default_delete<content::ServiceWorkerProcessManager>::operator()( 346 void default_delete<content::ServiceWorkerProcessManager>::operator()(
339 content::ServiceWorkerProcessManager* ptr) const { 347 content::ServiceWorkerProcessManager* ptr) const {
340 content::BrowserThread::DeleteSoon( 348 content::BrowserThread::DeleteSoon(
341 content::BrowserThread::UI, FROM_HERE, ptr); 349 content::BrowserThread::UI, FROM_HERE, ptr);
342 } 350 }
343 } // namespace std 351 } // namespace std
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698