| 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 "chrome/app/chrome_main_delegate.h" | 5 #include "chrome/app/chrome_main_delegate.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) | 353 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 354 | 354 |
| 355 #endif // OS_POSIX | 355 #endif // OS_POSIX |
| 356 | 356 |
| 357 struct MainFunction { | 357 struct MainFunction { |
| 358 const char* name; | 358 const char* name; |
| 359 int (*function)(const content::MainFunctionParams&); | 359 int (*function)(const content::MainFunctionParams&); |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 // Initializes the user data dir. Must be called before InitializeLocalState(). | 362 // Initializes the user data dir. Must be called before InitializeLocalState(). |
| 363 void InitializeUserDataDir() { | 363 void InitializeUserDataDir(base::CommandLine* command_line) { |
| 364 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 364 #if defined(OS_WIN) |
| 365 wchar_t user_data_dir_buf[MAX_PATH], invalid_user_data_dir_buf[MAX_PATH]; |
| 366 |
| 367 using GetUserDataDirectoryThunkFunction = |
| 368 void (*)(wchar_t*, size_t, wchar_t*, size_t); |
| 369 HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName); |
| 370 if (elf_module) { |
| 371 // If we're in a test, chrome_elf won't be loaded. |
| 372 GetUserDataDirectoryThunkFunction get_user_data_directory_thunk = |
| 373 reinterpret_cast<GetUserDataDirectoryThunkFunction>( |
| 374 GetProcAddress(elf_module, "GetUserDataDirectoryThunk")); |
| 375 get_user_data_directory_thunk( |
| 376 user_data_dir_buf, arraysize(user_data_dir_buf), |
| 377 invalid_user_data_dir_buf, arraysize(invalid_user_data_dir_buf)); |
| 378 base::FilePath user_data_dir(user_data_dir_buf); |
| 379 if (invalid_user_data_dir_buf[0] != 0) { |
| 380 chrome::SetInvalidSpecifiedUserDataDir( |
| 381 base::FilePath(invalid_user_data_dir_buf)); |
| 382 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 383 } |
| 384 CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, |
| 385 user_data_dir, false, true)); |
| 386 } else { |
| 387 // In tests, just respect the flag if given. |
| 388 base::FilePath user_data_dir = |
| 389 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 390 if (user_data_dir.EndsWithSeparator()) |
| 391 user_data_dir = user_data_dir.StripTrailingSeparators(); |
| 392 CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, |
| 393 user_data_dir, false, true)); |
| 394 } |
| 395 #else // OS_WIN |
| 365 base::FilePath user_data_dir = | 396 base::FilePath user_data_dir = |
| 366 command_line->GetSwitchValuePath(switches::kUserDataDir); | 397 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 367 std::string process_type = | 398 std::string process_type = |
| 368 command_line->GetSwitchValueASCII(switches::kProcessType); | 399 command_line->GetSwitchValueASCII(switches::kProcessType); |
| 369 | 400 |
| 370 #if defined(OS_LINUX) | 401 #if defined(OS_LINUX) |
| 371 // On Linux, Chrome does not support running multiple copies under different | 402 // On Linux, Chrome does not support running multiple copies under different |
| 372 // DISPLAYs, so the profile directory can be specified in the environment to | 403 // DISPLAYs, so the profile directory can be specified in the environment to |
| 373 // support the virtual desktop use-case. | 404 // support the virtual desktop use-case. |
| 374 if (user_data_dir.empty()) { | 405 if (user_data_dir.empty()) { |
| 375 std::string user_data_dir_string; | 406 std::string user_data_dir_string; |
| 376 std::unique_ptr<base::Environment> environment(base::Environment::Create()); | 407 std::unique_ptr<base::Environment> environment(base::Environment::Create()); |
| 377 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && | 408 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && |
| 378 base::IsStringUTF8(user_data_dir_string)) { | 409 base::IsStringUTF8(user_data_dir_string)) { |
| 379 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); | 410 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); |
| 380 } | 411 } |
| 381 } | 412 } |
| 382 #endif | 413 #endif // OS_LINUX |
| 383 #if defined(OS_MACOSX) || defined(OS_WIN) | 414 #if defined(OS_MACOSX) |
| 384 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); | 415 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); |
| 385 #endif | 416 #endif // OS_MAC |
| 386 | |
| 387 // On Windows, trailing separators leave Chrome in a bad state. | |
| 388 // See crbug.com/464616. | |
| 389 if (user_data_dir.EndsWithSeparator()) | |
| 390 user_data_dir = user_data_dir.StripTrailingSeparators(); | |
| 391 | 417 |
| 392 const bool specified_directory_was_invalid = !user_data_dir.empty() && | 418 const bool specified_directory_was_invalid = !user_data_dir.empty() && |
| 393 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, | 419 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, |
| 394 user_data_dir, false, true); | 420 user_data_dir, false, true); |
| 395 // Save inaccessible or invalid paths so the user may be prompted later. | 421 // Save inaccessible or invalid paths so the user may be prompted later. |
| 396 if (specified_directory_was_invalid) | 422 if (specified_directory_was_invalid) |
| 397 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir); | 423 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir); |
| 398 | 424 |
| 399 // Warn and fail early if the process fails to get a user data directory. | 425 // Warn and fail early if the process fails to get a user data directory. |
| 400 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { | 426 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 413 // The browser process (which is identified by an empty |process_type|) will | 439 // The browser process (which is identified by an empty |process_type|) will |
| 414 // handle the error later; other processes that need the dir crash here. | 440 // handle the error later; other processes that need the dir crash here. |
| 415 CHECK(process_type.empty()) << "Unable to get the user data directory " | 441 CHECK(process_type.empty()) << "Unable to get the user data directory " |
| 416 << "for process type: " << process_type; | 442 << "for process type: " << process_type; |
| 417 } | 443 } |
| 418 | 444 |
| 419 // Append the fallback user data directory to the commandline. Otherwise, | 445 // Append the fallback user data directory to the commandline. Otherwise, |
| 420 // child or service processes will attempt to use the invalid directory. | 446 // child or service processes will attempt to use the invalid directory. |
| 421 if (specified_directory_was_invalid) | 447 if (specified_directory_was_invalid) |
| 422 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); | 448 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 449 #endif // OS_WIN |
| 423 } | 450 } |
| 424 | 451 |
| 425 #if !defined(OS_ANDROID) | 452 #if !defined(OS_ANDROID) |
| 426 void InitLogging(const std::string& process_type) { | 453 void InitLogging(const std::string& process_type) { |
| 427 logging::OldFileDeletionState file_state = | 454 logging::OldFileDeletionState file_state = |
| 428 logging::APPEND_TO_OLD_LOG_FILE; | 455 logging::APPEND_TO_OLD_LOG_FILE; |
| 429 if (process_type.empty()) { | 456 if (process_type.empty()) { |
| 430 file_state = logging::DELETE_OLD_LOG_FILE; | 457 file_state = logging::DELETE_OLD_LOG_FILE; |
| 431 } | 458 } |
| 432 const base::CommandLine& command_line = | 459 const base::CommandLine& command_line = |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 child_process_logging::Init(); | 769 child_process_logging::Init(); |
| 743 #endif | 770 #endif |
| 744 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | 771 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) |
| 745 // Create an instance of the CPU class to parse /proc/cpuinfo and cache | 772 // Create an instance of the CPU class to parse /proc/cpuinfo and cache |
| 746 // cpu_brand info. | 773 // cpu_brand info. |
| 747 base::CPU cpu_info; | 774 base::CPU cpu_info; |
| 748 #endif | 775 #endif |
| 749 | 776 |
| 750 // Initialize the user data dir for any process type that needs it. | 777 // Initialize the user data dir for any process type that needs it. |
| 751 if (chrome::ProcessNeedsProfileDir(process_type)) { | 778 if (chrome::ProcessNeedsProfileDir(process_type)) { |
| 752 InitializeUserDataDir(); | 779 InitializeUserDataDir(base::CommandLine::ForCurrentProcess()); |
| 753 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD) | 780 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 754 if (downgrade::IsMSIInstall()) { | 781 if (downgrade::IsMSIInstall()) { |
| 755 downgrade::MoveUserDataForFirstRunAfterDowngrade(); | 782 downgrade::MoveUserDataForFirstRunAfterDowngrade(); |
| 756 base::FilePath user_data_dir; | 783 base::FilePath user_data_dir; |
| 757 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | 784 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 758 downgrade::UpdateLastVersion(user_data_dir); | 785 downgrade::UpdateLastVersion(user_data_dir); |
| 759 } | 786 } |
| 760 #endif | 787 #endif |
| 761 } | 788 } |
| 762 | 789 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 case version_info::Channel::CANARY: | 1082 case version_info::Channel::CANARY: |
| 1056 return true; | 1083 return true; |
| 1057 case version_info::Channel::DEV: | 1084 case version_info::Channel::DEV: |
| 1058 case version_info::Channel::BETA: | 1085 case version_info::Channel::BETA: |
| 1059 case version_info::Channel::STABLE: | 1086 case version_info::Channel::STABLE: |
| 1060 default: | 1087 default: |
| 1061 // Don't enable instrumentation. | 1088 // Don't enable instrumentation. |
| 1062 return false; | 1089 return false; |
| 1063 } | 1090 } |
| 1064 } | 1091 } |
| OLD | NEW |