OLD | NEW |
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/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 #if defined(USE_AURA) | 232 #if defined(USE_AURA) |
233 bool ShouldInitializeBrowserGpuChannelAndTransportSurface() { | 233 bool ShouldInitializeBrowserGpuChannelAndTransportSurface() { |
234 return true; | 234 return true; |
235 } | 235 } |
236 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 236 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
237 bool ShouldInitializeBrowserGpuChannelAndTransportSurface() { | 237 bool ShouldInitializeBrowserGpuChannelAndTransportSurface() { |
238 return IsDelegatedRendererEnabled(); | 238 return IsDelegatedRendererEnabled(); |
239 } | 239 } |
240 #endif | 240 #endif |
241 | 241 |
| 242 // Disable optimizations for this block of functions so the compiler doesn't |
| 243 // merge them all together. This makes it possible to tell what thread was |
| 244 // unresponsive by inspecting the callstack. |
| 245 MSVC_DISABLE_OPTIMIZE() |
| 246 MSVC_PUSH_DISABLE_WARNING(4748) |
| 247 |
| 248 NOINLINE void ResetThread_DB(scoped_ptr<BrowserProcessSubThread> thread) { |
| 249 thread.reset(); |
| 250 } |
| 251 |
| 252 NOINLINE void ResetThread_FILE(scoped_ptr<BrowserProcessSubThread> thread) { |
| 253 thread.reset(); |
| 254 } |
| 255 |
| 256 NOINLINE void ResetThread_FILE_USER_BLOCKING( |
| 257 scoped_ptr<BrowserProcessSubThread> thread) { |
| 258 thread.reset(); |
| 259 } |
| 260 |
| 261 NOINLINE void ResetThread_PROCESS_LAUNCHER( |
| 262 scoped_ptr<BrowserProcessSubThread> thread) { |
| 263 thread.reset(); |
| 264 } |
| 265 |
| 266 NOINLINE void ResetThread_CACHE(scoped_ptr<BrowserProcessSubThread> thread) { |
| 267 thread.reset(); |
| 268 } |
| 269 |
| 270 NOINLINE void ResetThread_IO(scoped_ptr<BrowserProcessSubThread> thread) { |
| 271 thread.reset(); |
| 272 } |
| 273 |
| 274 #if !defined(OS_IOS) |
| 275 NOINLINE void ResetThread_IndexedDb(scoped_ptr<base::Thread> thread) { |
| 276 thread.reset(); |
| 277 } |
| 278 #endif |
| 279 |
| 280 MSVC_POP_WARNING() |
| 281 MSVC_ENABLE_OPTIMIZE(); |
| 282 |
242 } // namespace | 283 } // namespace |
243 | 284 |
244 // The currently-running BrowserMainLoop. There can be one or zero. | 285 // The currently-running BrowserMainLoop. There can be one or zero. |
245 BrowserMainLoop* g_current_browser_main_loop = NULL; | 286 BrowserMainLoop* g_current_browser_main_loop = NULL; |
246 | 287 |
247 // This is just to be able to keep ShutdownThreadsAndCleanUp out of | 288 // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
248 // the public interface of BrowserMainLoop. | 289 // the public interface of BrowserMainLoop. |
249 class BrowserShutdownImpl { | 290 class BrowserShutdownImpl { |
250 public: | 291 public: |
251 static void ImmediateShutdownAndExitProcess() { | 292 static void ImmediateShutdownAndExitProcess() { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 // | 841 // |
801 // - The IO thread is the only user of the CACHE thread. | 842 // - The IO thread is the only user of the CACHE thread. |
802 // | 843 // |
803 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | 844 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
804 // the IO thread posted a task to terminate a process on the | 845 // the IO thread posted a task to terminate a process on the |
805 // process launcher thread. | 846 // process launcher thread. |
806 // | 847 // |
807 // - (Not sure why DB stops last.) | 848 // - (Not sure why DB stops last.) |
808 switch (thread_id) { | 849 switch (thread_id) { |
809 case BrowserThread::DB: { | 850 case BrowserThread::DB: { |
810 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); | 851 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); |
811 db_thread_.reset(); | 852 ResetThread_DB(db_thread_.Pass()); |
812 } | |
813 break; | 853 break; |
| 854 } |
| 855 case BrowserThread::FILE: { |
| 856 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); |
| 857 #if !defined(OS_IOS) |
| 858 // Clean up state that lives on or uses the file_thread_ before |
| 859 // it goes away. |
| 860 if (resource_dispatcher_host_) |
| 861 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); |
| 862 #endif // !defined(OS_IOS) |
| 863 ResetThread_FILE(file_thread_.Pass()); |
| 864 break; |
| 865 } |
814 case BrowserThread::FILE_USER_BLOCKING: { | 866 case BrowserThread::FILE_USER_BLOCKING: { |
815 TRACE_EVENT0("shutdown", | 867 TRACE_EVENT0("shutdown", |
816 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); | 868 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); |
817 file_user_blocking_thread_.reset(); | 869 ResetThread_FILE_USER_BLOCKING(file_user_blocking_thread_.Pass()); |
818 } | |
819 break; | 870 break; |
820 case BrowserThread::FILE: { | 871 } |
821 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); | 872 case BrowserThread::PROCESS_LAUNCHER: { |
822 #if !defined(OS_IOS) | 873 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); |
823 // Clean up state that lives on or uses the file_thread_ before | 874 ResetThread_PROCESS_LAUNCHER(process_launcher_thread_.Pass()); |
824 // it goes away. | |
825 if (resource_dispatcher_host_) | |
826 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); | |
827 #endif // !defined(OS_IOS) | |
828 file_thread_.reset(); | |
829 } | |
830 break; | 875 break; |
831 case BrowserThread::PROCESS_LAUNCHER: { | 876 } |
832 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); | 877 case BrowserThread::CACHE: { |
833 process_launcher_thread_.reset(); | 878 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); |
834 } | 879 ResetThread_CACHE(cache_thread_.Pass()); |
835 break; | 880 break; |
836 case BrowserThread::CACHE: { | 881 } |
837 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); | 882 case BrowserThread::IO: { |
838 cache_thread_.reset(); | 883 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); |
839 } | 884 ResetThread_IO(io_thread_.Pass()); |
840 break; | 885 break; |
841 case BrowserThread::IO: { | 886 } |
842 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); | |
843 io_thread_.reset(); | |
844 } | |
845 break; | |
846 case BrowserThread::UI: | 887 case BrowserThread::UI: |
847 case BrowserThread::ID_COUNT: | 888 case BrowserThread::ID_COUNT: |
848 default: | 889 default: |
849 NOTREACHED(); | 890 NOTREACHED(); |
850 break; | 891 break; |
851 } | 892 } |
852 } | 893 } |
853 | 894 |
854 #if !defined(OS_IOS) | 895 #if !defined(OS_IOS) |
855 { | 896 { |
856 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); | 897 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); |
857 indexed_db_thread_.reset(); | 898 ResetThread_IndexedDb(indexed_db_thread_.Pass()); |
858 } | 899 } |
859 #endif | 900 #endif |
860 | 901 |
861 // Close the blocking I/O pool after the other threads. Other threads such | 902 // Close the blocking I/O pool after the other threads. Other threads such |
862 // as the I/O thread may need to schedule work like closing files or flushing | 903 // as the I/O thread may need to schedule work like closing files or flushing |
863 // data during shutdown, so the blocking pool needs to be available. There | 904 // data during shutdown, so the blocking pool needs to be available. There |
864 // may also be slow operations pending that will blcok shutdown, so closing | 905 // may also be slow operations pending that will blcok shutdown, so closing |
865 // it here (which will block until required operations are complete) gives | 906 // it here (which will block until required operations are complete) gives |
866 // more head start for those operations to finish. | 907 // more head start for those operations to finish. |
867 { | 908 { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 &BrowserMainLoop::EndStartupTracing); | 1197 &BrowserMainLoop::EndStartupTracing); |
1157 } | 1198 } |
1158 | 1199 |
1159 void BrowserMainLoop::EndStartupTracing() { | 1200 void BrowserMainLoop::EndStartupTracing() { |
1160 is_tracing_startup_ = false; | 1201 is_tracing_startup_ = false; |
1161 TracingController::GetInstance()->DisableRecording( | 1202 TracingController::GetInstance()->DisableRecording( |
1162 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); | 1203 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); |
1163 } | 1204 } |
1164 | 1205 |
1165 } // namespace content | 1206 } // namespace content |
OLD | NEW |