Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/app/chrome_main_delegate.cc

Issue 2487783002: Make Crashpad use the user data dir, rather than always default location (Closed)
Patch Set: thunk Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) 352 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
353 353
354 #endif // OS_POSIX 354 #endif // OS_POSIX
355 355
356 struct MainFunction { 356 struct MainFunction {
357 const char* name; 357 const char* name;
358 int (*function)(const content::MainFunctionParams&); 358 int (*function)(const content::MainFunctionParams&);
359 }; 359 };
360 360
361 // Initializes the user data dir. Must be called before InitializeLocalState(). 361 // Initializes the user data dir. Must be called before InitializeLocalState().
362 void InitializeUserDataDir() { 362 void InitializeUserDataDir(base::CommandLine* command_line) {
363 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 363 #if defined(OS_WIN)
364 wchar_t user_data_dir_buf[MAX_PATH], invalid_user_data_dir_buf[MAX_PATH];
365
366 using GetUserDataDirectoryThunkFunction =
367 void (*)(wchar_t*, size_t, wchar_t*, size_t);
368 HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName);
369 CHECK(elf_module);
370 GetUserDataDirectoryThunkFunction get_user_data_directory_thunk =
371 reinterpret_cast<GetUserDataDirectoryThunkFunction>(
372 GetProcAddress(elf_module, "GetUserDataDirectoryThunk"));
373 get_user_data_directory_thunk(user_data_dir_buf, arraysize(user_data_dir_buf),
374 invalid_user_data_dir_buf,
375 arraysize(invalid_user_data_dir_buf));
376 base::FilePath user_data_dir(user_data_dir_buf);
377 if (invalid_user_data_dir_buf[0] != 0) {
378 chrome::SetInvalidSpecifiedUserDataDir(
379 base::FilePath(invalid_user_data_dir_buf));
380 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
381 }
382 CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
383 user_data_dir, false, true));
384 #else // OS_WIN
364 base::FilePath user_data_dir = 385 base::FilePath user_data_dir =
365 command_line->GetSwitchValuePath(switches::kUserDataDir); 386 command_line->GetSwitchValuePath(switches::kUserDataDir);
366 std::string process_type = 387 std::string process_type =
367 command_line->GetSwitchValueASCII(switches::kProcessType); 388 command_line->GetSwitchValueASCII(switches::kProcessType);
368 389
369 #if defined(OS_LINUX) 390 #if defined(OS_LINUX)
370 // On Linux, Chrome does not support running multiple copies under different 391 // On Linux, Chrome does not support running multiple copies under different
371 // DISPLAYs, so the profile directory can be specified in the environment to 392 // DISPLAYs, so the profile directory can be specified in the environment to
372 // support the virtual desktop use-case. 393 // support the virtual desktop use-case.
373 if (user_data_dir.empty()) { 394 if (user_data_dir.empty()) {
374 std::string user_data_dir_string; 395 std::string user_data_dir_string;
375 std::unique_ptr<base::Environment> environment(base::Environment::Create()); 396 std::unique_ptr<base::Environment> environment(base::Environment::Create());
376 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && 397 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
377 base::IsStringUTF8(user_data_dir_string)) { 398 base::IsStringUTF8(user_data_dir_string)) {
378 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); 399 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
379 } 400 }
380 } 401 }
381 #endif 402 #endif // OS_LINUX
382 #if defined(OS_MACOSX) || defined(OS_WIN) 403 #if defined(OS_MACOSX)
383 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); 404 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
384 #endif 405 #endif // OS_MAC
385
386 // On Windows, trailing separators leave Chrome in a bad state.
387 // See crbug.com/464616.
388 if (user_data_dir.EndsWithSeparator())
389 user_data_dir = user_data_dir.StripTrailingSeparators();
390 406
391 const bool specified_directory_was_invalid = !user_data_dir.empty() && 407 const bool specified_directory_was_invalid = !user_data_dir.empty() &&
392 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, 408 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
393 user_data_dir, false, true); 409 user_data_dir, false, true);
394 // Save inaccessible or invalid paths so the user may be prompted later. 410 // Save inaccessible or invalid paths so the user may be prompted later.
395 if (specified_directory_was_invalid) 411 if (specified_directory_was_invalid)
396 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir); 412 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
397 413
398 // Warn and fail early if the process fails to get a user data directory. 414 // Warn and fail early if the process fails to get a user data directory.
399 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { 415 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
(...skipping 12 matching lines...) Expand all
412 // The browser process (which is identified by an empty |process_type|) will 428 // The browser process (which is identified by an empty |process_type|) will
413 // handle the error later; other processes that need the dir crash here. 429 // handle the error later; other processes that need the dir crash here.
414 CHECK(process_type.empty()) << "Unable to get the user data directory " 430 CHECK(process_type.empty()) << "Unable to get the user data directory "
415 << "for process type: " << process_type; 431 << "for process type: " << process_type;
416 } 432 }
417 433
418 // Append the fallback user data directory to the commandline. Otherwise, 434 // Append the fallback user data directory to the commandline. Otherwise,
419 // child or service processes will attempt to use the invalid directory. 435 // child or service processes will attempt to use the invalid directory.
420 if (specified_directory_was_invalid) 436 if (specified_directory_was_invalid)
421 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 437 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
438 #endif // OS_WIN
422 } 439 }
423 440
424 #if !defined(OS_ANDROID) 441 #if !defined(OS_ANDROID)
425 void InitLogging(const std::string& process_type) { 442 void InitLogging(const std::string& process_type) {
426 logging::OldFileDeletionState file_state = 443 logging::OldFileDeletionState file_state =
427 logging::APPEND_TO_OLD_LOG_FILE; 444 logging::APPEND_TO_OLD_LOG_FILE;
428 if (process_type.empty()) { 445 if (process_type.empty()) {
429 file_state = logging::DELETE_OLD_LOG_FILE; 446 file_state = logging::DELETE_OLD_LOG_FILE;
430 } 447 }
431 const base::CommandLine& command_line = 448 const base::CommandLine& command_line =
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 child_process_logging::Init(); 758 child_process_logging::Init();
742 #endif 759 #endif
743 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) 760 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
744 // Create an instance of the CPU class to parse /proc/cpuinfo and cache 761 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
745 // cpu_brand info. 762 // cpu_brand info.
746 base::CPU cpu_info; 763 base::CPU cpu_info;
747 #endif 764 #endif
748 765
749 // Initialize the user data dir for any process type that needs it. 766 // Initialize the user data dir for any process type that needs it.
750 if (chrome::ProcessNeedsProfileDir(process_type)) { 767 if (chrome::ProcessNeedsProfileDir(process_type)) {
751 InitializeUserDataDir(); 768 InitializeUserDataDir(base::CommandLine::ForCurrentProcess());
752 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD) 769 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD)
753 if (downgrade::IsMSIInstall()) { 770 if (downgrade::IsMSIInstall()) {
754 downgrade::MoveUserDataForFirstRunAfterDowngrade(); 771 downgrade::MoveUserDataForFirstRunAfterDowngrade();
755 base::FilePath user_data_dir; 772 base::FilePath user_data_dir;
756 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 773 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
757 downgrade::UpdateLastVersion(user_data_dir); 774 downgrade::UpdateLastVersion(user_data_dir);
758 } 775 }
759 #endif 776 #endif
760 } 777 }
761 778
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 case version_info::Channel::CANARY: 1071 case version_info::Channel::CANARY:
1055 return true; 1072 return true;
1056 case version_info::Channel::DEV: 1073 case version_info::Channel::DEV:
1057 case version_info::Channel::BETA: 1074 case version_info::Channel::BETA:
1058 case version_info::Channel::STABLE: 1075 case version_info::Channel::STABLE:
1059 default: 1076 default:
1060 // Don't enable instrumentation. 1077 // Don't enable instrumentation.
1061 return false; 1078 return false;
1062 } 1079 }
1063 } 1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698