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

Unified Diff: net/base/file_stream_context.h

Issue 323683002: net: FileStream cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments, fix init typo Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: net/base/file_stream_context.h
diff --git a/net/base/file_stream_context.h b/net/base/file_stream_context.h
index c4a06ee1de62c4168675ae47d3150fc65069670b..e89016218843052bf82b415db2ce70b38fd36ceb 100644
--- a/net/base/file_stream_context.h
+++ b/net/base/file_stream_context.h
@@ -33,7 +33,6 @@
#include "base/task_runner.h"
#include "net/base/completion_callback.h"
#include "net/base/file_stream.h"
-#include "net/base/file_stream_whence.h"
#if defined(OS_POSIX)
#include <errno.h>
@@ -50,7 +49,7 @@ class IOBuffer;
#if defined(OS_WIN)
class FileStream::Context : public base::MessageLoopForIO::IOHandler {
#elif defined(OS_POSIX)
-class FileStream::Context {
+class FileStream::Context : public base::MessageLoopForIO::Watcher {
#endif
public:
////////////////////////////////////////////////////////////////////////////
@@ -60,23 +59,23 @@ class FileStream::Context {
explicit Context(const scoped_refptr<base::TaskRunner>& task_runner);
Context(base::File file, const scoped_refptr<base::TaskRunner>& task_runner);
-#if defined(OS_WIN)
virtual ~Context();
-#elif defined(OS_POSIX)
- ~Context();
-#endif
- int ReadAsync(IOBuffer* buf,
- int buf_len,
- const CompletionCallback& callback);
+ int Read(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
- int WriteAsync(IOBuffer* buf,
- int buf_len,
- const CompletionCallback& callback);
+ int ReadNonBlocking(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
- ////////////////////////////////////////////////////////////////////////////
- // Inline methods.
- ////////////////////////////////////////////////////////////////////////////
+ int Write(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
+
+ int WriteNonBlocking(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback);
const base::File& file() const { return file_; }
bool async_in_progress() const { return async_in_progress_; }
@@ -90,23 +89,19 @@ class FileStream::Context {
// not closed yet.
void Orphan();
- void OpenAsync(const base::FilePath& path,
- int open_flags,
- const CompletionCallback& callback);
+ void Open(const base::FilePath& path,
+ int open_flags,
+ const CompletionCallback& callback);
- void CloseAsync(const CompletionCallback& callback);
+ void Close(const CompletionCallback& callback);
- void SeekAsync(Whence whence,
- int64 offset,
- const Int64CompletionCallback& callback);
+ void Seek(base::File::Whence whence,
+ int64 offset,
+ const Int64CompletionCallback& callback);
- void FlushAsync(const CompletionCallback& callback);
+ void Flush(const CompletionCallback& callback);
private:
- ////////////////////////////////////////////////////////////////////////////
- // Platform-independent methods implemented in file_stream_context.cc.
- ////////////////////////////////////////////////////////////////////////////
-
struct IOResult {
IOResult();
IOResult(int64 result, int os_error);
@@ -129,10 +124,16 @@ class FileStream::Context {
IOResult error_code;
};
+ ////////////////////////////////////////////////////////////////////////////
+ // Platform-independent methods implemented in file_stream_context.cc.
+ ////////////////////////////////////////////////////////////////////////////
+
OpenResult OpenFileImpl(const base::FilePath& path, int open_flags);
IOResult CloseFileImpl();
+ IOResult FlushFileImpl();
+
void OnOpenCompleted(const CompletionCallback& callback,
OpenResult open_result);
@@ -140,37 +141,23 @@ class FileStream::Context {
Int64CompletionCallback IntToInt64(const CompletionCallback& callback);
- // Called when asynchronous Open() or Seek()
- // is completed. |result| contains the result or a network error code.
+ // Called when Open() or Seek() completes. |result| contains the result or a
+ // network error code.
void OnAsyncCompleted(const Int64CompletionCallback& callback,
const IOResult& result);
////////////////////////////////////////////////////////////////////////////
- // Helper stuff which is platform-dependent but is used in the platform-
- // independent code implemented in file_stream_context.cc. These helpers were
- // introduced solely to implement as much of the Context methods as
- // possible independently from platform.
- ////////////////////////////////////////////////////////////////////////////
-
-#if defined(OS_WIN)
- int GetLastErrno() { return GetLastError(); }
- void OnAsyncFileOpened();
-#elif defined(OS_POSIX)
- int GetLastErrno() { return errno; }
- void OnAsyncFileOpened() {}
- void CancelIo(base::PlatformFile) {}
-#endif
-
- ////////////////////////////////////////////////////////////////////////////
// Platform-dependent methods implemented in
// file_stream_context_{win,posix}.cc.
////////////////////////////////////////////////////////////////////////////
// Adjusts the position from where the data is read.
- IOResult SeekFileImpl(Whence whence, int64 offset);
+ IOResult SeekFileImpl(base::File::Whence whence, int64 offset);
- // Flushes all data written to the stream.
wtc 2014/06/16 23:01:44 Should we preserve this comment in the new code?
rvargas (doing something else) 2014/06/18 01:36:38 Looks kind of an empty comment to me, especially g
- IOResult FlushFileImpl();
+ void OnFileOpened();
+
+ // The stream is going away.
+ void CancelIO();
#if defined(OS_WIN)
void IOCompletionIsPending(const CompletionCallback& callback, IOBuffer* buf);
@@ -188,17 +175,24 @@ class FileStream::Context {
// signals and calls MapSystemError() to map errno to net error codes.
// It tries to write to completion.
IOResult WriteFileImpl(scoped_refptr<IOBuffer> buf, int buf_len);
+
+ // MessageLoopForIO::Watcher interface
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
+ virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
#endif
base::File file_;
bool async_in_progress_;
bool orphaned_;
scoped_refptr<base::TaskRunner> task_runner_;
+ CompletionCallback callback_;
+ scoped_refptr<IOBuffer> in_flight_buf_;
#if defined(OS_WIN)
base::MessageLoopForIO::IOContext io_context_;
- CompletionCallback callback_;
- scoped_refptr<IOBuffer> in_flight_buf_;
+#elif defined(OS_POSIX)
+ base::MessageLoopForIO::FileDescriptorWatcher file_watcher_;
+ int buf_len_;
wtc 2014/06/16 23:01:44 Document this member. I found that it is used in c
rvargas (doing something else) 2014/06/18 01:36:38 removed
#endif
DISALLOW_COPY_AND_ASSIGN(Context);

Powered by Google App Engine
This is Rietveld 408576698