Commit 087ef223 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Don't write to download metadata cache while in incognito

In incognito mode, we shouldn't write to the metadata cache.
BrowserContext::GetPath() will return the path of the normal
profile in incognito mode.

BUG=778425

Change-Id: If1cd5d819d0b754010f60f776226c34d92e383f4
Reviewed-on: https://chromium-review.googlesource.com/1033540Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554554}
parent 28e7ee60
......@@ -60,6 +60,9 @@ void RemoveEntryFromEntries(metadata_pb::DownloadEntries& entries,
// Helper functions for file read/write operations.
std::vector<char> ReadEntriesFromFile(base::FilePath file_path) {
if (file_path.empty())
return std::vector<char>();
// Check validity of file.
base::File entries_file(file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
......@@ -113,7 +116,8 @@ std::string EntriesToString(const metadata_pb::DownloadEntries& entries) {
}
void WriteEntriesToFile(const std::string& entries, base::FilePath file_path) {
DCHECK(!file_path.empty());
if (file_path.empty())
return;
if (!base::ImportantFileWriter::WriteFileAtomically(file_path, entries)) {
LOG(ERROR) << "Could not write download entries to file: "
......
......@@ -24,7 +24,7 @@ namespace download {
// right away.
class InProgressCacheImpl : public InProgressCache {
public:
explicit InProgressCacheImpl(
InProgressCacheImpl(
const base::FilePath& cache_file_path,
const scoped_refptr<base::SequencedTaskRunner>& task_runner);
~InProgressCacheImpl() override;
......
......@@ -239,11 +239,9 @@ void InProgressDownloadManager::InterceptDownloadFromNavigation(
void InProgressDownloadManager::Initialize(
const base::FilePath& metadata_cache_dir,
const base::RepeatingClosure& callback) {
DCHECK(!metadata_cache_dir.empty());
base::FilePath metadata_cache_file =
metadata_cache_dir.Append(kDownloadMetadataStoreFilename);
download_metadata_cache_ = std::make_unique<InProgressCacheImpl>(
metadata_cache_file,
metadata_cache_dir.empty() ? base::FilePath() :
metadata_cache_dir.Append(kDownloadMetadataStoreFilename),
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}));
......
......@@ -291,7 +291,7 @@ DownloadManagerImpl::DownloadManagerImpl(BrowserContext* browser_context)
in_progress_manager_ = std::make_unique<download::InProgressDownloadManager>(
this, base::BindRepeating(&IsOriginSecure));
in_progress_manager_->Initialize(
browser_context_->GetPath(),
IsOffTheRecord() ? base::FilePath() : browser_context_->GetPath(),
base::BindRepeating(
&DownloadManagerImpl::PostInitialization, weak_factory_.GetWeakPtr(),
DOWNLOAD_INITIALIZATION_DEPENDENCY_IN_PROGRESS_CACHE));
......
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