Commit 4eac21ba authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add ObfuscatedFileUtilMemoryDelegate.

|ObfuscatedFileUtilDelegate| and |ObfuscatedFileUtilMemoryDelegate|
are added to support in-memory file system for incognito mode and
|ObfuscatedFileUtil| is updated to choose the appropriate delegate
based on being incognito or not.

To avoid making the CL large, only the skeleton of the
|ObfuscatedFileUtilMemoryDelegate| is added in this CL and the actual
implementation will be added in a next one.

The change is part of the following design doc:
https://docs.google.com/document/d/17NV1cGSIEG2i5qm2QU4EzDMKRoyVEbNNq-Re-JhwSB0

Bug: 93417
Change-Id: I47353c656ab70ab6c98c8e06c9e0c3a03319d012
Reviewed-on: https://chromium-review.googlesource.com/c/1452176Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630002}
parent ef04f89b
......@@ -131,8 +131,11 @@ jumbo_component("browser") {
"fileapi/native_file_util.h",
"fileapi/obfuscated_file_util.cc",
"fileapi/obfuscated_file_util.h",
"fileapi/obfuscated_file_util_delegate.h",
"fileapi/obfuscated_file_util_disk_delegate.cc",
"fileapi/obfuscated_file_util_disk_delegate.h",
"fileapi/obfuscated_file_util_memory_delegate.cc",
"fileapi/obfuscated_file_util_memory_delegate.h",
"fileapi/open_file_system_mode.h",
"fileapi/plugin_private_file_system_backend.cc",
"fileapi/plugin_private_file_system_backend.h",
......
......@@ -25,6 +25,8 @@
#include "storage/browser/fileapi/file_observers.h"
#include "storage/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/file_system_operation_context.h"
#include "storage/browser/fileapi/obfuscated_file_util_disk_delegate.h"
#include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h"
#include "storage/browser/fileapi/sandbox_file_system_backend.h"
#include "storage/browser/fileapi/sandbox_isolated_origin_database.h"
#include "storage/browser/fileapi/sandbox_origin_database.h"
......@@ -265,14 +267,16 @@ ObfuscatedFileUtil::ObfuscatedFileUtil(
db_flush_delay_seconds_(10 * 60), // 10 mins.
get_type_string_for_url_(std::move(get_type_string_for_url)),
known_type_strings_(known_type_strings),
sandbox_delegate_(sandbox_delegate),
delegate_(std::make_unique<ObfuscatedFileUtilDiskDelegate>()) {
// TODO(https://crbug.com/93417): |delegate_| to be initialized with an
// instance of |ObfuscatedFileUtilMemoryDelegate| if |is_incognito| is true.
sandbox_delegate_(sandbox_delegate) {
DCHECK(!get_type_string_for_url_.is_null());
DETACH_FROM_SEQUENCE(sequence_checker_);
DCHECK(!is_incognito ||
(env_override && leveldb_chrome::IsMemEnv(env_override)));
if (is_incognito)
delegate_ = std::make_unique<ObfuscatedFileUtilMemoryDelegate>();
else
delegate_ = std::make_unique<ObfuscatedFileUtilDiskDelegate>();
}
ObfuscatedFileUtil::~ObfuscatedFileUtil() {
......
......@@ -23,9 +23,7 @@
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/fileapi/file_system_file_util.h"
#include "storage/browser/fileapi/file_system_url.h"
// TODO(https://crbug.com/93417): To be replaced with
// obfuscated_file_util_delegate.h
#include "storage/browser/fileapi/obfuscated_file_util_disk_delegate.h"
#include "storage/browser/fileapi/obfuscated_file_util_delegate.h"
#include "storage/browser/fileapi/sandbox_directory_database.h"
#include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h"
#include "storage/common/fileapi/file_system_types.h"
......@@ -342,9 +340,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtil
// Not owned.
SandboxFileSystemBackendDelegate* sandbox_delegate_;
// TODO(https://crbug.com/93417): To be replaced with
// ObfuscatedFileUtilDelegate.
std::unique_ptr<ObfuscatedFileUtilDiskDelegate> delegate_;
std::unique_ptr<ObfuscatedFileUtilDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtil);
};
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_DELEGATE_H_
#define STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_DELEGATE_H_
#include "base/component_export.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "storage/browser/fileapi/native_file_util.h"
namespace storage {
// This delegate performs all ObfuscatedFileUtil tasks that actually touch disk.
class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDelegate {
public:
ObfuscatedFileUtilDelegate() = default;
virtual ~ObfuscatedFileUtilDelegate() = default;
virtual bool DirectoryExists(const base::FilePath& path) = 0;
virtual bool DeleteFileOrDirectory(const base::FilePath& path,
bool recursive) = 0;
virtual bool IsLink(const base::FilePath& file_path) = 0;
virtual bool PathExists(const base::FilePath& path) = 0;
virtual NativeFileUtil::CopyOrMoveMode CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy) = 0;
virtual base::File CreateOrOpen(const base::FilePath& path,
int file_flags) = 0;
virtual base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) = 0;
virtual base::File::Error CreateDirectory(const base::FilePath& path,
bool exclusive,
bool recursive) = 0;
virtual base::File::Error GetFileInfo(const base::FilePath& path,
base::File::Info* file_info) = 0;
virtual base::File::Error Touch(const base::FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) = 0;
virtual base::File::Error Truncate(const base::FilePath& path,
int64_t length) = 0;
virtual base::File::Error CopyOrMoveFile(
const base::FilePath& src_path,
const base::FilePath& dest_path,
FileSystemOperation::CopyOrMoveOption option,
NativeFileUtil::CopyOrMoveMode mode) = 0;
virtual base::File::Error DeleteFile(const base::FilePath& path) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilDelegate);
};
} // namespace storage
#endif // STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_DELEGATE_H_
......@@ -11,6 +11,8 @@ namespace storage {
ObfuscatedFileUtilDiskDelegate::ObfuscatedFileUtilDiskDelegate() {}
ObfuscatedFileUtilDiskDelegate::~ObfuscatedFileUtilDiskDelegate() {}
bool ObfuscatedFileUtilDiskDelegate::DirectoryExists(
const base::FilePath& path) {
return base::DirectoryExists(path);
......
......@@ -9,42 +9,46 @@
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "storage/browser/fileapi/native_file_util.h"
#include "storage/browser/fileapi/obfuscated_file_util_delegate.h"
namespace storage {
// This delegate performs all ObfuscatedFileUtil tasks that actually touch disk.
// TODO(https://crbug.com/93417): To be driven from abstract class
// |ObfuscatedFileUtilDelegate|.
class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDiskDelegate {
class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDiskDelegate
: public ObfuscatedFileUtilDelegate {
public:
ObfuscatedFileUtilDiskDelegate();
~ObfuscatedFileUtilDiskDelegate() = default;
~ObfuscatedFileUtilDiskDelegate() override;
bool DirectoryExists(const base::FilePath& path);
bool DeleteFileOrDirectory(const base::FilePath& path, bool recursive);
bool IsLink(const base::FilePath& file_path);
bool PathExists(const base::FilePath& path);
bool DirectoryExists(const base::FilePath& path) override;
bool DeleteFileOrDirectory(const base::FilePath& path,
bool recursive) override;
bool IsLink(const base::FilePath& file_path) override;
bool PathExists(const base::FilePath& path) override;
NativeFileUtil::CopyOrMoveMode CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy);
base::File CreateOrOpen(const base::FilePath& path, int file_flags);
base::File::Error EnsureFileExists(const base::FilePath& path, bool* created);
bool copy) override;
base::File CreateOrOpen(const base::FilePath& path, int file_flags) override;
base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) override;
base::File::Error CreateDirectory(const base::FilePath& path,
bool exclusive,
bool recursive);
bool recursive) override;
base::File::Error GetFileInfo(const base::FilePath& path,
base::File::Info* file_info);
base::File::Info* file_info) override;
base::File::Error Touch(const base::FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time);
base::File::Error Truncate(const base::FilePath& path, int64_t length);
base::File::Error CopyOrMoveFile(const base::FilePath& src_path,
const base::FilePath& dest_path,
FileSystemOperation::CopyOrMoveOption option,
NativeFileUtil::CopyOrMoveMode mode);
base::File::Error DeleteFile(const base::FilePath& path);
const base::Time& last_modified_time) override;
base::File::Error Truncate(const base::FilePath& path,
int64_t length) override;
base::File::Error CopyOrMoveFile(
const base::FilePath& src_path,
const base::FilePath& dest_path,
FileSystemOperation::CopyOrMoveOption option,
NativeFileUtil::CopyOrMoveMode mode) override;
base::File::Error DeleteFile(const base::FilePath& path) override;
DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilDiskDelegate);
};
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h"
namespace storage {
ObfuscatedFileUtilMemoryDelegate::ObfuscatedFileUtilMemoryDelegate() {}
ObfuscatedFileUtilMemoryDelegate::~ObfuscatedFileUtilMemoryDelegate() {}
bool ObfuscatedFileUtilMemoryDelegate::DirectoryExists(
const base::FilePath& path) {
NOTIMPLEMENTED();
// return base::DirectoryExists(path);
return false;
}
bool ObfuscatedFileUtilMemoryDelegate::DeleteFileOrDirectory(
const base::FilePath& path,
bool recursive) {
NOTIMPLEMENTED();
// return base::DeleteFile(path, recursive);
return false;
}
bool ObfuscatedFileUtilMemoryDelegate::IsLink(const base::FilePath& file_path) {
NOTIMPLEMENTED();
// return base::IsLink(file_path);
return false;
}
bool ObfuscatedFileUtilMemoryDelegate::PathExists(const base::FilePath& path) {
NOTIMPLEMENTED();
// return base::PathExists(path);
return false;
}
NativeFileUtil::CopyOrMoveMode
ObfuscatedFileUtilMemoryDelegate::CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy) {
NOTIMPLEMENTED();
// return NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy);
return NativeFileUtil::CopyOrMoveMode::MOVE;
}
base::File ObfuscatedFileUtilMemoryDelegate::CreateOrOpen(
const base::FilePath& path,
int file_flags) {
NOTIMPLEMENTED();
// return NativeFileUtil::CreateOrOpen(path, file_flags);
return base::File();
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::EnsureFileExists(
const base::FilePath& path,
bool* created) {
NOTIMPLEMENTED();
// return NativeFileUtil::EnsureFileExists(path, created);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::CreateDirectory(
const base::FilePath& path,
bool exclusive,
bool recursive) {
NOTIMPLEMENTED();
// return NativeFileUtil::CreateDirectory(path, exclusive, recursive);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::GetFileInfo(
const base::FilePath& path,
base::File::Info* file_info) {
NOTIMPLEMENTED();
// return NativeFileUtil::GetFileInfo(path, file_info);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::Touch(
const base::FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) {
NOTIMPLEMENTED();
// return NativeFileUtil::Touch(path, last_access_time, last_modified_time);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::Truncate(
const base::FilePath& path,
int64_t length) {
NOTIMPLEMENTED();
// return NativeFileUtil::Truncate(path, length);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::CopyOrMoveFile(
const base::FilePath& src_path,
const base::FilePath& dest_path,
FileSystemOperation::CopyOrMoveOption option,
NativeFileUtil::CopyOrMoveMode mode) {
NOTIMPLEMENTED();
// return NativeFileUtil::CopyOrMoveFile(src_path, dest_path, option, mode);
return base::File::FILE_ERROR_FAILED;
}
base::File::Error ObfuscatedFileUtilMemoryDelegate::DeleteFile(
const base::FilePath& path) {
NOTIMPLEMENTED();
// return NativeFileUtil::DeleteFile(path);
return base::File::FILE_ERROR_FAILED;
}
} // namespace storage
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_MEMORY_DELEGATE_H_
#define STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_MEMORY_DELEGATE_H_
#include "base/component_export.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "storage/browser/fileapi/native_file_util.h"
#include "storage/browser/fileapi/obfuscated_file_util_delegate.h"
namespace storage {
// This delegate performs all ObfuscatedFileUtil tasks that require touching
// disk and peforms them in memory.
class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilMemoryDelegate
: public ObfuscatedFileUtilDelegate {
public:
ObfuscatedFileUtilMemoryDelegate();
~ObfuscatedFileUtilMemoryDelegate() override;
bool DirectoryExists(const base::FilePath& path) override;
bool DeleteFileOrDirectory(const base::FilePath& path,
bool recursive) override;
bool IsLink(const base::FilePath& file_path) override;
bool PathExists(const base::FilePath& path) override;
NativeFileUtil::CopyOrMoveMode CopyOrMoveModeForDestination(
const FileSystemURL& dest_url,
bool copy) override;
base::File CreateOrOpen(const base::FilePath& path, int file_flags) override;
base::File::Error EnsureFileExists(const base::FilePath& path,
bool* created) override;
base::File::Error CreateDirectory(const base::FilePath& path,
bool exclusive,
bool recursive) override;
base::File::Error GetFileInfo(const base::FilePath& path,
base::File::Info* file_info) override;
base::File::Error Touch(const base::FilePath& path,
const base::Time& last_access_time,
const base::Time& last_modified_time) override;
base::File::Error Truncate(const base::FilePath& path,
int64_t length) override;
base::File::Error CopyOrMoveFile(
const base::FilePath& src_path,
const base::FilePath& dest_path,
FileSystemOperation::CopyOrMoveOption option,
NativeFileUtil::CopyOrMoveMode mode) override;
base::File::Error DeleteFile(const base::FilePath& path) override;
DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilMemoryDelegate);
};
} // namespace storage
#endif // STORAGE_BROWSER_FILEAPI_OBFUSCATED_FILE_UTIL_MEMORY_DELEGATE_H_
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