Chromium Code Reviews| 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 NOINLINE void ResetThread_IndexedDb(scoped_ptr<base::Thread> thread) { | |
| 275 thread.reset(); | |
| 276 } | |
| 277 | |
| 278 MSVC_POP_WARNING() | |
| 279 MSVC_ENABLE_OPTIMIZE(); | |
| 280 | |
| 242 } // namespace | 281 } // namespace |
| 243 | 282 |
| 244 // The currently-running BrowserMainLoop. There can be one or zero. | 283 // The currently-running BrowserMainLoop. There can be one or zero. |
| 245 BrowserMainLoop* g_current_browser_main_loop = NULL; | 284 BrowserMainLoop* g_current_browser_main_loop = NULL; |
| 246 | 285 |
| 247 // This is just to be able to keep ShutdownThreadsAndCleanUp out of | 286 // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
| 248 // the public interface of BrowserMainLoop. | 287 // the public interface of BrowserMainLoop. |
| 249 class BrowserShutdownImpl { | 288 class BrowserShutdownImpl { |
| 250 public: | 289 public: |
| 251 static void ImmediateShutdownAndExitProcess() { | 290 static void ImmediateShutdownAndExitProcess() { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 // | 839 // |
| 801 // - The IO thread is the only user of the CACHE thread. | 840 // - The IO thread is the only user of the CACHE thread. |
| 802 // | 841 // |
| 803 // - The PROCESS_LAUNCHER thread must be stopped after IO in case | 842 // - The PROCESS_LAUNCHER thread must be stopped after IO in case |
| 804 // the IO thread posted a task to terminate a process on the | 843 // the IO thread posted a task to terminate a process on the |
| 805 // process launcher thread. | 844 // process launcher thread. |
| 806 // | 845 // |
| 807 // - (Not sure why DB stops last.) | 846 // - (Not sure why DB stops last.) |
| 808 switch (thread_id) { | 847 switch (thread_id) { |
| 809 case BrowserThread::DB: { | 848 case BrowserThread::DB: { |
| 810 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); | 849 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:DBThread"); |
|
sky
2014/08/15 04:48:01
nit: spacing is off in all these case statements,
rvargas (doing something else)
2014/08/15 18:01:26
Done.
| |
| 811 db_thread_.reset(); | 850 ResetThread_DB(db_thread_.Pass()); |
| 812 } | |
| 813 break; | |
| 814 case BrowserThread::FILE_USER_BLOCKING: { | |
| 815 TRACE_EVENT0("shutdown", | |
| 816 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); | |
| 817 file_user_blocking_thread_.reset(); | |
| 818 } | 851 } |
| 819 break; | 852 break; |
| 820 case BrowserThread::FILE: { | 853 case BrowserThread::FILE: { |
| 821 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); | 854 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:FileThread"); |
| 822 #if !defined(OS_IOS) | 855 #if !defined(OS_IOS) |
| 823 // Clean up state that lives on or uses the file_thread_ before | 856 // Clean up state that lives on or uses the file_thread_ before |
| 824 // it goes away. | 857 // it goes away. |
| 825 if (resource_dispatcher_host_) | 858 if (resource_dispatcher_host_) |
| 826 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); | 859 resource_dispatcher_host_.get()->save_file_manager()->Shutdown(); |
| 827 #endif // !defined(OS_IOS) | 860 #endif // !defined(OS_IOS) |
| 828 file_thread_.reset(); | 861 ResetThread_FILE(file_thread_.Pass()); |
| 862 } | |
| 863 break; | |
| 864 case BrowserThread::FILE_USER_BLOCKING: { | |
| 865 TRACE_EVENT0("shutdown", | |
| 866 "BrowserMainLoop::Subsystem:FileUserBlockingThread"); | |
| 867 ResetThread_FILE_USER_BLOCKING(file_user_blocking_thread_.Pass()); | |
| 829 } | 868 } |
| 830 break; | 869 break; |
| 831 case BrowserThread::PROCESS_LAUNCHER: { | 870 case BrowserThread::PROCESS_LAUNCHER: { |
| 832 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); | 871 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread"); |
| 833 process_launcher_thread_.reset(); | 872 ResetThread_PROCESS_LAUNCHER(process_launcher_thread_.Pass()); |
| 834 } | 873 } |
| 835 break; | 874 break; |
| 836 case BrowserThread::CACHE: { | 875 case BrowserThread::CACHE: { |
| 837 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); | 876 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:CacheThread"); |
| 838 cache_thread_.reset(); | 877 ResetThread_CACHE(cache_thread_.Pass()); |
| 839 } | 878 } |
| 840 break; | 879 break; |
| 841 case BrowserThread::IO: { | 880 case BrowserThread::IO: { |
| 842 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); | 881 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread"); |
| 843 io_thread_.reset(); | 882 ResetThread_IO(io_thread_.Pass()); |
| 844 } | 883 } |
| 845 break; | 884 break; |
| 846 case BrowserThread::UI: | 885 case BrowserThread::UI: |
| 847 case BrowserThread::ID_COUNT: | 886 case BrowserThread::ID_COUNT: |
| 848 default: | 887 default: |
| 849 NOTREACHED(); | 888 NOTREACHED(); |
| 850 break; | 889 break; |
| 851 } | 890 } |
| 852 } | 891 } |
| 853 | 892 |
| 854 #if !defined(OS_IOS) | 893 #if !defined(OS_IOS) |
| 855 { | 894 { |
| 856 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); | 895 TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IndexedDBThread"); |
| 857 indexed_db_thread_.reset(); | 896 ResetThread_IndexedDb(indexed_db_thread_.Pass()); |
| 858 } | 897 } |
| 859 #endif | 898 #endif |
| 860 | 899 |
| 861 // Close the blocking I/O pool after the other threads. Other threads such | 900 // 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 | 901 // 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 | 902 // 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 | 903 // may also be slow operations pending that will blcok shutdown, so closing |
| 865 // it here (which will block until required operations are complete) gives | 904 // it here (which will block until required operations are complete) gives |
| 866 // more head start for those operations to finish. | 905 // more head start for those operations to finish. |
| 867 { | 906 { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 &BrowserMainLoop::EndStartupTracing); | 1195 &BrowserMainLoop::EndStartupTracing); |
| 1157 } | 1196 } |
| 1158 | 1197 |
| 1159 void BrowserMainLoop::EndStartupTracing() { | 1198 void BrowserMainLoop::EndStartupTracing() { |
| 1160 is_tracing_startup_ = false; | 1199 is_tracing_startup_ = false; |
| 1161 TracingController::GetInstance()->DisableRecording( | 1200 TracingController::GetInstance()->DisableRecording( |
| 1162 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); | 1201 startup_trace_file_, base::Bind(&OnStoppedStartupTracing)); |
| 1163 } | 1202 } |
| 1164 | 1203 |
| 1165 } // namespace content | 1204 } // namespace content |
| OLD | NEW |