1 /* Copyright (c) 2012 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.
7 * This file defines the API to create a file reference or "weak pointer" to a
8 * file in a file system.
17 * The <code>PPB_FileRef</code> struct represents a "weak pointer" to a file in
18 * a file system. This struct contains a <code>PP_FileSystemType</code>
19 * identifier and a file path string.
21 interface PPB_FileRef
{
23 * Create() creates a weak pointer to a file in the given file system. File
24 * paths are POSIX style.
26 * @param[in] resource A <code>PP_Resource</code> corresponding to a file
28 * @param[in] path A path to the file.
30 * @return A <code>PP_Resource</code> corresponding to a file reference if
31 * successful or 0 if the path is malformed.
33 PP_Resource Create
([in] PP_Resource file_system
, [in] str_t path
);
35 * IsFileRef() determines if the provided resource is a file reference.
37 * @param[in] resource A <code>PP_Resource</code> corresponding to a file
40 * @return <code>PP_TRUE</code> if the resource is a
41 * <code>PPB_FileRef</code>, <code>PP_FALSE</code> if the resource is
42 * invalid or some type other than <code>PPB_FileRef</code>.
44 PP_Bool IsFileRef
([in] PP_Resource resource
);
47 * GetFileSystemType() returns the type of the file system.
49 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
52 * @return A <code>PP_FileSystemType</code> with the file system type if
53 * valid or <code>PP_FILESYSTEMTYPE_INVALID</code> if the provided resource
54 * is not a valid file reference.
56 PP_FileSystemType GetFileSystemType
([in] PP_Resource file_ref
);
59 * GetName() returns the name of the file.
61 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
64 * @return A <code>PP_Var</code> containing the name of the file. The value
65 * returned by this function does not include any path components (such as
66 * the name of the parent directory, for example). It is just the name of the
67 * file. Use GetPath() to get the full file path.
69 PP_Var GetName
([in] PP_Resource file_ref
);
72 * GetPath() returns the absolute path of the file.
74 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
77 * @return A <code>PP_Var</code> containing the absolute path of the file.
78 * This function fails if the file system type is
79 * <code>PP_FileSystemType_External</code>.
81 PP_Var GetPath
([in] PP_Resource file_ref
);
84 * GetParent() returns the parent directory of this file. If
85 * <code>file_ref</code> points to the root of the filesystem, then the root
88 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
91 * @return A <code>PP_Resource</code> containing the parent directory of the
92 * file. This function fails if the file system type is
93 * <code>PP_FileSystemType_External</code>.
95 PP_Resource GetParent
([in] PP_Resource file_ref
);
98 * MakeDirectory() makes a new directory in the file system as well as any
99 * parent directories if the <code>make_ancestors</code> argument is
100 * <code>PP_TRUE</code>. It is not valid to make a directory in the external
103 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
105 * @param[in] make_ancestors A <code>PP_Bool</code> set to
106 * <code>PP_TRUE</code> to make ancestor directories or <code>PP_FALSE</code>
107 * if ancestor directories are not needed.
109 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
110 * Fails if the directory already exists or if ancestor directories do not
111 * exist and <code>make_ancestors</code> was not passed as
112 * <code>PP_TRUE</code>.
114 int32_t MakeDirectory
([in] PP_Resource directory_ref
,
115 [in] PP_Bool make_ancestors
,
116 [in] PP_CompletionCallback
callback);
119 * Touch() Updates time stamps for a file. You must have write access to the
120 * file if it exists in the external filesystem.
122 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
124 * @param[in] last_access_time The last time the file was accessed.
125 * @param[in] last_modified_time The last time the file was modified.
126 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
127 * completion of Touch().
129 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
131 int32_t Touch
([in] PP_Resource file_ref
,
132 [in] PP_Time last_access_time
,
133 [in] PP_Time last_modified_time
,
134 [in] PP_CompletionCallback
callback);
137 * Delete() deletes a file or directory. If <code>file_ref</code> refers to
138 * a directory, then the directory must be empty. It is an error to delete a
139 * file or directory that is in use. It is not valid to delete a file in
140 * the external file system.
142 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
144 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
145 * completion of Delete().
147 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
149 int32_t Delete
([in] PP_Resource file_ref
,
150 [in] PP_CompletionCallback
callback);
153 * Rename() renames a file or directory. Arguments <code>file_ref</code> and
154 * <code>new_file_ref</code> must both refer to files in the same file
155 * system. It is an error to rename a file or directory that is in use. It
156 * is not valid to rename a file in the external file system.
158 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
160 * @param[in] new_file_ref A <code>PP_Resource</code> corresponding to a new
162 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
163 * completion of Rename().
165 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
167 int32_t Rename
([in] PP_Resource file_ref
,
168 [in] PP_Resource new_file_ref
,
169 [in] PP_CompletionCallback
callback);
172 * Query() queries info about a file or directory. You must have access to
173 * read this file or directory if it exists in the external filesystem.
175 * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file
177 * @param[out] info A pointer to a <code>PP_FileInfo</code> which will be
178 * populated with information about the file or directory.
179 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
180 * completion of Query().
182 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
185 int32_t Query
([in] PP_Resource file_ref
,
186 [out] PP_FileInfo info
,
187 [in] PP_CompletionCallback
callback);