Index: net/base/file_stream.h |
=================================================================== |
--- net/base/file_stream.h (revision 151422) |
+++ net/base/file_stream.h (working copy) |
@@ -15,11 +15,6 @@ |
#include "net/base/file_stream_whence.h" |
#include "net/base/net_export.h" |
#include "net/base/net_log.h" |
-#if defined(OS_WIN) |
-#include "net/base/file_stream_win.h" |
-#elif defined(OS_POSIX) |
-#include "net/base/file_stream_posix.h" |
-#endif |
class FilePath; |
@@ -39,8 +34,8 @@ |
// opened. |
// |net_log| is the net log pointer to use to create a |BoundNetLog|. May be |
// NULL if logging is not needed. |
- // The already opened file will not be automatically closed when FileStream |
- // is destructed. |
+ // Note: the new FileStream object takes ownership of the PlatformFile and |
+ // will close it on destruction. |
FileStream(base::PlatformFile file, int flags, net::NetLog* net_log); |
// If the file stream was opened with Open() or OpenSync(), the underlying |
@@ -62,7 +57,8 @@ |
// Call this method to close the FileStream synchronously. |
// It is OK to call CloseSync() multiple times. Redundant calls are |
// ignored. Note that if there are any pending async operations, they'll |
- // be aborted. |
+ // be aborted and actual closing of the stream will happen asynchronously |
+ // (to avoid races with async operation). |
virtual void CloseSync(); |
// Call this method to open the FileStream asynchronously. The remaining |
@@ -216,12 +212,21 @@ |
base::PlatformFile GetPlatformFileForTesting(); |
private: |
-#if defined(OS_WIN) |
- FileStreamWin impl_; |
-#elif defined(OS_POSIX) |
- FileStreamPosix impl_; |
-#endif |
+ class Context; |
+ bool is_async() { return !!(open_flags_ & base::PLATFORM_FILE_ASYNC); } |
willchan no longer on Chromium
2012/09/11 23:05:02
make this const?
|
+ |
+ int open_flags_; |
+ net::BoundNetLog bound_net_log_; |
+ |
+ // Context performing I/O operations. It was extracted into separate class |
+ // to perform asynchronous operations because FileStream can be destroyed |
+ // before completion of async operation. Also if async FileStream is destroyed |
+ // without explicit closing file should be closed asynchronously without |
+ // delaying FileStream's destructor. To perform all that separate object is |
+ // necessary. |
+ scoped_ptr<Context> context_; |
+ |
DISALLOW_COPY_AND_ASSIGN(FileStream); |
}; |