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

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

Issue 2342523002: Forcibly clear worker ref counts on shutdown. (Closed)
Patch Set: rebase Created 4 years, 2 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 // Shared workers also keep render process hosts alive, and are expected to
338 // return ref counts to 0 after documents close. However, shared worker
339 // bookkeeping is done on the IO thread and we want to ensure the hosts are
340 // destructed now, so forcibly release their ref counts here.
341 for (RenderProcessHost::iterator host_iterator =
342 RenderProcessHost::AllHostsIterator();
343 !host_iterator.IsAtEnd(); host_iterator.Advance()) {
344 RenderProcessHost* host = host_iterator.GetCurrentValue();
345 if (host->GetBrowserContext() == browser_context)
346 host->ForceReleaseWorkerRefCounts();
347 }
335 } 348 }
336 349
337 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { 350 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
338 // This will be enough to tickle initialization of BrowserContext if 351 // This will be enough to tickle initialization of BrowserContext if
339 // necessary, which initializes ResourceContext. The reason we don't call 352 // necessary, which initializes ResourceContext. The reason we don't call
340 // ResourceContext::InitializeResourceContext() directly here is that 353 // ResourceContext::InitializeResourceContext() directly here is that
341 // ResourceContext initialization may call back into BrowserContext 354 // ResourceContext initialization may call back into BrowserContext
342 // and when that call returns it'll end rewriting its UserData map. It will 355 // 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. 356 // end up rewriting the same value but this still causes a race condition.
344 // 357 //
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (GetUserData(kDownloadManagerKeyName)) 512 if (GetUserData(kDownloadManagerKeyName))
500 GetDownloadManager(this)->Shutdown(); 513 GetDownloadManager(this)->Shutdown();
501 } 514 }
502 515
503 void BrowserContext::ShutdownStoragePartitions() { 516 void BrowserContext::ShutdownStoragePartitions() {
504 if (GetUserData(kStoragePartitionMapKeyName)) 517 if (GetUserData(kStoragePartitionMapKeyName))
505 RemoveUserData(kStoragePartitionMapKeyName); 518 RemoveUserData(kStoragePartitionMapKeyName);
506 } 519 }
507 520
508 } // namespace content 521 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble_unittest.cc ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698