When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / webkit / chromeos / fileapi / async_file_stream.h
blobef0eeedf4d63f7178c295c842dfcb38dc5e71064
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
3 // found in the LICENSE file.
5 #ifndef WEBKIT_CHROMEOS_FILEAPI_ASYNC_FILE_STREAM_H_
6 #define WEBKIT_CHROMEOS_FILEAPI_ASYNC_FILE_STREAM_H_
8 #include "base/callback.h"
9 #include "base/platform_file.h"
11 namespace fileapi {
13 using base::PlatformFileError;
15 // This class is used for implementing Open() in FileUtilAsync. This class
16 // is similar to net::FileStream, but supporting only the asynchronous
17 // operations and not necessarily relying on PlatformFile.
18 class AsyncFileStream {
19 public:
20 // Used for Read() and Write(). |result| is the return code of the
21 // operation, and |length| is the length of data read or written.
22 typedef base::Callback<void(PlatformFileError result,
23 int64 length)> ReadWriteCallback;
25 // Used for Seek(). |result| is the return code of the operation.
26 typedef base::Callback<void(PlatformFileError)> SeekCallback;
28 virtual ~AsyncFileStream() {};
30 // Reads data from the current stream position. Up to |length| bytes
31 // will be read from |buffer|. The memory pointed to by |buffer| must
32 // remain valid until the callback is called. On success,
33 // PLATFORM_FILE_OK is passed to |callback| with the number of bytes
34 // read. On failure, an error code is passed instead.
35 virtual void Read(char* buffer,
36 int64 length,
37 const ReadWriteCallback& callback) = 0;
39 // Writes data at the current stream position. Up to |length| bytes will
40 // be written from |buffer|. The memory pointed to by |buffer| must
41 // remain valid until the callback is called. On success,
42 // PLATFORM_FILE_OK is passed to |callback| with the number of bytes
43 // written. On failure, an error code is passed instead.
44 virtual void Write(const char* buffer,
45 int64 length,
46 const ReadWriteCallback& callback) = 0;
48 // Moves the stream position. On success, PLATFORM_FILE_OK is passed to
49 // |callback|. On error, an error code is passed instead.
50 virtual void Seek(int64 offset,
51 const SeekCallback& callback) = 0;
54 } // namespace fileapi
56 #endif // WEBKIT_CHROMEOS_FILEAPI_ASYNC_FILE_STREAM_H_