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