Commit e34d4727 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Add a wrapper for |PasswordManagerExporter::delete_function_|.

Prepare for changing the signature of base::DeleteFile().

Bug: 1009837
Change-Id: I696626753362ddcd18df10879f816576a1f7aed9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204837Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#778845}
parent eb7e85a8
...@@ -51,6 +51,10 @@ bool DefaultWriteFunction(const base::FilePath& file, base::StringPiece data) { ...@@ -51,6 +51,10 @@ bool DefaultWriteFunction(const base::FilePath& file, base::StringPiece data) {
return base::WriteFile(file, data); return base::WriteFile(file, data);
} }
bool DefaultDeleteFunction(const base::FilePath& file) {
return base::DeleteFile(file, /*recursive=*/false);
}
} // namespace } // namespace
namespace password_manager { namespace password_manager {
...@@ -63,7 +67,7 @@ PasswordManagerExporter::PasswordManagerExporter( ...@@ -63,7 +67,7 @@ PasswordManagerExporter::PasswordManagerExporter(
on_progress_(std::move(on_progress)), on_progress_(std::move(on_progress)),
last_progress_status_(ExportProgressStatus::NOT_STARTED), last_progress_status_(ExportProgressStatus::NOT_STARTED),
write_function_(base::BindRepeating(&DefaultWriteFunction)), write_function_(base::BindRepeating(&DefaultWriteFunction)),
delete_function_(base::BindRepeating(&base::DeleteFile)), delete_function_(base::BindRepeating(&DefaultDeleteFunction)),
#if defined(OS_POSIX) #if defined(OS_POSIX)
set_permissions_function_( set_permissions_function_(
base::BindRepeating(base::SetPosixFilePermissions)), base::BindRepeating(base::SetPosixFilePermissions)),
...@@ -191,9 +195,9 @@ void PasswordManagerExporter::Cleanup() { ...@@ -191,9 +195,9 @@ void PasswordManagerExporter::Cleanup() {
// TODO(crbug.com/811779) When Chrome is overwriting an existing file, cancel // TODO(crbug.com/811779) When Chrome is overwriting an existing file, cancel
// should restore the file rather than delete it. // should restore the file rather than delete it.
if (!destination_.empty()) { if (!destination_.empty()) {
task_runner_->PostTask(FROM_HERE, task_runner_->PostTask(
base::BindOnce(base::IgnoreResult(delete_function_), FROM_HERE,
destination_, false)); base::BindOnce(base::IgnoreResult(delete_function_), destination_));
} }
} }
......
...@@ -32,8 +32,7 @@ class PasswordManagerExporter { ...@@ -32,8 +32,7 @@ class PasswordManagerExporter {
const std::string&)>; const std::string&)>;
using WriteCallback = using WriteCallback =
base::RepeatingCallback<bool(const base::FilePath&, base::StringPiece)>; base::RepeatingCallback<bool(const base::FilePath&, base::StringPiece)>;
using DeleteCallback = using DeleteCallback = base::RepeatingCallback<bool(const base::FilePath&)>;
base::RepeatingCallback<bool(const base::FilePath&, bool)>;
using SetPosixFilePermissionsCallback = using SetPosixFilePermissionsCallback =
base::RepeatingCallback<bool(const base::FilePath&, int)>; base::RepeatingCallback<bool(const base::FilePath&, int)>;
......
...@@ -153,7 +153,7 @@ TEST_F(PasswordManagerExporterTest, WriteFileFailed) { ...@@ -153,7 +153,7 @@ TEST_F(PasswordManagerExporterTest, WriteFileFailed) {
destination_path_.DirName().BaseName().AsUTF8Unsafe()); destination_path_.DirName().BaseName().AsUTF8Unsafe());
EXPECT_CALL(mock_write_file_, Run(_, _)).WillOnce(Return(false)); EXPECT_CALL(mock_write_file_, Run(_, _)).WillOnce(Return(false));
EXPECT_CALL(mock_delete_file_, Run(destination_path_, false)); EXPECT_CALL(mock_delete_file_, Run(destination_path_));
EXPECT_CALL( EXPECT_CALL(
mock_on_progress_, mock_on_progress_,
Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty())); Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty()));
...@@ -216,7 +216,7 @@ TEST_F(PasswordManagerExporterTest, CancelAfterPasswords) { ...@@ -216,7 +216,7 @@ TEST_F(PasswordManagerExporterTest, CancelAfterPasswords) {
TEST_F(PasswordManagerExporterTest, CancelWhileExporting) { TEST_F(PasswordManagerExporterTest, CancelWhileExporting) {
EXPECT_CALL(mock_write_file_, Run(_, _)).Times(0); EXPECT_CALL(mock_write_file_, Run(_, _)).Times(0);
EXPECT_CALL(mock_delete_file_, Run(destination_path_, false)); EXPECT_CALL(mock_delete_file_, Run(destination_path_));
EXPECT_CALL( EXPECT_CALL(
mock_on_progress_, mock_on_progress_,
Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty())); Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty()));
...@@ -235,7 +235,7 @@ TEST_F(PasswordManagerExporterTest, CancelWhileExporting) { ...@@ -235,7 +235,7 @@ TEST_F(PasswordManagerExporterTest, CancelWhileExporting) {
// exporting. If they choose to cancel, we should clear the file. // exporting. If they choose to cancel, we should clear the file.
TEST_F(PasswordManagerExporterTest, CancelAfterExporting) { TEST_F(PasswordManagerExporterTest, CancelAfterExporting) {
EXPECT_CALL(mock_write_file_, Run(_, _)).WillOnce(Return(true)); EXPECT_CALL(mock_write_file_, Run(_, _)).WillOnce(Return(true));
EXPECT_CALL(mock_delete_file_, Run(destination_path_, false)); EXPECT_CALL(mock_delete_file_, Run(destination_path_));
EXPECT_CALL( EXPECT_CALL(
mock_on_progress_, mock_on_progress_,
Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty())); Run(password_manager::ExportProgressStatus::IN_PROGRESS, IsEmpty()));
......
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