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

Side by Side Diff: content/browser/browser_context.cc

Issue 2342523002: Forcibly clear worker ref counts on shutdown. (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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/browser/browser_context.h" 5 #include "content/public/browser/browser_context.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 11 matching lines...) Expand all
22 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 22 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
23 #include "content/browser/download/download_manager_impl.h" 23 #include "content/browser/download/download_manager_impl.h"
24 #include "content/browser/indexed_db/indexed_db_context_impl.h" 24 #include "content/browser/indexed_db/indexed_db_context_impl.h"
25 #include "content/browser/loader/resource_dispatcher_host_impl.h" 25 #include "content/browser/loader/resource_dispatcher_host_impl.h"
26 #include "content/browser/push_messaging/push_messaging_router.h" 26 #include "content/browser/push_messaging/push_messaging_router.h"
27 #include "content/browser/storage_partition_impl_map.h" 27 #include "content/browser/storage_partition_impl_map.h"
28 #include "content/common/child_process_host_impl.h" 28 #include "content/common/child_process_host_impl.h"
29 #include "content/public/browser/blob_handle.h" 29 #include "content/public/browser/blob_handle.h"
30 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
32 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/site_instance.h" 33 #include "content/public/browser/site_instance.h"
33 #include "content/public/common/content_switches.h" 34 #include "content/public/common/content_switches.h"
34 #include "content/public/common/mojo_shell_connection.h" 35 #include "content/public/common/mojo_shell_connection.h"
35 #include "content/public/common/service_names.h" 36 #include "content/public/common/service_names.h"
36 #include "net/cookies/cookie_store.h" 37 #include "net/cookies/cookie_store.h"
37 #include "net/ssl/channel_id_service.h" 38 #include "net/ssl/channel_id_service.h"
38 #include "net/ssl/channel_id_store.h" 39 #include "net/ssl/channel_id_store.h"
39 #include "net/url_request/url_request_context.h" 40 #include "net/url_request/url_request_context.h"
40 #include "net/url_request/url_request_context_getter.h" 41 #include "net/url_request/url_request_context_getter.h"
41 #include "services/file/file_service.h" 42 #include "services/file/file_service.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 callback); 326 callback);
326 } 327 }
327 328
328 // static 329 // static
329 void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) { 330 void BrowserContext::NotifyWillBeDestroyed(BrowserContext* browser_context) {
330 // Service Workers must shutdown before the browser context is destroyed, 331 // Service Workers must shutdown before the browser context is destroyed,
331 // since they keep render process hosts alive and the codebase assumes that 332 // since they keep render process hosts alive and the codebase assumes that
332 // render process hosts die before their profile (browser context) dies. 333 // render process hosts die before their profile (browser context) dies.
333 ForEachStoragePartition(browser_context, 334 ForEachStoragePartition(browser_context,
334 base::Bind(ShutdownServiceWorkerContext)); 335 base::Bind(ShutdownServiceWorkerContext));
336
337 // Some tests don't setup RenderProcessHost and don't necessarily run
338 // on the UI thread anyway, so we can't use the AllHostIterator.
jam 2016/09/14 17:10:49 how many tests is this for? can't we just add test
falken 2016/09/21 08:59:43 Done, removed this and added testbundles.
339 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
340 return;
341
342 // Shared workers also keep render process hosts alive. However shared worker
343 // bookkeeping is done on the IO thread and we want to ensure the hosts are
344 // destructed now, so forcibly release their ref counts.
345 for (content::RenderProcessHost::iterator host_iterator =
jam 2016/09/14 17:10:49 here and below, no "content::"
falken 2016/09/21 08:59:43 Done.
346 content::RenderProcessHost::AllHostsIterator();
347 !host_iterator.IsAtEnd(); host_iterator.Advance()) {
348 content::RenderProcessHost* host = host_iterator.GetCurrentValue();
349 if (host->GetBrowserContext() == browser_context)
350 host->ForceReleaseWorkerRefCounts();
351 }
335 } 352 }
336 353
337 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { 354 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
338 // This will be enough to tickle initialization of BrowserContext if 355 // This will be enough to tickle initialization of BrowserContext if
339 // necessary, which initializes ResourceContext. The reason we don't call 356 // necessary, which initializes ResourceContext. The reason we don't call
340 // ResourceContext::InitializeResourceContext() directly here is that 357 // ResourceContext::InitializeResourceContext() directly here is that
341 // ResourceContext initialization may call back into BrowserContext 358 // ResourceContext initialization may call back into BrowserContext
342 // and when that call returns it'll end rewriting its UserData map. It will 359 // and when that call returns it'll end rewriting its UserData map. It will
343 // end up rewriting the same value but this still causes a race condition. 360 // end up rewriting the same value but this still causes a race condition.
344 // 361 //
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (GetUserData(kDownloadManagerKeyName)) 516 if (GetUserData(kDownloadManagerKeyName))
500 GetDownloadManager(this)->Shutdown(); 517 GetDownloadManager(this)->Shutdown();
501 } 518 }
502 519
503 void BrowserContext::ShutdownStoragePartitions() { 520 void BrowserContext::ShutdownStoragePartitions() {
504 if (GetUserData(kStoragePartitionMapKeyName)) 521 if (GetUserData(kStoragePartitionMapKeyName))
505 RemoveUserData(kStoragePartitionMapKeyName); 522 RemoveUserData(kStoragePartitionMapKeyName);
506 } 523 }
507 524
508 } // namespace content 525 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698