summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 23:02:20 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 23:02:20 +0000
commitbc6431ccc1c076a404a6aa6747ed8183f4e0943e (patch)
treebf7ce0cbd9896342560313fccc0ee4c76656a8e2 /chrome
parent8b38988b9820041f31fb0af6a9dd19acdaafe7b1 (diff)
downloadchromium_src-bc6431ccc1c076a404a6aa6747ed8183f4e0943e.zip
chromium_src-bc6431ccc1c076a404a6aa6747ed8183f4e0943e.tar.gz
chromium_src-bc6431ccc1c076a404a6aa6747ed8183f4e0943e.tar.bz2
Reduce user-data-dir crashes; warn and exit if possible.
Only init the user-data-dir as needed. Warn and exit on browser startup, don't crash. Warn with the default dir if PathService fails. (Get fails when that dir can't be created) TODO(followup): Fix IsFirstRunSentinelPresent paths. (ignores --user-data-dir switches, policy) (DCHECKs even with a good override dir) TODO(followup): PathService::Get behavior change. (return paths that it cannot create with false/error) TODO(followup): Handle existing, inaccessible dirs. (see description at <http://crbug.com/349899#c3>) BUG=349899,345025,345582 TEST=fewer user-data-dir related crashes, more warning dialogs, especially when the browser process is launched without access privileges to the parent of the default user-data-dir (mixed account uses, launching as service(?), etc.); see the bug. Does not regress issue 345025 nor issue 345582. R=cpu@chromium.org, gab@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/180723025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/chrome_main_delegate.cc31
-rw-r--r--chrome/browser/chrome_browser_main.cc3
2 files changed, 25 insertions, 9 deletions
diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc
index 26ef191..be19f7b 100644
--- a/chrome/app/chrome_main_delegate.cc
+++ b/chrome/app/chrome_main_delegate.cc
@@ -348,16 +348,30 @@ void InitializeUserDataDir() {
const bool specified_directory_was_invalid = !user_data_dir.empty() &&
!PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
- user_data_dir, chrome::ProcessNeedsProfileDir(process_type));
+ user_data_dir, true);
// Save inaccessible or invalid paths so the user may be prompted later.
if (specified_directory_was_invalid)
chrome::SetInvalidSpecifiedUserDataDir(user_data_dir);
- // Getting the user data directory can fail if the directory isn't creatable.
- // ProcessSingleton needs a real user data directory on Mac/Linux, so it's
- // better to fail here than fail mysteriously elsewhere.
- CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
- << "Must be able to get user data directory!";
+ // 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;
+ }
// Append the fallback user data directory to the commandline. Otherwise,
// child or service processes will attempt to use the invalid directory.
@@ -633,8 +647,9 @@ void ChromeMainDelegate::PreSandboxStartup() {
child_process_logging::Init();
#endif
- // Initialize the user data dir for service processes, logging, etc.
- InitializeUserDataDir();
+ // Initialize the user data dir for any process type that needs it.
+ if (chrome::ProcessNeedsProfileDir(process_type))
+ InitializeUserDataDir();
stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init"));
startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer>
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 8eb447b..2a882f9 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -780,10 +780,11 @@ int ChromeBrowserMainParts::PreCreateThreads() {
int ChromeBrowserMainParts::PreCreateThreadsImpl() {
TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreadsImpl")
run_message_loop_ = false;
- CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_));
#if !defined(OS_ANDROID)
chrome::MaybeShowInvalidUserDataDirWarningDialog();
#endif
+ if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
+ return chrome::RESULT_CODE_MISSING_DATA;
// Force MediaCaptureDevicesDispatcher to be created on UI thread.
MediaCaptureDevicesDispatcher::GetInstance();