Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: base/platform_file.h

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/platform_file_posix.cc » ('j') | tools/valgrind/memcheck/suppressions.txt » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 BASE_PLATFORM_FILE_H_ 5 #ifndef BASE_PLATFORM_FILE_H_
6 #define BASE_PLATFORM_FILE_H_ 6 #define BASE_PLATFORM_FILE_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 PLATFORM_FILE_ERROR_NO_SPACE = -8, 72 PLATFORM_FILE_ERROR_NO_SPACE = -8,
73 PLATFORM_FILE_ERROR_NOT_A_DIRECTORY = -9, 73 PLATFORM_FILE_ERROR_NOT_A_DIRECTORY = -9,
74 PLATFORM_FILE_ERROR_INVALID_OPERATION = -10, 74 PLATFORM_FILE_ERROR_INVALID_OPERATION = -10,
75 PLATFORM_FILE_ERROR_SECURITY = -11, 75 PLATFORM_FILE_ERROR_SECURITY = -11,
76 PLATFORM_FILE_ERROR_ABORT = -12, 76 PLATFORM_FILE_ERROR_ABORT = -12,
77 PLATFORM_FILE_ERROR_NOT_A_FILE = -13, 77 PLATFORM_FILE_ERROR_NOT_A_FILE = -13,
78 PLATFORM_FILE_ERROR_NOT_EMPTY = -14, 78 PLATFORM_FILE_ERROR_NOT_EMPTY = -14,
79 PLATFORM_FILE_ERROR_INVALID_URL = -15, 79 PLATFORM_FILE_ERROR_INVALID_URL = -15,
80 }; 80 };
81 81
82 // This explicit mapping matches both FILE_ on Windows and SEEK_ on Linux.
83 enum PlatformFileWhence {
84 PLATFORM_FILE_FROM_BEGIN = 0,
85 PLATFORM_FILE_FROM_CURRENT = 1,
86 PLATFORM_FILE_FROM_END = 2
87 };
88
82 // Used to hold information about a given file. 89 // Used to hold information about a given file.
83 // If you add more fields to this structure (platform-specific fields are OK), 90 // If you add more fields to this structure (platform-specific fields are OK),
84 // make sure to update all functions that use it in file_util_{win|posix}.cc 91 // make sure to update all functions that use it in file_util_{win|posix}.cc
85 // too, and the ParamTraits<base::PlatformFileInfo> implementation in 92 // too, and the ParamTraits<base::PlatformFileInfo> implementation in
86 // chrome/common/common_param_traits.cc. 93 // chrome/common/common_param_traits.cc.
87 struct BASE_EXPORT PlatformFileInfo { 94 struct BASE_EXPORT PlatformFileInfo {
88 PlatformFileInfo(); 95 PlatformFileInfo();
89 ~PlatformFileInfo(); 96 ~PlatformFileInfo();
90 97
91 // The size of the file in bytes. Undefined when is_directory is true. 98 // The size of the file in bytes. Undefined when is_directory is true.
(...skipping 20 matching lines...) Expand all
112 // simulate a new file, which can happen with PLATFORM_FILE_CREATE_ALWAYS], and 119 // simulate a new file, which can happen with PLATFORM_FILE_CREATE_ALWAYS], and
113 // false otherwise. |error_code| can be NULL. 120 // false otherwise. |error_code| can be NULL.
114 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name, 121 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name,
115 int flags, 122 int flags,
116 bool* created, 123 bool* created,
117 PlatformFileError* error_code); 124 PlatformFileError* error_code);
118 125
119 // Closes a file handle. Returns |true| on success and |false| otherwise. 126 // Closes a file handle. Returns |true| on success and |false| otherwise.
120 BASE_EXPORT bool ClosePlatformFile(PlatformFile file); 127 BASE_EXPORT bool ClosePlatformFile(PlatformFile file);
121 128
129 // Changes current position in the file to an |offset| relative to an origin
130 // defined by |whence|. Returns the resultant current position in the file
131 // (relative to the start) or -1 in case of error.
132 BASE_EXPORT int64 SeekPlatformFile(PlatformFile file,
133 PlatformFileWhence whence,
134 int64 offset);
135
122 // Reads the given number of bytes (or until EOF is reached) starting with the 136 // Reads the given number of bytes (or until EOF is reached) starting with the
123 // given offset. Returns the number of bytes read, or -1 on error. Note that 137 // given offset. Returns the number of bytes read, or -1 on error. Note that
124 // this function makes a best effort to read all data on all platforms, so it is 138 // this function makes a best effort to read all data on all platforms, so it is
125 // not intended for stream oriented files but instead for cases when the normal 139 // not intended for stream oriented files but instead for cases when the normal
126 // expectation is that actually |size| bytes are read unless there is an error. 140 // expectation is that actually |size| bytes are read unless there is an error.
127 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset, 141 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset,
128 char* data, int size); 142 char* data, int size);
129 143
130 // Same as above but without seek. 144 // Same as above but without seek.
131 BASE_EXPORT int ReadPlatformFileAtCurrentPos(PlatformFile file, 145 BASE_EXPORT int ReadPlatformFileAtCurrentPos(PlatformFile file,
132 char* data, int size); 146 char* data, int size);
133 147
134 // Reads the given number of bytes (or until EOF is reached) starting with the 148 // Reads the given number of bytes (or until EOF is reached) starting with the
135 // given offset, but does not make any effort to read all data on all platforms. 149 // given offset, but does not make any effort to read all data on all platforms.
136 // Returns the number of bytes read, or -1 on error. 150 // Returns the number of bytes read, or -1 on error.
137 BASE_EXPORT int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 151 BASE_EXPORT int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
138 char* data, int size); 152 char* data, int size);
139 153
154 // Same as above but without seek.
155 BASE_EXPORT int ReadPlatformFileCurPosNoBestEffort(PlatformFile file,
156 char* data, int size);
157
140 // Writes the given buffer into the file at the given offset, overwritting any 158 // Writes the given buffer into the file at the given offset, overwritting any
141 // data that was previously there. Returns the number of bytes written, or -1 159 // data that was previously there. Returns the number of bytes written, or -1
142 // on error. Note that this function makes a best effort to write all data on 160 // on error. Note that this function makes a best effort to write all data on
143 // all platforms. 161 // all platforms.
144 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, 162 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset,
145 const char* data, int size); 163 const char* data, int size);
146 164
147 // Save as above but without seek. 165 // Save as above but without seek.
148 BASE_EXPORT int WritePlatformFileAtCurrentPos(PlatformFile file, 166 BASE_EXPORT int WritePlatformFileAtCurrentPos(PlatformFile file,
149 const char* data, int size); 167 const char* data, int size);
150 168
169 // Save as above but does not make any effort to write all data on all
170 // platforms. Returns the number of bytes written, or -1 on error.
171 BASE_EXPORT int WritePlatformFileCurPosNoBestEffort(PlatformFile file,
172 const char* data, int size);
173
151 // Truncates the given file to the given length. If |length| is greater than 174 // Truncates the given file to the given length. If |length| is greater than
152 // the current size of the file, the file is extended with zeros. If the file 175 // the current size of the file, the file is extended with zeros. If the file
153 // doesn't exist, |false| is returned. 176 // doesn't exist, |false| is returned.
154 BASE_EXPORT bool TruncatePlatformFile(PlatformFile file, int64 length); 177 BASE_EXPORT bool TruncatePlatformFile(PlatformFile file, int64 length);
155 178
156 // Flushes the buffers of the given file. 179 // Flushes the buffers of the given file.
157 BASE_EXPORT bool FlushPlatformFile(PlatformFile file); 180 BASE_EXPORT bool FlushPlatformFile(PlatformFile file);
158 181
159 // Touches the given file. 182 // Touches the given file.
160 BASE_EXPORT bool TouchPlatformFile(PlatformFile file, 183 BASE_EXPORT bool TouchPlatformFile(PlatformFile file,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return temp; 221 return temp;
199 } 222 }
200 223
201 private: 224 private:
202 PlatformFile* value_; 225 PlatformFile* value_;
203 }; 226 };
204 227
205 } // namespace base 228 } // namespace base
206 229
207 #endif // BASE_PLATFORM_FILE_H_ 230 #endif // BASE_PLATFORM_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | base/platform_file_posix.cc » ('j') | tools/valgrind/memcheck/suppressions.txt » ('J')

Powered by Google App Engine
This is Rietveld 408576698