Commit 49a54b59 authored by michaelpg's avatar michaelpg Committed by Commit bot

content_shell/app_shell: validate --data-path and fall back to default directory

The --data-path switch, if passed, specifies what directory to use as the browsing
context's data directory. This CL checks that the directory actually exists/can be
created, and converts relative paths to absolute.

Note: This code is executed twice in content_shell (for normal and OTR contexts); in
the long run, giving the shell its own PathProvider may be a better solution.

Review-Url: https://codereview.chromium.org/2344073003
Cr-Commit-Position: refs/heads/master@{#422670}
parent bd230111
......@@ -75,9 +75,20 @@ void ShellBrowserContext::InitWhileIOAllowed() {
ignore_certificate_errors_ = true;
if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
BrowserContext::Initialize(this, path_);
return;
if (base::DirectoryExists(path_) || base::CreateDirectory(path_)) {
// BrowserContext needs an absolute path, which we would normally get via
// PathService. In this case, manually ensure the path is absolute.
if (!path_.IsAbsolute())
path_ = base::MakeAbsoluteFilePath(path_);
if (!path_.empty()) {
BrowserContext::Initialize(this, path_);
return;
}
} else {
LOG(WARNING) << "Unable to create data-path directory: " << path_.value();
}
}
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"content_shell"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment