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

Unified Diff: base/platform_file.h

Issue 2878062: Asynchronously open the temp file used for Pepper StreamToFile, and delete th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « base/base.gypi ('k') | base/scoped_callback_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/platform_file.h
===================================================================
--- base/platform_file.h (revision 54397)
+++ base/platform_file.h (working copy)
@@ -54,6 +54,44 @@
// Closes a file handle
bool ClosePlatformFile(PlatformFile file);
+// Use this class to pass ownership of a PlatformFile to a receiver that may or
+// may not want to accept it. This class does not own the storage for the
+// PlatformFile.
+//
+// EXAMPLE:
+//
+// void MaybeProcessFile(PassPlatformFile pass_file) {
+// if (...) {
+// PlatformFile file = pass_file.ReleaseValue();
+// // Now, we are responsible for closing |file|.
+// }
+// }
+//
+// void OpenAndMaybeProcessFile(const FilePath& path) {
+// PlatformFile file = CreatePlatformFile(path, ...);
+// MaybeProcessFile(PassPlatformFile(&file));
+// if (file != kInvalidPlatformFileValue)
+// ClosePlatformFile(file);
+// }
+//
+class PassPlatformFile {
+ public:
+ explicit PassPlatformFile(PlatformFile* value) : value_(value) {
+ }
+
+ // Called to retrieve the PlatformFile stored in this object. The caller
+ // gains ownership of the PlatformFile and is now responsible for closing it.
+ // Any subsequent calls to this method will return an invalid PlatformFile.
+ PlatformFile ReleaseValue() {
+ PlatformFile temp = *value_;
+ *value_ = kInvalidPlatformFileValue;
+ return temp;
+ }
+
+ private:
+ PlatformFile* value_;
+};
+
} // namespace base
#endif // BASE_PLATFORM_FILE_H_
« no previous file with comments | « base/base.gypi ('k') | base/scoped_callback_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698