OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "chrome/browser/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 #if defined(OS_POSIX) | 157 #if defined(OS_POSIX) |
158 // See comment in BrowserMain, where sigaction is called. | 158 // See comment in BrowserMain, where sigaction is called. |
159 void SIGCHLDHandler(int signal) { | 159 void SIGCHLDHandler(int signal) { |
160 } | 160 } |
161 | 161 |
162 // See comment in BrowserMain, where sigaction is called. | 162 // See comment in BrowserMain, where sigaction is called. |
163 void SIGTERMHandler(int signal) { | 163 void SIGTERMHandler(int signal) { |
164 DCHECK_EQ(signal, SIGTERM); | 164 DCHECK_EQ(signal, SIGTERM); |
165 LOG(WARNING) << "Addressing SIGTERM on " << PlatformThread::CurrentId(); | 165 LOG(WARNING) << "Addressing SIGTERM on " << PlatformThread::CurrentId(); |
166 | 166 |
167 MessageLoop* main_loop = ChromeThread::GetMessageLoop(ChromeThread::UI); | 167 bool posted = ChromeThread::PostTask( |
168 if (main_loop) { | 168 ChromeThread::UI, FROM_HERE, |
169 // Post the exit task to the main thread. | 169 NewRunnableFunction(BrowserList::CloseAllBrowsersAndExit)); |
170 main_loop->PostTask( | 170 if (posted) { |
171 FROM_HERE, NewRunnableFunction(BrowserList::CloseAllBrowsersAndExit)); | |
172 LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler"; | 171 LOG(WARNING) << "Posted task to UI thread; resetting SIGTERM handler"; |
173 } | 172 } |
174 | 173 |
175 // Reinstall the default handler. We had one shot at graceful shutdown. | 174 // Reinstall the default handler. We had one shot at graceful shutdown. |
176 struct sigaction term_action; | 175 struct sigaction term_action; |
177 memset(&term_action, 0, sizeof(term_action)); | 176 memset(&term_action, 0, sizeof(term_action)); |
178 term_action.sa_handler = SIG_DFL; | 177 term_action.sa_handler = SIG_DFL; |
179 CHECK(sigaction(SIGTERM, &term_action, NULL) == 0); | 178 CHECK(sigaction(SIGTERM, &term_action, NULL) == 0); |
180 | 179 |
181 if (!main_loop) { | 180 if (!posted) { |
182 // Without a UI thread to post the exit task to, there aren't many | 181 // Without a UI thread to post the exit task to, there aren't many |
183 // options. Raise the signal again. The default handler will pick it up | 182 // options. Raise the signal again. The default handler will pick it up |
184 // and cause an ungraceful exit. | 183 // and cause an ungraceful exit. |
185 LOG(WARNING) << "No UI thread, exiting ungracefully"; | 184 LOG(WARNING) << "No UI thread, exiting ungracefully"; |
186 kill(getpid(), signal); | 185 kill(getpid(), signal); |
187 | 186 |
188 // The signal may be handled on another thread. Give that a chance to | 187 // The signal may be handled on another thread. Give that a chance to |
189 // happen. | 188 // happen. |
190 sleep(3); | 189 sleep(3); |
191 | 190 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 FieldTrialList field_trial; | 323 FieldTrialList field_trial; |
325 | 324 |
326 std::wstring app_name = chrome::kBrowserAppName; | 325 std::wstring app_name = chrome::kBrowserAppName; |
327 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); | 326 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); |
328 | 327 |
329 const char* thread_name = thread_name_string.c_str(); | 328 const char* thread_name = thread_name_string.c_str(); |
330 PlatformThread::SetName(thread_name); | 329 PlatformThread::SetName(thread_name); |
331 main_message_loop.set_thread_name(thread_name); | 330 main_message_loop.set_thread_name(thread_name); |
332 | 331 |
333 // Register the main thread by instantiating it, but don't call any methods. | 332 // Register the main thread by instantiating it, but don't call any methods. |
334 ChromeThread main_thread; | 333 ChromeThread main_thread(ChromeThread::UI, MessageLoop::current()); |
335 | 334 |
336 FilePath user_data_dir; | 335 FilePath user_data_dir; |
337 #if defined(OS_WIN) | 336 #if defined(OS_WIN) |
338 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 337 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
339 #else | 338 #else |
340 // Getting the user data dir can fail if the directory isn't | 339 // Getting the user data dir can fail if the directory isn't |
341 // creatable, for example; on Windows in code below we bring up a | 340 // creatable, for example; on Windows in code below we bring up a |
342 // dialog prompting the user to pick a different directory. | 341 // dialog prompting the user to pick a different directory. |
343 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, | 342 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
344 // so it's better to fail here than fail mysteriously elsewhere. | 343 // so it's better to fail here than fail mysteriously elsewhere. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 PrefService* local_state = browser_process->local_state(); | 403 PrefService* local_state = browser_process->local_state(); |
405 DCHECK(local_state); | 404 DCHECK(local_state); |
406 | 405 |
407 // Initialize ResourceBundle which handles files loaded from external | 406 // Initialize ResourceBundle which handles files loaded from external |
408 // sources. This has to be done before uninstall code path and before prefs | 407 // sources. This has to be done before uninstall code path and before prefs |
409 // are registered. | 408 // are registered. |
410 local_state->RegisterStringPref(prefs::kApplicationLocale, L""); | 409 local_state->RegisterStringPref(prefs::kApplicationLocale, L""); |
411 local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, | 410 local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, |
412 GoogleUpdateSettings::GetCollectStatsConsent()); | 411 GoogleUpdateSettings::GetCollectStatsConsent()); |
413 | 412 |
413 // Start the database thread (the order doesn't really matter for it). | |
darin (slow to review)
2009/10/27 00:06:52
Q: i'm not sure what the second part means. the o
jam
2009/10/27 02:38:18
I was trying to say that we just need to start the
darin (slow to review)
2009/10/27 04:43:33
OK
| |
414 browser_process->db_thread(); | |
415 | |
414 #if defined(TOOLKIT_GTK) | 416 #if defined(TOOLKIT_GTK) |
415 // It is important for this to happen before the first run dialog, as it | 417 // It is important for this to happen before the first run dialog, as it |
416 // styles the dialog as well. | 418 // styles the dialog as well. |
417 gtk_util::InitRCStyles(); | 419 gtk_util::InitRCStyles(); |
418 #elif defined(TOOLKIT_VIEWS) | 420 #elif defined(TOOLKIT_VIEWS) |
419 // The delegate needs to be set before any UI is created so that windows | 421 // The delegate needs to be set before any UI is created so that windows |
420 // display the correct icon. | 422 // display the correct icon. |
421 if (!views::ViewsDelegate::views_delegate) | 423 if (!views::ViewsDelegate::views_delegate) |
422 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; | 424 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; |
423 #endif | 425 #endif |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 if (metrics) | 894 if (metrics) |
893 metrics->Stop(); | 895 metrics->Stop(); |
894 | 896 |
895 // browser_shutdown takes care of deleting browser_process, so we need to | 897 // browser_shutdown takes care of deleting browser_process, so we need to |
896 // release it. | 898 // release it. |
897 browser_process.release(); | 899 browser_process.release(); |
898 browser_shutdown::Shutdown(); | 900 browser_shutdown::Shutdown(); |
899 | 901 |
900 return result_code; | 902 return result_code; |
901 } | 903 } |
OLD | NEW |