| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "sandbox/src/sandbox.h" | 8 #include "sandbox/src/sandbox.h" |
| 9 | 9 |
| 10 // TODO(port): several win-only methods have been pulled out of this, but | 10 // TODO(port): several win-only methods have been pulled out of this, but |
| 11 // BrowserMain() as a whole needs to be broken apart so that it's usable by | 11 // BrowserMain() as a whole needs to be broken apart so that it's usable by |
| 12 // other platforms. For now, it's just a stub. This is a serious work in | 12 // other platforms. For now, it's just a stub. This is a serious work in |
| 13 // progress and should not be taken as an indication of a real refactoring. | 13 // progress and should not be taken as an indication of a real refactoring. |
| 14 | 14 |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 | 16 |
| 17 #include <windows.h> | 17 #include <windows.h> |
| 18 #include <shellapi.h> | 18 #include <shellapi.h> |
| 19 | 19 |
| 20 #include <algorithm> | 20 #include <algorithm> |
| 21 | 21 |
| 22 #include "base/file_util.h" | 22 #include "base/file_util.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // Main routine for running as the Browser process. | 143 // Main routine for running as the Browser process. |
| 144 int BrowserMain(CommandLine &parsed_command_line, | 144 int BrowserMain(CommandLine &parsed_command_line, |
| 145 sandbox::BrokerServices* broker_services) { | 145 sandbox::BrokerServices* broker_services) { |
| 146 // WARNING: If we get a WM_ENDSESSION objects created on the stack here | 146 // WARNING: If we get a WM_ENDSESSION objects created on the stack here |
| 147 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 147 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
| 148 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 148 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
| 149 | 149 |
| 150 // TODO(beng, brettw): someday, break this out into sub functions with well | 150 // TODO(beng, brettw): someday, break this out into sub functions with well |
| 151 // defined roles (e.g. pre/post-profile startup, etc). | 151 // defined roles (e.g. pre/post-profile startup, etc). |
| 152 | 152 |
| 153 #ifdef TRACK_ALL_TASK_OBJECTS |
| 154 // Start tracking the creation and deletion of Task instance. |
| 155 // This construction MUST be done before main_message_loop, so that it is |
| 156 // destroyed after the main_message_loop. |
| 157 tracked_objects::AutoTracking tracking_objects; |
| 158 #endif |
| 159 |
| 153 MessageLoop main_message_loop(MessageLoop::TYPE_UI); | 160 MessageLoop main_message_loop(MessageLoop::TYPE_UI); |
| 154 | 161 |
| 155 // Initialize the SystemMonitor | 162 // Initialize the SystemMonitor |
| 156 base::SystemMonitor::Start(); | 163 base::SystemMonitor::Start(); |
| 157 | 164 |
| 158 // Initialize statistical testing infrastructure. | 165 // Initialize statistical testing infrastructure. |
| 159 FieldTrialList field_trial; | 166 FieldTrialList field_trial; |
| 160 | 167 |
| 161 std::wstring app_name = chrome::kBrowserAppName; | 168 std::wstring app_name = chrome::kBrowserAppName; |
| 162 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); | 169 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ResourceBundle::GetSharedInstance().LoadThemeResources(); | 264 ResourceBundle::GetSharedInstance().LoadThemeResources(); |
| 258 | 265 |
| 259 if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) { | 266 if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) { |
| 260 // Display a warning if the user is running windows 2000. | 267 // Display a warning if the user is running windows 2000. |
| 261 CheckForWin2000(); | 268 CheckForWin2000(); |
| 262 } | 269 } |
| 263 | 270 |
| 264 // Initialize histogram statistics gathering system. | 271 // Initialize histogram statistics gathering system. |
| 265 StatisticsRecorder statistics; | 272 StatisticsRecorder statistics; |
| 266 | 273 |
| 267 // Start tracking the creation and deletion of Task instances | |
| 268 bool tracking_objects = false; | |
| 269 #ifdef TRACK_ALL_TASK_OBJECTS | |
| 270 tracking_objects = tracked_objects::ThreadData::StartTracking(true); | |
| 271 #endif | |
| 272 | |
| 273 // Initialize the shared instance of user data manager. | 274 // Initialize the shared instance of user data manager. |
| 274 UserDataManager::Create(); | 275 UserDataManager::Create(); |
| 275 | 276 |
| 276 // Try to create/load the profile. | 277 // Try to create/load the profile. |
| 277 ProfileManager* profile_manager = browser_process->profile_manager(); | 278 ProfileManager* profile_manager = browser_process->profile_manager(); |
| 278 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); | 279 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 279 if (!profile) { | 280 if (!profile) { |
| 280 user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir); | 281 user_data_dir = UserDataDirDialog::RunUserDataDirDialog(user_data_dir); |
| 281 // Flush the message loop which lets the UserDataDirDialog close. | 282 // Flush the message loop which lets the UserDataDirDialog close. |
| 282 MessageLoop::current()->Run(); | 283 MessageLoop::current()->Run(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 true, profile, &result_code)) { | 481 true, profile, &result_code)) { |
| 481 MessageLoopForUI::current()->Run(browser_process->accelerator_handler()); | 482 MessageLoopForUI::current()->Run(browser_process->accelerator_handler()); |
| 482 } | 483 } |
| 483 | 484 |
| 484 if (metrics) | 485 if (metrics) |
| 485 metrics->Stop(); | 486 metrics->Stop(); |
| 486 | 487 |
| 487 // browser_shutdown takes care of deleting browser_process, so we need to | 488 // browser_shutdown takes care of deleting browser_process, so we need to |
| 488 // release it. | 489 // release it. |
| 489 browser_process.release(); | 490 browser_process.release(); |
| 490 | |
| 491 browser_shutdown::Shutdown(); | 491 browser_shutdown::Shutdown(); |
| 492 | 492 |
| 493 // The following teardown code will pacify Purify, but is not necessary for | |
| 494 // shutdown. Only list methods here that have no significant side effects | |
| 495 // and can be run in single threaded mode before terminating. | |
| 496 #ifndef NDEBUG // Don't call these in a Release build: they just waste time. | |
| 497 // The following should ONLY be called when in single threaded mode. It is | |
| 498 // unsafe to do this cleanup if other threads are still active. | |
| 499 // It is also very unnecessary, so I'm only doing this in debug to satisfy | |
| 500 // purify. | |
| 501 if (tracking_objects) | |
| 502 tracked_objects::ThreadData::ShutdownSingleThreadedCleanup(); | |
| 503 #endif // NDEBUG | |
| 504 | |
| 505 return result_code; | 493 return result_code; |
| 506 } | 494 } |
| 507 | 495 |
| 508 #elif defined(OS_POSIX) | 496 #elif defined(OS_POSIX) |
| 509 | 497 |
| 510 // Call to kick off the main message loop. The implementation for this on Mac | 498 // Call to kick off the main message loop. The implementation for this on Mac |
| 511 // must reside in another file because it has to call Cocoa functions and thus | 499 // must reside in another file because it has to call Cocoa functions and thus |
| 512 // cannot live in a .cc file. | 500 // cannot live in a .cc file. |
| 513 int StartPlatformMessageLoop(); | 501 int StartPlatformMessageLoop(); |
| 514 | 502 |
| 515 // TODO(port): merge this with above. Just a stub for now, not meant as a place | 503 // TODO(port): merge this with above. Just a stub for now, not meant as a place |
| 516 // to duplicate code. | 504 // to duplicate code. |
| 517 // Main routine for running as the Browser process. | 505 // Main routine for running as the Browser process. |
| 518 int BrowserMain(CommandLine &parsed_command_line, | 506 int BrowserMain(CommandLine &parsed_command_line, |
| 519 sandbox::BrokerServices* broker_services) { | 507 sandbox::BrokerServices* broker_services) { |
| 520 return StartPlatformMessageLoop(); | 508 return StartPlatformMessageLoop(); |
| 521 } | 509 } |
| 522 | 510 |
| 523 #if defined(OS_LINUX) | 511 #if defined(OS_LINUX) |
| 524 void StartPlatformMessageLoop() { | 512 void StartPlatformMessageLoop() { |
| 525 return 0; | 513 return 0; |
| 526 } | 514 } |
| 527 #endif | 515 #endif |
| 528 | 516 |
| 529 #endif | 517 #endif |
| OLD | NEW |