util.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2015 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 COMPONENTS_SERVICES_FILESYSTEM_UTIL_H_
  5. #define COMPONENTS_SERVICES_FILESYSTEM_UTIL_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/files/file.h"
  9. #include "components/services/filesystem/public/mojom/types.mojom.h"
  10. namespace filesystem {
  11. // Validation functions (typically used to check arguments; they return
  12. // |ERROR_OK| if valid, else the standard/recommended error for the validation
  13. // error):
  14. // Checks if |path| is (looks like) a valid (relative) path. (On failure,
  15. // returns |ERROR_INVALID_ARGUMENT| if |path| is not UTF-8, or
  16. // |ERROR_PERMISSION_DENIED| if it is not relative.)
  17. base::File::Error IsPathValid(const std::string& path);
  18. // Checks if |whence| is a valid (known) |Whence| value. (On failure, returns
  19. // |ERROR_UNIMPLEMENTED|.)
  20. base::File::Error IsWhenceValid(mojom::Whence whence);
  21. // Checks if |offset| is a valid file offset (from some point); this is
  22. // implementation-dependent (typically checking if |offset| fits in an |off_t|).
  23. // (On failure, returns |ERROR_OUT_OF_RANGE|.)
  24. base::File::Error IsOffsetValid(int64_t offset);
  25. // Conversion functions:
  26. // Returns the platform dependent error details converted to the
  27. // filesystem.Error enum.
  28. base::File::Error GetError(const base::File& file);
  29. // Serializes Info to the wire format.
  30. mojom::FileInformationPtr MakeFileInformation(const base::File::Info& info);
  31. // Creates an absolute file path and ensures that we don't try to traverse up.
  32. base::File::Error ValidatePath(const std::string& raw_path,
  33. const base::FilePath& filesystem_base,
  34. base::FilePath* out);
  35. } // namespace filesystem
  36. #endif // COMPONENTS_SERVICES_FILESYSTEM_UTIL_H_