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

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

Issue 2248583003: Force release the worker ref count to release the process in BrowserContext::NotifyWillBeDestroyed() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 12 matching lines...) Expand all
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/common/mojo/constants.h" 29 #include "content/common/mojo/constants.h"
30 #include "content/public/browser/blob_handle.h" 30 #include "content/public/browser/blob_handle.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/content_browser_client.h" 32 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/site_instance.h" 34 #include "content/public/browser/site_instance.h"
34 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
35 #include "content/public/common/mojo_shell_connection.h" 36 #include "content/public/common/mojo_shell_connection.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"
42 #include "services/file/public/cpp/constants.h" 43 #include "services/file/public/cpp/constants.h"
(...skipping 282 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 correctly and don't necessary run
338 // on the UI thread anyway, so we can't use the AllHostIterator.
339 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
340 return;
341
342 // Force release the worker ref count to release the render process which have
343 // been kept alive for shared workers.
344 for (content::RenderProcessHost::iterator host_iterator =
345 content::RenderProcessHost::AllHostsIterator();
346 !host_iterator.IsAtEnd(); host_iterator.Advance()) {
347 content::RenderProcessHost* host = host_iterator.GetCurrentValue();
348 if (host->GetBrowserContext() == browser_context)
349 host->ForceReleaseWorkerRefCount();
350 }
335 } 351 }
336 352
337 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) { 353 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
338 // This will be enough to tickle initialization of BrowserContext if 354 // This will be enough to tickle initialization of BrowserContext if
339 // necessary, which initializes ResourceContext. The reason we don't call 355 // necessary, which initializes ResourceContext. The reason we don't call
340 // ResourceContext::InitializeResourceContext() directly here is that 356 // ResourceContext::InitializeResourceContext() directly here is that
341 // ResourceContext initialization may call back into BrowserContext 357 // ResourceContext initialization may call back into BrowserContext
342 // and when that call returns it'll end rewriting its UserData map. It will 358 // 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. 359 // end up rewriting the same value but this still causes a race condition.
344 // 360 //
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (GetUserData(kDownloadManagerKeyName)) 515 if (GetUserData(kDownloadManagerKeyName))
500 GetDownloadManager(this)->Shutdown(); 516 GetDownloadManager(this)->Shutdown();
501 } 517 }
502 518
503 void BrowserContext::ShutdownStoragePartitions() { 519 void BrowserContext::ShutdownStoragePartitions() {
504 if (GetUserData(kStoragePartitionMapKeyName)) 520 if (GetUserData(kStoragePartitionMapKeyName))
505 RemoveUserData(kStoragePartitionMapKeyName); 521 RemoveUserData(kStoragePartitionMapKeyName);
506 } 522 }
507 523
508 } // namespace content 524 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698