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

Unified Diff: net/base/file_stream.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, 5 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.h
===================================================================
--- net/base/file_stream.h (revision 145483)
+++ net/base/file_stream.h (working copy)
@@ -41,7 +41,16 @@
// |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.
+ // is destroyed.
+ // Note: if you use this constructor you have 3 options of further usage:
+ // - Only sync operations are used on this stream;
+ // - You wait for completion of all async operations;
+ // - When you finished using stream you call any type of Close*() method
+ // (including possibly CloseAndCancelAsync() or Close() with later
+ // destruction without waiting for closing callback).
+ // If your usage doesn't fall into one of 3 options above you are introducing
+ // use-after-free bug when file descriptor could be used after you close it
+ // (and it possibly gets reopened to another file).
FileStream(base::PlatformFile file, int flags, net::NetLog* net_log);
// If the file stream was opened with Open() or OpenSync(), the underlying
@@ -62,10 +71,16 @@
// 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.
+ // ignored. Note that if there are any pending async operations, then
+ // behavior of this method is equivalent to CloseAndCancelAsync().
virtual void CloseSync();
+ // Call this method to cancel pending async operations and close FileStream
+ // asynchronously without any notification of completion. Method should be
+ // used when you want to quickly destroy FileStream without actually calling
+ // the destructor.
+ virtual void CloseAndCancelAsync();
+
// Call this method to open the FileStream asynchronously. The remaining
// methods cannot be used unless the file is opened successfully. Returns
// ERR_IO_PENDING if the operation is started. If the operation cannot be

Powered by Google App Engine
This is Rietveld 408576698