| Index: net/base/file_stream.h
|
| ===================================================================
|
| --- net/base/file_stream.h (revision 4000)
|
| +++ net/base/file_stream.h (working copy)
|
| @@ -2,18 +2,17 @@
|
| // source code is governed by a BSD-style license that can be found in the
|
| // LICENSE file.
|
|
|
| -// This file defines FileInputStream, a basic interface for reading files
|
| +// This file defines FileStream, a basic interface for reading and writing files
|
| // synchronously or asynchronously with support for seeking to an offset.
|
| +// Note that even when used asynchronously, only one operation is supported at
|
| +// a time.
|
|
|
| -#ifndef NET_BASE_FILE_INPUT_STREAM_H_
|
| -#define NET_BASE_FILE_INPUT_STREAM_H_
|
| +#ifndef NET_BASE_FILE_STREAM_H_
|
| +#define NET_BASE_FILE_STREAM_H_
|
|
|
| +#include "base/platform_file.h"
|
| #include "net/base/completion_callback.h"
|
|
|
| -#if defined(OS_WIN)
|
| -typedef void* HANDLE;
|
| -#endif
|
| -
|
| namespace net {
|
|
|
| // TODO(darin): Move this to a more generic location.
|
| @@ -24,20 +23,21 @@
|
| FROM_END = 2
|
| };
|
|
|
| -class FileInputStream {
|
| +class FileStream {
|
| public:
|
| - FileInputStream();
|
| - ~FileInputStream();
|
| + FileStream();
|
| + ~FileStream();
|
|
|
| - // Call this method to close the FileInputStream. It is OK to call Close
|
| + // Call this method to close the FileStream. It is OK to call Close
|
| // multiple times. Redundant calls are ignored.
|
| + // Note that if there are any pending async operations, they'll be aborted.
|
| void Close();
|
|
|
| - // Call this method to open the FileInputStream. The remaining methods
|
| + // Call this method to open the FileStream. The remaining methods
|
| // cannot be used unless this method returns OK. If the file cannot be
|
| // opened then an error code is returned.
|
| - // NOTE: The underlying file is opened with non-exclusive access.
|
| - int Open(const std::wstring& path, bool asynchronous_mode);
|
| + // open_flags is a bitfield of base::PlatformFileFlags
|
| + int Open(const std::wstring& path, int open_flags);
|
|
|
| // Returns true if Open succeeded and Close has not been called.
|
| bool IsOpen() const;
|
| @@ -57,7 +57,7 @@
|
| // allowed.) Returns the number of bytes copied, 0 if at end-of-file, or an
|
| // error code if the operation could not be performed.
|
| //
|
| - // If opened with |asynchronous_mode| set to true, then a non-null callback
|
| + // If opened with PLATFORM_FILE_ASYNC, then a non-null callback
|
| // must be passed to this method. In asynchronous mode, if the read could
|
| // not complete synchronously, then ERR_IO_PENDING is returned, and the
|
| // callback will be notified on the current thread (via the MessageLoop) when
|
| @@ -68,25 +68,42 @@
|
| // destroy or close the file stream while there is an asynchronous read in
|
| // progress. That will cancel the read and allow the buffer to be freed.
|
| //
|
| + // This method should not be called if the stream was opened WRITE_ONLY.
|
| int Read(char* buf, int buf_len, CompletionCallback* callback);
|
|
|
| + // Call this method to write data at the current stream position. Up to
|
| + // buf_len bytes will be written from buf. (In other words, partial writes are
|
| + // allowed.) Returns the number of bytes written, or an error code if the
|
| + // operation could not be performed.
|
| + //
|
| + // If opened with PLATFORM_FILE_ASYNC, then a non-null callback
|
| + // must be passed to this method. In asynchronous mode, if the write could
|
| + // not complete synchronously, then ERR_IO_PENDING is returned, and the
|
| + // callback will be notified on the current thread (via the MessageLoop) when
|
| + // the write has completed.
|
| + //
|
| + // In the case of an asychronous write, the memory pointed to by |buf| must
|
| + // remain valid until the callback is notified. However, it is valid to
|
| + // destroy or close the file stream while there is an asynchronous write in
|
| + // progress. That will cancel the write and allow the buffer to be freed.
|
| + //
|
| + // This method should not be called if the stream was opened READ_ONLY.
|
| + int Write(const char* buf, int buf_len, CompletionCallback* callback);
|
| +
|
| private:
|
| class AsyncContext;
|
| friend class AsyncContext;
|
|
|
| // This member is used to support asynchronous reads. It is non-null when
|
| - // the FileInputStream was opened with asynchronous_mode set to true.
|
| + // the FileStream was opened with PLATFORM_FILE_ASYNC.
|
| scoped_ptr<AsyncContext> async_context_;
|
|
|
| -#if defined(OS_WIN)
|
| - HANDLE handle_;
|
| -#elif defined(OS_POSIX)
|
| - int fd_;
|
| -#endif
|
| + base::PlatformFile file_;
|
| + int open_flags_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(FileInputStream);
|
| + DISALLOW_COPY_AND_ASSIGN(FileStream);
|
| };
|
|
|
| } // namespace net
|
|
|
| -#endif // NET_BASE_FILE_INPUT_STREAM_H_
|
| +#endif // NET_BASE_FILE_STREAM_H_
|
|
|
| Property changes on: net\base\file_stream.h
|
| ___________________________________________________________________
|
| Added: svn:mergeinfo
|
| Merged /branches/chrome_webkit_merge_branch/net/base/file_input_stream.h:r69-2775
|
|
|
|
|