| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_FILESYSTEM_UTIL_H_ | 5 #ifndef COMPONENTS_FILESYSTEM_UTIL_H_ |
| 6 #define COMPONENTS_FILESYSTEM_UTIL_H_ | 6 #define COMPONENTS_FILESYSTEM_UTIL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "components/filesystem/public/interfaces/types.mojom.h" | 11 #include "components/filesystem/public/interfaces/types.mojom.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 class String; | 14 class String; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace filesystem { | 17 namespace filesystem { |
| 18 | 18 |
| 19 // Validation functions (typically used to check arguments; they return | 19 // Validation functions (typically used to check arguments; they return |
| 20 // |ERROR_OK| if valid, else the standard/recommended error for the validation | 20 // |ERROR_OK| if valid, else the standard/recommended error for the validation |
| 21 // error): | 21 // error): |
| 22 | 22 |
| 23 // Checks if |path|, which must be non-null, is (looks like) a valid (relative) | 23 // Checks if |path| is (looks like) a valid (relative) path. (On failure, |
| 24 // path. (On failure, returns |ERROR_INVALID_ARGUMENT| if |path| is not UTF-8, | 24 // returns |ERROR_INVALID_ARGUMENT| if |path| is not UTF-8, or |
| 25 // or |ERROR_PERMISSION_DENIED| if it is not relative.) | 25 // |ERROR_PERMISSION_DENIED| if it is not relative.) |
| 26 mojom::FileError IsPathValid(const mojo::String& path); | 26 mojom::FileError IsPathValid(const std::string& path); |
| 27 | 27 |
| 28 // Checks if |whence| is a valid (known) |Whence| value. (On failure, returns | 28 // Checks if |whence| is a valid (known) |Whence| value. (On failure, returns |
| 29 // |ERROR_UNIMPLEMENTED|.) | 29 // |ERROR_UNIMPLEMENTED|.) |
| 30 mojom::FileError IsWhenceValid(mojom::Whence whence); | 30 mojom::FileError IsWhenceValid(mojom::Whence whence); |
| 31 | 31 |
| 32 // Checks if |offset| is a valid file offset (from some point); this is | 32 // Checks if |offset| is a valid file offset (from some point); this is |
| 33 // implementation-dependent (typically checking if |offset| fits in an |off_t|). | 33 // implementation-dependent (typically checking if |offset| fits in an |off_t|). |
| 34 // (On failure, returns |ERROR_OUT_OF_RANGE|.) | 34 // (On failure, returns |ERROR_OUT_OF_RANGE|.) |
| 35 mojom::FileError IsOffsetValid(int64_t offset); | 35 mojom::FileError IsOffsetValid(int64_t offset); |
| 36 | 36 |
| 37 // Conversion functions: | 37 // Conversion functions: |
| 38 | 38 |
| 39 // Returns the platform dependent error details converted to the | 39 // Returns the platform dependent error details converted to the |
| 40 // filesystem.Error enum. | 40 // filesystem.Error enum. |
| 41 mojom::FileError GetError(const base::File& file); | 41 mojom::FileError GetError(const base::File& file); |
| 42 | 42 |
| 43 // Serializes Info to the wire format. | 43 // Serializes Info to the wire format. |
| 44 mojom::FileInformationPtr MakeFileInformation(const base::File::Info& info); | 44 mojom::FileInformationPtr MakeFileInformation(const base::File::Info& info); |
| 45 | 45 |
| 46 // Creates an absolute file path and ensures that we don't try to traverse up. | 46 // Creates an absolute file path and ensures that we don't try to traverse up. |
| 47 mojom::FileError ValidatePath(const mojo::String& raw_path, | 47 mojom::FileError ValidatePath(const std::string& raw_path, |
| 48 const base::FilePath& filesystem_base, | 48 const base::FilePath& filesystem_base, |
| 49 base::FilePath* out); | 49 base::FilePath* out); |
| 50 | 50 |
| 51 } // namespace filesystem | 51 } // namespace filesystem |
| 52 | 52 |
| 53 #endif // COMPONENTS_FILESYSTEM_UTIL_H_ | 53 #endif // COMPONENTS_FILESYSTEM_UTIL_H_ |
| OLD | NEW |