Commit cbae8d9e authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[NativeFS] Change hash calculation code to go through FS backends.

This makes sure this code works for non-native file systems.

Bug: 1103076
Change-Id: I1579fd33cd40b6527504a89987ba8dbc9b3c8931
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304958
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791250}
parent fbbf6668
...@@ -85,14 +85,16 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl ...@@ -85,14 +85,16 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl
// perform cleanup even if the writer was deleted before they were invoked. // perform cleanup even if the writer was deleted before they were invoked.
static void DoAfterWriteCheck( static void DoAfterWriteCheck(
base::WeakPtr<NativeFileSystemFileWriterImpl> file_writer, base::WeakPtr<NativeFileSystemFileWriterImpl> file_writer,
const base::FilePath& swap_path, scoped_refptr<NativeFileSystemManagerImpl> manager,
const storage::FileSystemURL& swap_url,
NativeFileSystemFileWriterImpl::CloseCallback callback, NativeFileSystemFileWriterImpl::CloseCallback callback,
base::File::Error hash_result, base::File::Error hash_result,
const std::string& hash, const std::string& hash,
int64_t size); int64_t size);
static void DidAfterWriteCheck( static void DidAfterWriteCheck(
base::WeakPtr<NativeFileSystemFileWriterImpl> file_writer, base::WeakPtr<NativeFileSystemFileWriterImpl> file_writer,
const base::FilePath& swap_path, scoped_refptr<NativeFileSystemManagerImpl> manager,
const storage::FileSystemURL& swap_url,
NativeFileSystemFileWriterImpl::CloseCallback callback, NativeFileSystemFileWriterImpl::CloseCallback callback,
NativeFileSystemPermissionContext::AfterWriteCheckResult result); NativeFileSystemPermissionContext::AfterWriteCheckResult result);
void DidPassAfterWriteCheck(CloseCallback callback); void DidPassAfterWriteCheck(CloseCallback callback);
...@@ -106,8 +108,7 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl ...@@ -106,8 +108,7 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl
// except temporary file systems. // except temporary file systems.
// TOOD(crbug.com/1103076): Extend this check to non-native paths. // TOOD(crbug.com/1103076): Extend this check to non-native paths.
bool RequireSecurityChecks() const { bool RequireSecurityChecks() const {
return url().type() == storage::kFileSystemTypeNativeLocal || return url().type() != storage::kFileSystemTypeTemporary;
url().type() == storage::kFileSystemTypeNativeForPlatformApp;
} }
void ComputeHashForSwapFile(HashCallback callback); void ComputeHashForSwapFile(HashCallback callback);
......
...@@ -290,8 +290,7 @@ TEST_F(NativeFileSystemManagerImplTest, ...@@ -290,8 +290,7 @@ TEST_F(NativeFileSystemManagerImplTest,
storage::AsyncFileTestHelper::kDontCheckSize)); storage::AsyncFileTestHelper::kDontCheckSize));
} }
TEST_F(NativeFileSystemManagerImplTest, TEST_F(NativeFileSystemManagerImplTest, FileWriterCloseAbortsOnDestruct) {
FileWriterCloseAllowedToCompleteOnDestruct) {
auto test_file_url = file_system_context_->CreateCrackedFileSystemURL( auto test_file_url = file_system_context_->CreateCrackedFileSystemURL(
kTestOrigin, storage::kFileSystemTypeTest, kTestOrigin, storage::kFileSystemTypeTest,
base::FilePath::FromUTF8Unsafe("test")); base::FilePath::FromUTF8Unsafe("test"));
...@@ -319,11 +318,14 @@ TEST_F(NativeFileSystemManagerImplTest, ...@@ -319,11 +318,14 @@ TEST_F(NativeFileSystemManagerImplTest,
writer_remote.reset(); writer_remote.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Since the writer was destroyed before close completed, the swap file should
// have been destroyed and the target file should have been left untouched.
ASSERT_FALSE(storage::AsyncFileTestHelper::FileExists( ASSERT_FALSE(storage::AsyncFileTestHelper::FileExists(
file_system_context_.get(), test_swap_url, file_system_context_.get(), test_swap_url,
storage::AsyncFileTestHelper::kDontCheckSize)); storage::AsyncFileTestHelper::kDontCheckSize));
ASSERT_TRUE(storage::AsyncFileTestHelper::FileExists( ASSERT_FALSE(storage::AsyncFileTestHelper::FileExists(
file_system_context_.get(), test_file_url, 3)); file_system_context_.get(), test_file_url,
storage::AsyncFileTestHelper::kDontCheckSize));
} }
TEST_F(NativeFileSystemManagerImplTest, SerializeHandle_SandboxedFile) { TEST_F(NativeFileSystemManagerImplTest, SerializeHandle_SandboxedFile) {
...@@ -750,4 +752,4 @@ TEST_F(NativeFileSystemManagerImplTest, ...@@ -750,4 +752,4 @@ TEST_F(NativeFileSystemManagerImplTest,
EXPECT_FALSE(dir_remote.is_connected()); EXPECT_FALSE(dir_remote.is_connected());
} }
} // namespace content } // namespace content
\ No newline at end of file
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