diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 17:50:50 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 17:50:50 +0000 |
commit | 13934469b77d74a740bec503278c9aa0fdc8b586 (patch) | |
tree | aa7e8ba75130abec0bd740b4263ace8bdf498318 | |
parent | 2acfa97ab71fd9db54e6ccff9bf3b7c413c1f925 (diff) | |
download | chromium_src-13934469b77d74a740bec503278c9aa0fdc8b586.zip chromium_src-13934469b77d74a740bec503278c9aa0fdc8b586.tar.gz chromium_src-13934469b77d74a740bec503278c9aa0fdc8b586.tar.bz2 |
Merge 257512 "Reduce user-data-dir crashes; warn and exit if pos..."
> 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
TBR=msw@chromium.org
Review URL: https://codereview.chromium.org/196413024
git-svn-id: svn://svn.chromium.org/chrome/branches/1847/src@257684 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_main_delegate.cc | 31 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 3 |
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 c803506..d19a796 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -785,10 +785,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(); |