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

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

Issue 290993006: Pepper: Remove Quota management from TempFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 6 years, 7 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') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h" 5 #include "ppapi/native_client/src/trusted/plugin/temporary_file.h"
6 6
7 #include "native_client/src/include/portability_io.h" 7 #include "native_client/src/include/portability_io.h"
8 #include "native_client/src/shared/platform/nacl_check.h" 8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" 9 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
10 10
11 #include "ppapi/cpp/core.h" 11 #include "ppapi/cpp/core.h"
12 #include "ppapi/cpp/instance.h" 12 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/module.h" 13 #include "ppapi/cpp/module.h"
14 #include "ppapi/c/private/pp_file_handle.h" 14 #include "ppapi/c/private/pp_file_handle.h"
15 15
16 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 16 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
17 #include "ppapi/native_client/src/trusted/plugin/utility.h" 17 #include "ppapi/native_client/src/trusted/plugin/utility.h"
18 18
19
20 //////////////////////////////////////////////////////////////////////
21 // Temporary file access.
22 //////////////////////////////////////////////////////////////////////
23
24 namespace plugin { 19 namespace plugin {
25 20
26 uint32_t TempFile::next_identifier = 0;
27
28 TempFile::TempFile(Plugin* plugin) : plugin_(plugin), 21 TempFile::TempFile(Plugin* plugin) : plugin_(plugin),
29 existing_handle_(PP_kInvalidFileHandle) { 22 existing_handle_(PP_kInvalidFileHandle) {
30 PLUGIN_PRINTF(("TempFile::TempFile\n")); 23 PLUGIN_PRINTF(("TempFile::TempFile\n"));
31 ++next_identifier;
32 SNPRINTF(reinterpret_cast<char *>(identifier_), sizeof identifier_,
33 "%" NACL_PRIu32, next_identifier);
34 } 24 }
35 25
36 TempFile::~TempFile() { 26 TempFile::~TempFile() {
37 PLUGIN_PRINTF(("TempFile::~TempFile\n")); 27 PLUGIN_PRINTF(("TempFile::~TempFile\n"));
38 } 28 }
39 29
40 void TempFile::Open(const pp::CompletionCallback& cb, bool writeable) { 30 void TempFile::Open(const pp::CompletionCallback& cb, bool writeable) {
41 PLUGIN_PRINTF(("TempFile::Open\n")); 31 PLUGIN_PRINTF(("TempFile::Open\n"));
42 PP_FileHandle file_handle; 32 PP_FileHandle file_handle;
43 if (existing_handle_ == PP_kInvalidFileHandle) { 33 if (existing_handle_ == PP_kInvalidFileHandle) {
(...skipping 26 matching lines...) Expand all
70 #else 60 #else
71 int32_t fd = file_handle; 61 int32_t fd = file_handle;
72 #endif 62 #endif
73 63
74 if (fd < 0) { 64 if (fd < 0) {
75 PLUGIN_PRINTF(("TempFile::Open failed\n")); 65 PLUGIN_PRINTF(("TempFile::Open failed\n"));
76 core->CallOnMainThread(0, cb, PP_ERROR_FAILED); 66 core->CallOnMainThread(0, cb, PP_ERROR_FAILED);
77 return; 67 return;
78 } 68 }
79 69
80 // dup the fd to make allow making a non-Quota-based wrapper. 70 // dup the fd to make allow making separate read and write wrappers.
81 // sel_ldr currently does not allow loading from Quota-backed descs,
82 // only plain host descs. It's probably good hygiene to separate the
83 // read wrapper from the write wrapper anyway.
84 int32_t read_fd = DUP(fd); 71 int32_t read_fd = DUP(fd);
85 if (read_fd == NACL_NO_FILE_DESC) { 72 if (read_fd == NACL_NO_FILE_DESC) {
86 PLUGIN_PRINTF(("TempFile::Open DUP failed\n")); 73 PLUGIN_PRINTF(("TempFile::Open DUP failed\n"));
87 core->CallOnMainThread(0, cb, PP_ERROR_FAILED); 74 core->CallOnMainThread(0, cb, PP_ERROR_FAILED);
88 return; 75 return;
89 } 76 }
90 77
91 // The descriptor for a writeable file needs to have quota management.
92 if (writeable) { 78 if (writeable) {
93 write_wrapper_.reset( 79 write_wrapper_.reset(
94 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); 80 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDWR));
95 } 81 }
82
96 read_wrapper_.reset( 83 read_wrapper_.reset(
97 plugin_->wrapper_factory()->MakeFileDesc(read_fd, O_RDONLY)); 84 plugin_->wrapper_factory()->MakeFileDesc(read_fd, O_RDONLY));
98 core->CallOnMainThread(0, cb, PP_OK); 85 core->CallOnMainThread(0, cb, PP_OK);
99 } 86 }
100 87
101 bool TempFile::Reset() { 88 bool TempFile::Reset() {
102 PLUGIN_PRINTF(("TempFile::Reset\n")); 89 PLUGIN_PRINTF(("TempFile::Reset\n"));
103 // Use the read_wrapper_ to reset the file pos. The write_wrapper_ is also 90 // Use the read_wrapper_ to reset the file pos. The write_wrapper_ is also
104 // backed by the same file, so it should also reset. 91 // backed by the same file, so it should also reset.
105 CHECK(read_wrapper_.get() != NULL); 92 CHECK(read_wrapper_.get() != NULL);
106 nacl_off64_t newpos = read_wrapper_->Seek(0, SEEK_SET); 93 nacl_off64_t newpos = read_wrapper_->Seek(0, SEEK_SET);
107 return newpos >= 0; 94 return newpos == 0;
108 } 95 }
109 96
110 } // namespace plugin 97 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/temporary_file.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698