Add callback in UserScriptLoader to notify users when scripts are loaded.
[chromium-blink-merge.git] / content / browser / browser_process_sub_thread.cc
blobb1904e10971814c4ff0dd594b179eb0dfab5b02b
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
3 // found in the LICENSE file.
5 #include "content/browser/browser_process_sub_thread.h"
7 #include "base/debug/leak_tracker.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "base/trace_event/memory_dump_manager.h"
10 #include "build/build_config.h"
11 #include "content/browser/browser_child_process_host_impl.h"
12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
13 #include "content/browser/notification_service_impl.h"
14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_request.h"
17 #if defined(OS_WIN)
18 #include "base/win/scoped_com_initializer.h"
19 #endif
21 namespace content {
23 BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier)
24 : BrowserThreadImpl(identifier) {
27 BrowserProcessSubThread::~BrowserProcessSubThread() {
28 Stop();
31 void BrowserProcessSubThread::Init() {
32 #if defined(OS_WIN)
33 com_initializer_.reset(new base::win::ScopedCOMInitializer());
34 #endif
36 notification_service_.reset(new NotificationServiceImpl());
38 BrowserThreadImpl::Init();
40 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
41 // Though this thread is called the "IO" thread, it actually just routes
42 // messages around; it shouldn't be allowed to perform any blocking disk
43 // I/O.
44 base::ThreadRestrictions::SetIOAllowed(false);
45 base::ThreadRestrictions::DisallowWaiting();
49 void BrowserProcessSubThread::CleanUp() {
50 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
51 IOThreadPreCleanUp();
53 BrowserThreadImpl::CleanUp();
55 notification_service_.reset();
57 #if defined(OS_WIN)
58 com_initializer_.reset();
59 #endif
62 void BrowserProcessSubThread::IOThreadPreCleanUp() {
63 // Kill all things that might be holding onto
64 // net::URLRequest/net::URLRequestContexts.
66 // Destroy all URLRequests started by URLFetchers.
67 net::URLFetcher::CancelAll();
69 #if !defined(OS_IOS)
70 // If any child processes are still running, terminate them and
71 // and delete the BrowserChildProcessHost instances to release whatever
72 // IO thread only resources they are referencing.
73 BrowserChildProcessHostImpl::TerminateAll();
74 #endif // !defined(OS_IOS)
76 // Unregister GpuMemoryBuffer dump provider before IO thread is shut down.
77 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
78 BrowserGpuMemoryBufferManager::current());
81 } // namespace content