Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / filesystem / util.h
blob0a3042bedcde8355827755c1101bf0888fde38ac
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.
5 #ifndef COMPONENTS_FILESYSTEM_UTIL_H_
6 #define COMPONENTS_FILESYSTEM_UTIL_H_
8 #include "base/files/file.h"
9 #include "components/filesystem/public/interfaces/types.mojom.h"
11 namespace mojo {
12 class String;
15 namespace filesystem {
17 // Validation functions (typically used to check arguments; they return
18 // |ERROR_OK| if valid, else the standard/recommended error for the validation
19 // error):
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,
23 // or |ERROR_PERMISSION_DENIED| if it is not relative.)
24 FileError IsPathValid(const mojo::String& path);
26 // Checks if |whence| is a valid (known) |Whence| value. (On failure, returns
27 // |ERROR_UNIMPLEMENTED|.)
28 FileError IsWhenceValid(Whence whence);
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|).
32 // (On failure, returns |ERROR_OUT_OF_RANGE|.)
33 FileError IsOffsetValid(int64_t offset);
35 // Conversion functions:
37 // Returns the platform dependent error details converted to the
38 // filesystem.Error enum.
39 FileError GetError(const base::File& file);
41 // Serializes Info to the wire format.
42 FileInformationPtr MakeFileInformation(const base::File::Info& info);
44 // Creates an absolute file path and ensures that we don't try to traverse up.
45 FileError ValidatePath(const mojo::String& raw_path,
46 const base::FilePath& filesystem_base,
47 base::FilePath* out);
49 } // namespace filesystem
51 #endif // COMPONENTS_FILESYSTEM_UTIL_H_