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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/app/chrome_main_delegate.cc
diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc
index b33dec417a1fe9ab77c86e7868ff781748e5e2e8..ca3e866b83756dbeadbb6d1af008cf5771d8d5e3 100644
--- a/chrome/app/chrome_main_delegate.cc
+++ b/chrome/app/chrome_main_delegate.cc
@@ -26,6 +26,7 @@
#include "build/build_config.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/defaults.h"
+#include "chrome/browser/ui/startup/bad_flags_prompt.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_content_client.h"
@@ -358,14 +359,51 @@ struct MainFunction {
int (*function)(const content::MainFunctionParams&);
};
+#if !defined(OS_ANDROID)
+void InitLogging(const std::string& process_type) {
+ logging::OldFileDeletionState file_state =
+ logging::APPEND_TO_OLD_LOG_FILE;
+ if (process_type.empty()) {
+ file_state = logging::DELETE_OLD_LOG_FILE;
+ }
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+ logging::InitChromeLogging(command_line, file_state);
+}
+#endif
+
+#if !defined(CHROME_MULTIPLE_DLL_CHILD)
+void RecordMainStartupMetrics(base::TimeTicks exe_entry_point_ticks) {
+ if (!exe_entry_point_ticks.is_null())
+ startup_metric_utils::RecordExeMainEntryPointTicks(exe_entry_point_ticks);
+#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
+ // Record the startup process creation time on supported platforms.
+ startup_metric_utils::RecordStartupProcessCreationTime(
+ base::CurrentProcessInfo::CreationTime());
+#endif
+
+// On Android the main entry point time is the time when the Java code starts.
+// This happens before the shared library containing this code is even loaded.
+// The Java startup code has recorded that time, but the C++ code can't fetch it
+// from the Java side until it has initialized the JNI. See
+// ChromeMainDelegateAndroid.
+#if !defined(OS_ANDROID)
+ startup_metric_utils::RecordMainEntryPointTime(base::Time::Now());
+#endif
+}
+#endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
+
+} // namespace
+
// Initializes the user data dir. Must be called before InitializeLocalState().
-void InitializeUserDataDir() {
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+// WARNING! It is important that this code match behavior with
+// GetUserDataDirectory() in chrome_elf. The two functions must be updated in
+// sync.
+void InitializeUserDataDir(base::CommandLine* command_line) {
base::FilePath user_data_dir =
command_line->GetSwitchValuePath(switches::kUserDataDir);
std::string process_type =
command_line->GetSwitchValueASCII(switches::kProcessType);
-
#if defined(OS_LINUX)
// On Linux, Chrome does not support running multiple copies under different
// DISPLAYs, so the profile directory can be specified in the environment to
@@ -397,22 +435,9 @@ void InitializeUserDataDir() {
// Warn and fail early if the process fails to get a user data directory.
if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
- // If an invalid command-line or policy override was specified, the user
- // will be given an error with that value. Otherwise, use the directory
- // returned by PathService (or the fallback default directory) in the error.
- if (!specified_directory_was_invalid) {
- // PathService::Get() returns false and yields an empty path if it fails
- // to create DIR_USER_DATA. Retrieve the default value manually to display
- // a more meaningful error to the user in that case.
- if (user_data_dir.empty())
- chrome::GetDefaultUserDataDirectory(&user_data_dir);
- chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
- }
-
- // The browser process (which is identified by an empty |process_type|) will
- // handle the error later; other processes that need the dir crash here.
- CHECK(process_type.empty()) << "Unable to get the user data directory "
- << "for process type: " << process_type;
+ chrome::MaybeShowInvalidUserDataDirWarningDialog();
+ LOG(FATAL) << "Unable to get the user data directory "
+ << "for process type: " << process_type;
}
// Append the fallback user data directory to the commandline. Otherwise,
@@ -421,41 +446,6 @@ void InitializeUserDataDir() {
command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
}
-#if !defined(OS_ANDROID)
-void InitLogging(const std::string& process_type) {
- logging::OldFileDeletionState file_state =
- logging::APPEND_TO_OLD_LOG_FILE;
- if (process_type.empty()) {
- file_state = logging::DELETE_OLD_LOG_FILE;
- }
- const base::CommandLine& command_line =
- *base::CommandLine::ForCurrentProcess();
- logging::InitChromeLogging(command_line, file_state);
-}
-#endif
-
-#if !defined(CHROME_MULTIPLE_DLL_CHILD)
-void RecordMainStartupMetrics(base::TimeTicks exe_entry_point_ticks) {
- if (!exe_entry_point_ticks.is_null())
- startup_metric_utils::RecordExeMainEntryPointTicks(exe_entry_point_ticks);
-#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
- // Record the startup process creation time on supported platforms.
- startup_metric_utils::RecordStartupProcessCreationTime(
- base::CurrentProcessInfo::CreationTime());
-#endif
-
-// On Android the main entry point time is the time when the Java code starts.
-// This happens before the shared library containing this code is even loaded.
-// The Java startup code has recorded that time, but the C++ code can't fetch it
-// from the Java side until it has initialized the JNI. See
-// ChromeMainDelegateAndroid.
-#if !defined(OS_ANDROID)
- startup_metric_utils::RecordMainEntryPointTime(base::Time::Now());
-#endif
-}
-#endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
-
-} // namespace
ChromeMainDelegate::ChromeMainDelegate()
: ChromeMainDelegate(base::TimeTicks()) {}
@@ -748,7 +738,7 @@ void ChromeMainDelegate::PreSandboxStartup() {
// Initialize the user data dir for any process type that needs it.
if (chrome::ProcessNeedsProfileDir(process_type)) {
- InitializeUserDataDir();
+ InitializeUserDataDir(base::CommandLine::ForCurrentProcess());
#if defined(OS_WIN) && !defined(CHROME_MULTIPLE_DLL_CHILD)
if (downgrade::IsMSIInstall()) {
downgrade::MoveUserDataForFirstRunAfterDowngrade();

Powered by Google App Engine
This is Rietveld 408576698