OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 PPAPI_CPP_FILE_REF_H_ | 5 #ifndef PPAPI_CPP_FILE_REF_H_ |
6 #define PPAPI_CPP_FILE_REF_H_ | 6 #define PPAPI_CPP_FILE_REF_H_ |
7 | 7 |
8 #include "ppapi/c/pp_stdint.h" | 8 #include "ppapi/c/pp_stdint.h" |
9 #include "ppapi/c/ppb_file_ref.h" | 9 #include "ppapi/c/ppb_file_ref.h" |
10 #include "ppapi/cpp/resource.h" | 10 #include "ppapi/cpp/resource.h" |
11 #include "ppapi/cpp/var.h" | 11 #include "ppapi/cpp/var.h" |
12 | 12 |
13 /// @file | |
14 /// This file defines the API to create a file reference or "weak pointer" to a | |
15 /// file in a file system. | |
16 | |
13 namespace pp { | 17 namespace pp { |
14 | 18 |
15 class CompletionCallback; | 19 class CompletionCallback; |
16 class FileSystem; | 20 class FileSystem; |
17 | 21 |
22 /// The <code>FileRef</code> class represents a "weak pointer" to a file in | |
23 /// a file system. | |
18 class FileRef : public Resource { | 24 class FileRef : public Resource { |
19 public: | 25 public: |
20 // Creates an is_null() FileRef object. | 26 /// Default constructor for creating an is_null() <code>FileRef</code> |
27 /// object. | |
21 FileRef() {} | 28 FileRef() {} |
22 | 29 |
23 // This constructor is used when we've gotten a PP_Resource as a return value | 30 /// A constructor used when an <code>PP_Resource</code> is provided as a |
24 // that we need to addref. | 31 /// return value whose reference count we need to increment. |
sanga
2011/07/08 00:54:49
return value?
jond
2011/07/08 15:22:35
See previous
On 2011/07/08 00:54:49, sanga wrote:
jond
2011/07/08 15:35:53
Done.
| |
32 /// | |
33 /// @param[in] instance An <code>Instance</code>. | |
25 explicit FileRef(PP_Resource resource); | 34 explicit FileRef(PP_Resource resource); |
26 | 35 |
27 // This constructor is used when we've gotten a PP_Resource as a return value | 36 /// A special structure used by the constructor that does not increment the |
28 // that has already been addref'ed for us. | 37 /// reference count of the underlying file reference. |
29 struct PassRef {}; | 38 struct PassRef {}; |
39 | |
40 /// A constructor used when you have received a PP_Resource as a return | |
41 /// value that has already been reference counted. | |
42 /// | |
43 /// @param[in] resource A PP_Resource corresponding to file reference. | |
30 FileRef(PassRef, PP_Resource resource); | 44 FileRef(PassRef, PP_Resource resource); |
31 | 45 |
32 // Creates a FileRef pointing to a path in the given filesystem. | 46 /// A constructor that creates a weak pointer to a file in the given file |
47 /// system. File paths are POSIX style. | |
48 /// | |
49 /// @param[in] file_system A <code>FileSystem</code> corresponding to a file | |
50 /// system typ. | |
51 /// @param[in] path A path to the file. | |
33 FileRef(const FileSystem& file_system, const char* path); | 52 FileRef(const FileSystem& file_system, const char* path); |
34 | 53 |
54 /// The copy constructor for <code>FileRef</code>. | |
55 /// | |
56 /// @param[in] other A pointer to a <code>FileRef</code>. | |
35 FileRef(const FileRef& other); | 57 FileRef(const FileRef& other); |
36 | 58 |
37 // Returns the file system type. | 59 /// GetFileSystemType() returns the type of the file system. |
60 /// | |
61 /// @return A <code>PP_FileSystemType</code> with the file system type if | |
62 /// valid or <code>PP_FILESYSTEMTYPE_INVALID</code> if the provided resource | |
63 /// is not a valid file reference. | |
38 PP_FileSystemType GetFileSystemType() const; | 64 PP_FileSystemType GetFileSystemType() const; |
39 | 65 |
40 // Returns the name of the file. | 66 /// GetName() returns the name of the file. |
67 /// | |
68 /// @return A <code>Var</code> containing the name of the file. The value | |
69 /// returned by this function does not include any path components (such as | |
70 /// the name of the parent directory, for example). It is just the name of the | |
71 /// file. Use GetPath() to get the full file path. | |
41 Var GetName() const; | 72 Var GetName() const; |
42 | 73 |
43 // Returns the absolute path of the file. See PPB_FileRef::GetPath for more | 74 /// GetPath() returns the absolute path of the file. |
44 // details. | 75 /// |
76 /// @return A <code>Var</code> containing the absolute path of the file. | |
77 /// This function fails if the file system type is | |
78 /// <code>PP_FileSystemType_External</code>. | |
45 Var GetPath() const; | 79 Var GetPath() const; |
46 | 80 |
47 // Returns the parent directory of this file. See PPB_FileRef::GetParent for | 81 /// GetParent() returns the parent directory of this file. If |
48 // more details. | 82 /// <code>file_ref</code> points to the root of the filesystem, then the root |
83 /// is returned. | |
84 /// | |
85 /// @return A <code>FileRef</code> containing the parent directory of the | |
86 /// file. This function fails if the file system type is | |
87 /// <code>PP_FileSystemType_External</code>. | |
49 FileRef GetParent() const; | 88 FileRef GetParent() const; |
50 | 89 |
90 /// MakeDirectory() makes a new directory in the file system. It is not | |
91 /// valid to make a directory in the external file system. | |
92 /// <strong>Note:</strong> Use MakeDirectoryIncludingAncestors() to create | |
93 /// parent directories. | |
94 /// | |
95 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
96 /// completion of MakeDirectory(). | |
97 /// | |
98 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
99 /// Fails if the directory already exists. | |
51 int32_t MakeDirectory(const CompletionCallback& cc); | 100 int32_t MakeDirectory(const CompletionCallback& cc); |
52 | 101 |
102 /// MakeDirectoryIncludingAncestors() makes a new directory in the file | |
103 /// system as well as any parent directories. It is not valid to make a | |
104 /// directory in the external file system. | |
105 /// | |
106 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
107 /// completion of MakeDirectoryIncludingAncestors(). | |
108 /// | |
109 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
110 /// Fails if the directory already exists. | |
53 int32_t MakeDirectoryIncludingAncestors(const CompletionCallback& cc); | 111 int32_t MakeDirectoryIncludingAncestors(const CompletionCallback& cc); |
54 | 112 |
113 /// Touch() Updates time stamps for a file. You must have write access to the | |
114 /// file if it exists in the external filesystem. | |
115 /// | |
116 /// @param[in] last_access_time The last time the file was accessed. | |
117 /// @param[in] last_modified_time The last time the file was modified. | |
118 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
119 /// completion of Touch(). | |
120 /// | |
121 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
55 int32_t Touch(PP_Time last_access_time, | 122 int32_t Touch(PP_Time last_access_time, |
56 PP_Time last_modified_time, | 123 PP_Time last_modified_time, |
57 const CompletionCallback& cc); | 124 const CompletionCallback& cc); |
58 | 125 |
126 /// Delete() deletes a file or directory. If <code>file_ref</code> refers to | |
127 /// a directory, then the directory must be empty. It is an error to delete a | |
128 /// file or directory that is in use. It is not valid to delete a file in | |
129 /// the external file system. | |
130 /// | |
131 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
132 /// completion of Delete(). | |
133 /// | |
134 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
59 int32_t Delete(const CompletionCallback& cc); | 135 int32_t Delete(const CompletionCallback& cc); |
60 | 136 |
137 /// Rename() renames a file or directory. Argument <code>new_file_ref</code> | |
138 /// must refer to files in the same file system as in this object. It is an | |
139 /// error to rename a file or directory that is in use. It is not valid to | |
140 /// rename a file in the external file system. | |
141 /// | |
142 /// @param[in] new_file_ref A <code>FileRef</code> corresponding to a new | |
143 /// file reference. | |
144 /// @param[in] callback A <code>CompletionCallback</code> to be called upon | |
145 /// completion of Rename(). | |
146 /// | |
147 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
61 int32_t Rename(const FileRef& new_file_ref, const CompletionCallback& cc); | 148 int32_t Rename(const FileRef& new_file_ref, const CompletionCallback& cc); |
62 }; | 149 }; |
63 | 150 |
64 } // namespace pp | 151 } // namespace pp |
65 | 152 |
66 #endif // PPAPI_CPP_FILE_REF_H_ | 153 #endif // PPAPI_CPP_FILE_REF_H_ |
OLD | NEW |