copy_or_move_file_validator.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef STORAGE_BROWSER_FILE_SYSTEM_COPY_OR_MOVE_FILE_VALIDATOR_H_
  5. #define STORAGE_BROWSER_FILE_SYSTEM_COPY_OR_MOVE_FILE_VALIDATOR_H_
  6. #include "base/callback.h"
  7. #include "base/component_export.h"
  8. #include "base/files/file.h"
  9. namespace base {
  10. class FilePath;
  11. }
  12. namespace storage {
  13. class FileSystemURL;
  14. class COMPONENT_EXPORT(STORAGE_BROWSER) CopyOrMoveFileValidator {
  15. public:
  16. // Callback that is invoked when validation completes. A result of
  17. // base::File::FILE_OK means the file validated.
  18. using ResultCallback = base::OnceCallback<void(base::File::Error result)>;
  19. CopyOrMoveFileValidator(const CopyOrMoveFileValidator&) = delete;
  20. CopyOrMoveFileValidator& operator=(const CopyOrMoveFileValidator&) = delete;
  21. virtual ~CopyOrMoveFileValidator() = default;
  22. // Called on a source file before copying or moving to the final
  23. // destination.
  24. virtual void StartPreWriteValidation(ResultCallback result_callback) = 0;
  25. // Called on a destination file after copying or moving to the final
  26. // destination. Suitable for running Anti-Virus checks.
  27. virtual void StartPostWriteValidation(
  28. const base::FilePath& dest_platform_path,
  29. ResultCallback result_callback) = 0;
  30. protected:
  31. CopyOrMoveFileValidator() = default;
  32. };
  33. class CopyOrMoveFileValidatorFactory {
  34. public:
  35. CopyOrMoveFileValidatorFactory(const CopyOrMoveFileValidatorFactory&) =
  36. delete;
  37. CopyOrMoveFileValidatorFactory& operator=(
  38. const CopyOrMoveFileValidatorFactory&) = delete;
  39. virtual ~CopyOrMoveFileValidatorFactory() = default;
  40. // This method must always return a non-null validator. |src_url| is needed
  41. // in addition to |platform_path| because in the obfuscated file system
  42. // case, |platform_path| will be an obfuscated filename and extension.
  43. virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
  44. const FileSystemURL& src_url,
  45. const base::FilePath& platform_path) = 0;
  46. protected:
  47. CopyOrMoveFileValidatorFactory() = default;
  48. };
  49. } // namespace storage
  50. #endif // STORAGE_BROWSER_FILE_SYSTEM_COPY_OR_MOVE_FILE_VALIDATOR_H_