diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 23:05:15 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-30 23:05:15 +0000 |
commit | 21ae1f956c163bc0e3b3e239b5c027a7ac93ae7f (patch) | |
tree | 4eee3fe37f83559b1a97f75dcdef0337b68e2cf1 /base/platform_file.h | |
parent | 0436fcd542e8ce436fe9395a64cc03fa369276b1 (diff) | |
download | chromium_src-21ae1f956c163bc0e3b3e239b5c027a7ac93ae7f.zip chromium_src-21ae1f956c163bc0e3b3e239b5c027a7ac93ae7f.tar.gz chromium_src-21ae1f956c163bc0e3b3e239b5c027a7ac93ae7f.tar.bz2 |
Asynchronously open the temp file used for Pepper StreamToFile, and delete the
temp file once we are done with it.
We observe ResourceHandle::OnRequestClosed as a signal of when we should delete
the temp file. This corresponds to the WebURLLoader being closed (or
canceled).
This patch also includes some helpers:
base/scoped_callback_factory.h
This class makes it easy to allocate Callbacks that hold a weak reference
back to the owning class. It works just like ScopedRunnableMethodFactory
but for Callbacks instead of RunnableMethods.
base/platform_file.h
Added a PassPlatformFile class that is useful for cases where a callback may
decide not to take ownership of a PlatformFile (as can happen when using
ScopedCallbackFactory).
chrome/file_system_proxy.{h,cc}
This class provides static methods for executing file system commands on the
FILE thread. It routes callbacks back to the originating thread to deliver
results (file handles, etc.). Note: this file declares a few functions that
are not yet used. I anticipate that we'll make use of these and add more
functions here to support the Pepper and OWP FileSystem APIs.
chrome/chrome_thread_relay.{h,cc}
This class is a helper class for proxying calls over to a background
ChromeThread and then returning results to the originating ChromeThread.
R=brettw
BUG=49789
TEST=(more to be added in third_party/ppapi/tests)
Review URL: http://codereview.chromium.org/2878062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_file.h')
-rw-r--r-- | base/platform_file.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/base/platform_file.h b/base/platform_file.h index 3571e24..43f8511 100644 --- a/base/platform_file.h +++ b/base/platform_file.h @@ -54,6 +54,44 @@ PlatformFile CreatePlatformFile(const std::wstring& name, // 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_ |