| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); | 276 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); |
| 277 | 277 |
| 278 const char* thread_name = thread_name_string.c_str(); | 278 const char* thread_name = thread_name_string.c_str(); |
| 279 PlatformThread::SetName(thread_name); | 279 PlatformThread::SetName(thread_name); |
| 280 main_message_loop.set_thread_name(thread_name); | 280 main_message_loop.set_thread_name(thread_name); |
| 281 | 281 |
| 282 // Register the main thread by instantiating it, but don't call any methods. | 282 // Register the main thread by instantiating it, but don't call any methods. |
| 283 ChromeThread main_thread; | 283 ChromeThread main_thread; |
| 284 | 284 |
| 285 FilePath user_data_dir; | 285 FilePath user_data_dir; |
| 286 #if defined(OS_WIN) |
| 286 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 287 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 288 #else |
| 289 // Getting the user data dir can fail if the directory isn't |
| 290 // creatable, for example; on Windows in code below we bring up a |
| 291 // dialog prompting the user to pick a different directory. |
| 292 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, |
| 293 // so it's better to fail here than fail mysteriously elsewhere. |
| 294 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 295 << "Must be able to get user data directory!"; |
| 296 #endif |
| 297 |
| 287 ProcessSingleton process_singleton(user_data_dir); | 298 ProcessSingleton process_singleton(user_data_dir); |
| 288 | 299 |
| 289 bool is_first_run = FirstRun::IsChromeFirstRun() || | 300 bool is_first_run = FirstRun::IsChromeFirstRun() || |
| 290 parsed_command_line.HasSwitch(switches::kFirstRun); | 301 parsed_command_line.HasSwitch(switches::kFirstRun); |
| 291 bool first_run_ui_bypass = false; | 302 bool first_run_ui_bypass = false; |
| 292 | 303 |
| 293 scoped_ptr<BrowserProcess> browser_process; | 304 scoped_ptr<BrowserProcess> browser_process; |
| 294 if (parsed_command_line.HasSwitch(switches::kImport)) { | 305 if (parsed_command_line.HasSwitch(switches::kImport)) { |
| 295 // We use different BrowserProcess when importing so no GoogleURLTracker is | 306 // We use different BrowserProcess when importing so no GoogleURLTracker is |
| 296 // instantiated (as it makes a URLRequest and we don't have an IO thread, | 307 // instantiated (as it makes a URLRequest and we don't have an IO thread, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // will not be deleted after the Task is executed. | 487 // will not be deleted after the Task is executed. |
| 477 scoped_refptr<HistogramSynchronizer> histogram_synchronizer = | 488 scoped_refptr<HistogramSynchronizer> histogram_synchronizer = |
| 478 new HistogramSynchronizer(); | 489 new HistogramSynchronizer(); |
| 479 | 490 |
| 480 // Initialize the shared instance of user data manager. | 491 // Initialize the shared instance of user data manager. |
| 481 scoped_ptr<UserDataManager> user_data_manager(UserDataManager::Create()); | 492 scoped_ptr<UserDataManager> user_data_manager(UserDataManager::Create()); |
| 482 | 493 |
| 483 // Try to create/load the profile. | 494 // Try to create/load the profile. |
| 484 ProfileManager* profile_manager = browser_process->profile_manager(); | 495 ProfileManager* profile_manager = browser_process->profile_manager(); |
| 485 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); | 496 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 497 #if defined(OS_WIN) |
| 486 if (!profile) { | 498 if (!profile) { |
| 487 // Ideally, we should be able to run w/o access to disk. For now, we | 499 // Ideally, we should be able to run w/o access to disk. For now, we |
| 488 // prompt the user to pick a different user-data-dir and restart chrome | 500 // prompt the user to pick a different user-data-dir and restart chrome |
| 489 // with the new dir. | 501 // with the new dir. |
| 490 // http://code.google.com/p/chromium/issues/detail?id=11510 | 502 // http://code.google.com/p/chromium/issues/detail?id=11510 |
| 491 #if defined(OS_WIN) | |
| 492 user_data_dir = FilePath::FromWStringHack( | 503 user_data_dir = FilePath::FromWStringHack( |
| 493 UserDataDirDialog::RunUserDataDirDialog(user_data_dir.ToWStringHack())); | 504 UserDataDirDialog::RunUserDataDirDialog(user_data_dir.ToWStringHack())); |
| 494 #elif defined(OS_LINUX) | |
| 495 // TODO(port): fix this. | |
| 496 user_data_dir = FilePath("/tmp"); | |
| 497 #endif | |
| 498 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 499 if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) { | 505 if (!parameters.ui_task && browser_shutdown::delete_resources_on_shutdown) { |
| 500 // Only delete the resources if we're not running tests. If we're running | 506 // Only delete the resources if we're not running tests. If we're running |
| 501 // tests the resources need to be reused as many places in the UI cache | 507 // tests the resources need to be reused as many places in the UI cache |
| 502 // SkBitmaps from the ResourceBundle. | 508 // SkBitmaps from the ResourceBundle. |
| 503 ResourceBundle::CleanupSharedInstance(); | 509 ResourceBundle::CleanupSharedInstance(); |
| 504 } | 510 } |
| 505 | 511 |
| 506 if (!user_data_dir.empty()) { | 512 if (!user_data_dir.empty()) { |
| 507 // Because of the way CommandLine parses, it's sufficient to append a new | 513 // Because of the way CommandLine parses, it's sufficient to append a new |
| 508 // --user-data-dir switch. The last flag of the same name wins. | 514 // --user-data-dir switch. The last flag of the same name wins. |
| 509 // TODO(tc): It would be nice to remove the flag we don't want, but that | 515 // TODO(tc): It would be nice to remove the flag we don't want, but that |
| 510 // sounds risky if we parse differently than CommandLineToArgvW. | 516 // sounds risky if we parse differently than CommandLineToArgvW. |
| 511 CommandLine new_command_line = parsed_command_line; | 517 CommandLine new_command_line = parsed_command_line; |
| 512 new_command_line.AppendSwitchWithValue(switches::kUserDataDir, | 518 new_command_line.AppendSwitchWithValue(switches::kUserDataDir, |
| 513 user_data_dir.ToWStringHack()); | 519 user_data_dir.ToWStringHack()); |
| 514 base::LaunchApp(new_command_line, false, false, NULL); | 520 base::LaunchApp(new_command_line, false, false, NULL); |
| 515 } | 521 } |
| 516 #endif // defined(OS_WIN) || defined(OS_LINUX) | |
| 517 | 522 |
| 518 return ResultCodes::NORMAL_EXIT; | 523 return ResultCodes::NORMAL_EXIT; |
| 519 } | 524 } |
| 525 #else |
| 526 // TODO(port): fix this. See comments near the definition of |
| 527 // user_data_dir. It is better to CHECK-fail here than it is to |
| 528 // silently exit because of missing code in the above test. |
| 529 CHECK(profile) << "Cannot get default profile."; |
| 530 #endif |
| 531 |
| 520 if (profile->GetBlacklist() && !profile->GetBlacklist()->is_good()) { | 532 if (profile->GetBlacklist() && !profile->GetBlacklist()->is_good()) { |
| 521 // TODO(idanan): Enable this for other platforms once the dispatching | 533 // TODO(idanan): Enable this for other platforms once the dispatching |
| 522 // support code has been ported. See ifdefs in message_loop.h. | 534 // support code has been ported. See ifdefs in message_loop.h. |
| 523 #if defined(OS_WIN) | 535 #if defined(OS_WIN) |
| 524 bool accepted = BlacklistErrorDialog::RunBlacklistErrorDialog(); | 536 bool accepted = BlacklistErrorDialog::RunBlacklistErrorDialog(); |
| 525 if (!accepted) | 537 if (!accepted) |
| 526 return ResultCodes::NORMAL_EXIT; | 538 return ResultCodes::NORMAL_EXIT; |
| 527 #else | 539 #else |
| 528 return ResultCodes::NORMAL_EXIT; | 540 return ResultCodes::NORMAL_EXIT; |
| 529 #endif | 541 #endif |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 if (metrics) | 836 if (metrics) |
| 825 metrics->Stop(); | 837 metrics->Stop(); |
| 826 | 838 |
| 827 // browser_shutdown takes care of deleting browser_process, so we need to | 839 // browser_shutdown takes care of deleting browser_process, so we need to |
| 828 // release it. | 840 // release it. |
| 829 browser_process.release(); | 841 browser_process.release(); |
| 830 browser_shutdown::Shutdown(); | 842 browser_shutdown::Shutdown(); |
| 831 | 843 |
| 832 return result_code; | 844 return result_code; |
| 833 } | 845 } |
| OLD | NEW |