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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/temporary_file.cc

Issue 10815080: Add an interface for nacl to create delete-on-close temp files, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert buildbot hack Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/temporary_file.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "native_client/src/trusted/plugin/temporary_file.h"
6
7 #include "native_client/src/include/portability_io.h"
8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/plugin/plugin.h"
10 #include "native_client/src/trusted/plugin/utility.h"
11 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
12
13 #include "ppapi/cpp/core.h"
14 #include "ppapi/cpp/instance.h"
15 #include "ppapi/cpp/module.h"
16 #include "ppapi/c/private/pp_file_handle.h"
17
18
19 //////////////////////////////////////////////////////////////////////
20 // Temporary file access.
21 //////////////////////////////////////////////////////////////////////
22
23 namespace plugin {
24
25 uint32_t TempFile::next_identifier = 0;
26
27 TempFile::TempFile(Plugin* plugin) : plugin_(plugin) {
28 PLUGIN_PRINTF(("TempFile::TempFile\n"));
29 ++next_identifier;
30 SNPRINTF(reinterpret_cast<char *>(identifier_), sizeof identifier_,
31 "%"NACL_PRIu32, next_identifier);
32 }
33
34 TempFile::~TempFile() {
35 PLUGIN_PRINTF(("TempFile::~TempFile\n"));
36 }
37
38 void TempFile::Open(const pp::CompletionCallback& cb) {
39 PLUGIN_PRINTF(("TempFile::Open\n"));
40 PP_FileHandle file_handle =
41 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance());
42
43 pp::Core* core = pp::Module::Get()->core();
44 if (file_handle == PP_kInvalidFileHandle) {
45 PLUGIN_PRINTF(("TempFile::Open failed w/ PP_kInvalidFileHandle\n"));
46 core->CallOnMainThread(0, cb, PP_ERROR_FAILED);
47 }
48
49 #if NACL_WINDOWS
50 HANDLE handle = file_handle;
51
52 //////// Now try the posix view.
53 int32_t posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(handle),
54 _O_RDWR | _O_BINARY
55 | _O_TEMPORARY | _O_SHORT_LIVED );
56 if (posix_desc == -1) {
57 PLUGIN_PRINTF(("TempFile::Open failed to convert HANDLE to posix\n"));
58 // Close the Windows HANDLE if it can't be converted.
59 CloseHandle(handle);
60 }
61 int32_t fd = posix_desc;
62 #else
63 int32_t fd = file_handle;
64 #endif
65
66 if (fd < 0) {
67 PLUGIN_PRINTF(("TempFile::Open failed\n"));
68 core->CallOnMainThread(0, cb, PP_ERROR_FAILED);
69 return;
70 }
71
72 // The descriptor for a writeable file needs to have quota management.
73 wrapper_.reset(
74 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_));
75 core->CallOnMainThread(0, cb, PP_OK);
76 }
77
78 bool TempFile::Reset() {
79 PLUGIN_PRINTF(("TempFile::Reset\n"));
80 CHECK(wrapper_.get() != NULL);
81 nacl_off64_t newpos = wrapper_->Seek(0, SEEK_SET);
82 return newpos >= 0;
83 }
84
85 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/temporary_file.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698