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

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: . 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 23 matching lines...) Expand all
34 #include "chrome/common/chrome_result_codes.h" 34 #include "chrome/common/chrome_result_codes.h"
35 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
36 #include "chrome/common/crash_keys.h" 36 #include "chrome/common/crash_keys.h"
37 #include "chrome/common/features.h" 37 #include "chrome/common/features.h"
38 #include "chrome/common/logging_chrome.h" 38 #include "chrome/common/logging_chrome.h"
39 #include "chrome/common/profiling.h" 39 #include "chrome/common/profiling.h"
40 #include "chrome/common/switch_utils.h" 40 #include "chrome/common/switch_utils.h"
41 #include "chrome/common/trace_event_args_whitelist.h" 41 #include "chrome/common/trace_event_args_whitelist.h"
42 #include "chrome/common/url_constants.h" 42 #include "chrome/common/url_constants.h"
43 #include "chrome/gpu/chrome_content_gpu_client.h" 43 #include "chrome/gpu/chrome_content_gpu_client.h"
44 #include "chrome/install_static/install_details.h"
44 #include "chrome/renderer/chrome_content_renderer_client.h" 45 #include "chrome/renderer/chrome_content_renderer_client.h"
45 #include "chrome/utility/chrome_content_utility_client.h" 46 #include "chrome/utility/chrome_content_utility_client.h"
46 #include "components/component_updater/component_updater_paths.h" 47 #include "components/component_updater/component_updater_paths.h"
47 #include "components/content_settings/core/common/content_settings_pattern.h" 48 #include "components/content_settings/core/common/content_settings_pattern.h"
48 #include "components/crash/content/app/crash_reporter_client.h" 49 #include "components/crash/content/app/crash_reporter_client.h"
49 #include "components/version_info/version_info.h" 50 #include "components/version_info/version_info.h"
50 #include "content/public/common/content_client.h" 51 #include "content/public/common/content_client.h"
51 #include "content/public/common/content_paths.h" 52 #include "content/public/common/content_paths.h"
52 #include "content/public/common/content_switches.h" 53 #include "content/public/common/content_switches.h"
53 #include "extensions/common/constants.h" 54 #include "extensions/common/constants.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) 353 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID)
353 354
354 #endif // OS_POSIX 355 #endif // OS_POSIX
355 356
356 struct MainFunction { 357 struct MainFunction {
357 const char* name; 358 const char* name;
358 int (*function)(const content::MainFunctionParams&); 359 int (*function)(const content::MainFunctionParams&);
359 }; 360 };
360 361
361 // Initializes the user data dir. Must be called before InitializeLocalState(). 362 // Initializes the user data dir. Must be called before InitializeLocalState().
362 void InitializeUserDataDir() { 363 void InitializeUserDataDir(base::CommandLine* command_line) {
363 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 364 #if defined(OS_WIN)
365 base::FilePath user_data_dir(
366 install_static::InstallDetails::Get().user_data_dir());
367 std::wstring invalid_user_data_dir(
368 install_static::InstallDetails::Get().invalid_user_data_dir());
369 if (!invalid_user_data_dir.empty()) {
370 chrome::SetInvalidSpecifiedUserDataDir(
371 base::FilePath(invalid_user_data_dir));
372 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
373 }
374 CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
375 user_data_dir, true, false));
376 #else // OS_WIN
364 base::FilePath user_data_dir = 377 base::FilePath user_data_dir =
365 command_line->GetSwitchValuePath(switches::kUserDataDir); 378 command_line->GetSwitchValuePath(switches::kUserDataDir);
366 std::string process_type = 379 std::string process_type =
367 command_line->GetSwitchValueASCII(switches::kProcessType); 380 command_line->GetSwitchValueASCII(switches::kProcessType);
368 381
369 #if defined(OS_LINUX) 382 #if defined(OS_LINUX)
370 // On Linux, Chrome does not support running multiple copies under different 383 // On Linux, Chrome does not support running multiple copies under different
371 // DISPLAYs, so the profile directory can be specified in the environment to 384 // DISPLAYs, so the profile directory can be specified in the environment to
372 // support the virtual desktop use-case. 385 // support the virtual desktop use-case.
373 if (user_data_dir.empty()) { 386 if (user_data_dir.empty()) {
374 std::string user_data_dir_string; 387 std::string user_data_dir_string;
375 std::unique_ptr<base::Environment> environment(base::Environment::Create()); 388 std::unique_ptr<base::Environment> environment(base::Environment::Create());
376 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) && 389 if (environment->GetVar("CHROME_USER_DATA_DIR", &user_data_dir_string) &&
377 base::IsStringUTF8(user_data_dir_string)) { 390 base::IsStringUTF8(user_data_dir_string)) {
378 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string); 391 user_data_dir = base::FilePath::FromUTF8Unsafe(user_data_dir_string);
379 } 392 }
380 } 393 }
381 #endif 394 #endif // OS_LINUX
382 #if defined(OS_MACOSX) || defined(OS_WIN) 395 #if defined(OS_MACOSX)
383 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir); 396 policy::path_parser::CheckUserDataDirPolicy(&user_data_dir);
384 #endif 397 #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 398
391 const bool specified_directory_was_invalid = !user_data_dir.empty() && 399 const bool specified_directory_was_invalid = !user_data_dir.empty() &&
392 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, 400 !PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
393 user_data_dir, false, true); 401 user_data_dir, false, true);
394 // Save inaccessible or invalid paths so the user may be prompted later. 402 // Save inaccessible or invalid paths so the user may be prompted later.
395 if (specified_directory_was_invalid) 403 if (specified_directory_was_invalid)
396 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir); 404 chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
397 405
398 // Warn and fail early if the process fails to get a user data directory. 406 // 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)) { 407 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 420 // 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. 421 // handle the error later; other processes that need the dir crash here.
414 CHECK(process_type.empty()) << "Unable to get the user data directory " 422 CHECK(process_type.empty()) << "Unable to get the user data directory "
415 << "for process type: " << process_type; 423 << "for process type: " << process_type;
416 } 424 }
417 425
418 // Append the fallback user data directory to the commandline. Otherwise, 426 // Append the fallback user data directory to the commandline. Otherwise,
419 // child or service processes will attempt to use the invalid directory. 427 // child or service processes will attempt to use the invalid directory.
420 if (specified_directory_was_invalid) 428 if (specified_directory_was_invalid)
421 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 429 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
430 #endif // OS_WIN
422 } 431 }
423 432
424 #if !defined(OS_ANDROID) 433 #if !defined(OS_ANDROID)
425 void InitLogging(const std::string& process_type) { 434 void InitLogging(const std::string& process_type) {
426 logging::OldFileDeletionState file_state = 435 logging::OldFileDeletionState file_state =
427 logging::APPEND_TO_OLD_LOG_FILE; 436 logging::APPEND_TO_OLD_LOG_FILE;
428 if (process_type.empty()) { 437 if (process_type.empty()) {
429 file_state = logging::DELETE_OLD_LOG_FILE; 438 file_state = logging::DELETE_OLD_LOG_FILE;
430 } 439 }
431 const base::CommandLine& command_line = 440 const base::CommandLine& command_line =
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 child_process_logging::Init(); 750 child_process_logging::Init();
742 #endif 751 #endif
743 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) 752 #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 753 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
745 // cpu_brand info. 754 // cpu_brand info.
746 base::CPU cpu_info; 755 base::CPU cpu_info;
747 #endif 756 #endif
748 757
749 // Initialize the user data dir for any process type that needs it. 758 // Initialize the user data dir for any process type that needs it.
750 if (chrome::ProcessNeedsProfileDir(process_type)) { 759 if (chrome::ProcessNeedsProfileDir(process_type)) {
751 InitializeUserDataDir(); 760 InitializeUserDataDir(base::CommandLine::ForCurrentProcess());
752 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD) 761 #if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD)
753 if (downgrade::IsMSIInstall()) { 762 if (downgrade::IsMSIInstall()) {
754 downgrade::MoveUserDataForFirstRunAfterDowngrade(); 763 downgrade::MoveUserDataForFirstRunAfterDowngrade();
755 base::FilePath user_data_dir; 764 base::FilePath user_data_dir;
756 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 765 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
757 downgrade::UpdateLastVersion(user_data_dir); 766 downgrade::UpdateLastVersion(user_data_dir);
758 } 767 }
759 #endif 768 #endif
760 } 769 }
761 770
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 case version_info::Channel::CANARY: 1063 case version_info::Channel::CANARY:
1055 return true; 1064 return true;
1056 case version_info::Channel::DEV: 1065 case version_info::Channel::DEV:
1057 case version_info::Channel::BETA: 1066 case version_info::Channel::BETA:
1058 case version_info::Channel::STABLE: 1067 case version_info::Channel::STABLE:
1059 default: 1068 default:
1060 // Don't enable instrumentation. 1069 // Don't enable instrumentation.
1061 return false; 1070 return false;
1062 } 1071 }
1063 } 1072 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698