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

Unified Diff: ppapi/native_client/src/trusted/plugin/file_downloader.h

Issue 147083014: Introduce NaClFileInfoAutoCloser as an RAII wrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 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: ppapi/native_client/src/trusted/plugin/file_downloader.h
diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.h b/ppapi/native_client/src/trusted/plugin/file_downloader.h
index 4fd7997cc92555f5e8294ad43868636e9af3b0c7..b3f381084cfa50542a2abbdb95b8363502651c93 100644
--- a/ppapi/native_client/src/trusted/plugin/file_downloader.h
+++ b/ppapi/native_client/src/trusted/plugin/file_downloader.h
@@ -41,6 +41,35 @@ typedef std::vector<char>* FileStreamData;
typedef CallbackSource<FileStreamData> StreamCallbackSource;
typedef pp::CompletionCallbackWithOutput<FileStreamData> StreamCallback;
+// RAII-style wrapper class
+class NaClFileInfoAutoCloser {
+ public:
+ NaClFileInfoAutoCloser();
+
+ NaClFileInfoAutoCloser(NaClFileInfo pass_ownership);
dmichael (off chromium) 2014/01/29 18:22:28 nit: explicit
bsy 2014/01/29 20:51:28 Done. Thanks, this was careless of me.
+
+ ~NaClFileInfoAutoCloser() {
+ FreeResources();
+ }
+
+ void FreeResources(); // Frees owned resources
dmichael (off chromium) 2014/01/29 18:22:28 nit: comment should go above the method. Ditto rel
bsy 2014/01/29 20:51:28 Done.
+
+ void set(NaClFileInfo pass_ownership);
+
+ // Return NaClFileInfo for temporary use, retaining ownership.
+ NaClFileInfo get() { return info_; }
+
+ // Returns POSIX descriptor for temporary use, retaining ownership.
+ int get_desc() { return info_.desc; }
+
+ NaClFileInfo release(); // Returns ownership to caller
dmichael (off chromium) 2014/01/29 18:22:28 nit: Probably should be capitalized, since it's se
bsy 2014/01/29 20:51:28 Done.
+
+ private:
+ NACL_DISALLOW_COPY_AND_ASSIGN(NaClFileInfoAutoCloser);
+
+ NaClFileInfo info_;
+};
+
// A class that wraps PPAPI URLLoader and FileIO functionality for downloading
// the url into a file and providing an open file descriptor.
class FileDownloader {
@@ -51,7 +80,6 @@ class FileDownloader {
: instance_(NULL),
file_open_notify_callback_(pp::BlockUntilComplete()),
stream_finish_callback_(pp::BlockUntilComplete()),
- file_handle_(PP_kInvalidFileHandle),
file_io_private_interface_(NULL),
url_loader_trusted_interface_(NULL),
open_time_(-1),
@@ -185,8 +213,6 @@ class FileDownloader {
pp::CompletionCallback file_open_notify_callback_;
pp::CompletionCallback stream_finish_callback_;
pp::FileIO file_reader_;
- PP_FileHandle file_handle_;
- struct NaClFileToken file_token_;
const PPB_FileIO_Private* file_io_private_interface_;
const PPB_URLLoaderTrusted* url_loader_trusted_interface_;
pp::URLLoader url_loader_;
@@ -200,7 +226,7 @@ class FileDownloader {
std::deque<char> buffer_;
UrlSchemeType url_scheme_;
StreamCallbackSource* data_stream_callback_source_;
- NaClFileInfo cached_file_info_;
+ NaClFileInfoAutoCloser file_info_;
};
} // namespace plugin;
#endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_

Powered by Google App Engine
This is Rietveld 408576698