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

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

Issue 2549593002: Revert of Make Crashpad use the user data dir, rather than always default location (Closed)
Patch Set: Created 4 years 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(base::CommandLine* command_line) { 363 void InitializeUserDataDir() {
364 #if defined(OS_WIN) 364 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
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
396 base::FilePath user_data_dir = 365 base::FilePath user_data_dir =
397 command_line->GetSwitchValuePath(switches::kUserDataDir); 366 command_line->GetSwitchValuePath(switches::kUserDataDir);
398 std::string process_type = 367 std::string process_type =
399 command_line->GetSwitchValueASCII(switches::kProcessType); 368 command_line->GetSwitchValueASCII(switches::kProcessType);
400 369
401 #if defined(OS_LINUX) 370 #if defined(OS_LINUX)
402 // On Linux, Chrome does not support running multiple copies under different 371 // On Linux, Chrome does not support running multiple copies under different
403 // DISPLAYs, so the profile directory can be specified in the environment to 372 // DISPLAYs, so the profile directory can be specified in the environment to
404 // support the virtual desktop use-case. 373 // support the virtual desktop use-case.
405 if (user_data_dir.empty()) { 374 if (user_data_dir.empty()) {
406 std::string user_data_dir_string; 375 std::string user_data_dir_string;
407 std::unique_ptr<base::Environment> environment(base::Environment::Create()); 376 std::unique_ptr<base::Environment> environment(base::Environment::Create());
408 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && 377 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
409 base::IsStringUTF8(user_data_dir_string)) { 378 base::IsStringUTF8(user_data_dir_string)) {
410 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); 379 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
411 } 380 }
412 } 381 }
413 #endif // OS_LINUX 382 #endif
414 #if defined(OS_MACOSX) 383 #if defined(OS_MACOSX) || defined(OS_WIN)
415 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); 384 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
416 #endif // OS_MAC 385 #endif
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();
417 391
418 const bool specified_directory_was_invalid = !user_data_dir.empty() && 392 const bool specified_directory_was_invalid = !user_data_dir.empty() &&
419 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, 393 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
420 user_data_dir, false, true); 394 user_data_dir, false, true);
421 // Save inaccessible or invalid paths so the user may be prompted later. 395 // Save inaccessible or invalid paths so the user may be prompted later.
422 if (specified_directory_was_invalid) 396 if (specified_directory_was_invalid)
423 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir); 397 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
424 398
425 // Warn and fail early if the process fails to get a user data directory. 399 // Warn and fail early if the process fails to get a user data directory.
426 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { 400 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
(...skipping 12 matching lines...) Expand all
439 // The browser process (which is identified by an empty |process_type|) will 413 // The browser process (which is identified by an empty |process_type|) will
440 // handle the error later; other processes that need the dir crash here. 414 // handle the error later; other processes that need the dir crash here.
441 CHECK(process_type.empty()) << "Unable to get the user data directory " 415 CHECK(process_type.empty()) << "Unable to get the user data directory "
442 << "for process type: " << process_type; 416 << "for process type: " << process_type;
443 } 417 }
444 418
445 // Append the fallback user data directory to the commandline. Otherwise, 419 // Append the fallback user data directory to the commandline. Otherwise,
446 // child or service processes will attempt to use the invalid directory. 420 // child or service processes will attempt to use the invalid directory.
447 if (specified_directory_was_invalid) 421 if (specified_directory_was_invalid)
448 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 422 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
449 #endif // OS_WIN
450 } 423 }
451 424
452 #if !defined(OS_ANDROID) 425 #if !defined(OS_ANDROID)
453 void InitLogging(const std::string& process_type) { 426 void InitLogging(const std::string& process_type) {
454 logging::OldFileDeletionState file_state = 427 logging::OldFileDeletionState file_state =
455 logging::APPEND_TO_OLD_LOG_FILE; 428 logging::APPEND_TO_OLD_LOG_FILE;
456 if (process_type.empty()) { 429 if (process_type.empty()) {
457 file_state = logging::DELETE_OLD_LOG_FILE; 430 file_state = logging::DELETE_OLD_LOG_FILE;
458 } 431 }
459 const base::CommandLine& command_line = 432 const base::CommandLine& command_line =
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 child_process_logging::Init(); 742 child_process_logging::Init();
770 #endif 743 #endif
771 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) 744 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
772 // Create an instance of the CPU class to parse /proc/cpuinfo and cache 745 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
773 // cpu_brand info. 746 // cpu_brand info.
774 base::CPU cpu_info; 747 base::CPU cpu_info;
775 #endif 748 #endif
776 749
777 // Initialize the user data dir for any process type that needs it. 750 // Initialize the user data dir for any process type that needs it.
778 if (chrome::ProcessNeedsProfileDir(process_type)) { 751 if (chrome::ProcessNeedsProfileDir(process_type)) {
779 InitializeUserDataDir(base::CommandLine::ForCurrentProcess()); 752 InitializeUserDataDir();
780 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD) 753 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD)
781 if (downgrade::IsMSIInstall()) { 754 if (downgrade::IsMSIInstall()) {
782 downgrade::MoveUserDataForFirstRunAfterDowngrade(); 755 downgrade::MoveUserDataForFirstRunAfterDowngrade();
783 base::FilePath user_data_dir; 756 base::FilePath user_data_dir;
784 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 757 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
785 downgrade::UpdateLastVersion(user_data_dir); 758 downgrade::UpdateLastVersion(user_data_dir);
786 } 759 }
787 #endif 760 #endif
788 } 761 }
789 762
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 case version_info::Channel::CANARY: 1055 case version_info::Channel::CANARY:
1083 return true; 1056 return true;
1084 case version_info::Channel::DEV: 1057 case version_info::Channel::DEV:
1085 case version_info::Channel::BETA: 1058 case version_info::Channel::BETA:
1086 case version_info::Channel::STABLE: 1059 case version_info::Channel::STABLE:
1087 default: 1060 default:
1088 // Don't enable instrumentation. 1061 // Don't enable instrumentation.
1089 return false; 1062 return false;
1090 } 1063 }
1091 } 1064 }
OLDNEW
« no previous file with comments | « chrome/app/chrome_crash_reporter_client_win.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698