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

Unified Diff: ppapi/native_client/src/trusted/plugin/service_runtime.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, 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
Index: ppapi/native_client/src/trusted/plugin/service_runtime.cc
diff --git a/ppapi/native_client/src/trusted/plugin/service_runtime.cc b/ppapi/native_client/src/trusted/plugin/service_runtime.cc
index f58f0c56509f573c92036fbb14419f5bed630ceb..3ea07ee48ac183fb331a44d3fd51c2867684e153 100644
--- a/ppapi/native_client/src/trusted/plugin/service_runtime.cc
+++ b/ppapi/native_client/src/trusted/plugin/service_runtime.cc
@@ -59,6 +59,14 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/file_io.h"
+namespace {
+
+// For doing crude quota enforcement on writes to temp files.
+// We do not allow a temp file bigger than 512 MB for now.
+const uint64_t kMaxTempQuota = 0x20000000;
+
+} // namespace
+
namespace plugin {
PluginReverseInterface::PluginReverseInterface(
@@ -433,23 +441,44 @@ void PluginReverseInterface::QuotaRequest_MainThreadContinuation(
if (err != PP_OK) {
return;
}
- const PPB_FileIOTrusted* file_io_trusted =
- static_cast<const PPB_FileIOTrusted*>(
- pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE));
- // Copy the request object because this one will be deleted on return.
- QuotaRequest* cont_for_response = new QuotaRequest(*request); // copy ctor!
- pp::CompletionCallback quota_cc = WeakRefNewCallback(
- anchor_,
- this,
- &PluginReverseInterface::QuotaRequest_MainThreadResponse,
- cont_for_response);
- file_io_trusted->WillWrite(request->resource,
- request->offset,
- // TODO(sehr): remove need for cast.
- // Unify WillWrite interface vs Quota request.
- nacl::assert_cast<int32_t>(
- request->bytes_requested),
- quota_cc.pp_completion_callback());
+
+ switch (request->data.type) {
+ case plugin::PepperQuotaType: {
+ const PPB_FileIOTrusted* file_io_trusted =
+ static_cast<const PPB_FileIOTrusted*>(
+ pp::Module::Get()->GetBrowserInterface(
+ PPB_FILEIOTRUSTED_INTERFACE));
+ // Copy the request object because this one will be deleted on return.
+ // copy ctor!
+ QuotaRequest* cont_for_response = new QuotaRequest(*request);
+ pp::CompletionCallback quota_cc = WeakRefNewCallback(
+ anchor_,
+ this,
+ &PluginReverseInterface::QuotaRequest_MainThreadResponse,
+ cont_for_response);
+ file_io_trusted->WillWrite(request->data.resource,
+ request->offset,
+ // TODO(sehr): remove need for cast.
+ // Unify WillWrite interface vs Quota request.
+ nacl::assert_cast<int32_t>(
+ request->bytes_requested),
+ quota_cc.pp_completion_callback());
+ break;
+ }
+ case plugin::TempQuotaType: {
+ uint64_t len = request->offset + request->bytes_requested;
+ nacl::MutexLocker take(&mu_);
+ // Do some crude quota enforcement.
+ if (len > kMaxTempQuota) {
+ *request->bytes_granted = 0;
+ } else {
+ *request->bytes_granted = request->bytes_requested;
+ }
+ *request->op_complete_ptr = true;
+ NaClXCondVarBroadcast(&cv_);
+ break;
+ }
+ }
// request automatically deleted
}
@@ -460,7 +489,8 @@ void PluginReverseInterface::QuotaRequest_MainThreadResponse(
"PluginReverseInterface::QuotaRequest_MainThreadResponse:"
" (resource=%"NACL_PRIx32", offset=%"NACL_PRId64", requested=%"
NACL_PRId64", err=%"NACL_PRId32")\n",
- request->resource, request->offset, request->bytes_requested, err);
+ request->data.resource,
+ request->offset, request->bytes_requested, err);
nacl::MutexLocker take(&mu_);
if (err >= PP_OK) {
*request->bytes_granted = err;
@@ -478,7 +508,7 @@ int64_t PluginReverseInterface::RequestQuotaForWrite(
"PluginReverseInterface::RequestQuotaForWrite:"
" (file_id='%s', offset=%"NACL_PRId64", bytes_to_write=%"
NACL_PRId64")\n", file_id.c_str(), offset, bytes_to_write);
- PP_Resource resource;
+ QuotaData quota_data;
{
nacl::MutexLocker take(&mu_);
uint64_t file_key = STRTOULL(file_id.c_str(), NULL, 10);
@@ -487,13 +517,13 @@ int64_t PluginReverseInterface::RequestQuotaForWrite(
NaClLog(4, "PluginReverseInterface::RequestQuotaForWrite: failed...\n");
return 0;
}
- resource = quota_map_[file_key];
+ quota_data = quota_map_[file_key];
}
// Variables set by requesting quota.
int64_t quota_granted = 0;
bool op_complete = false;
QuotaRequest* continuation =
- new QuotaRequest(resource, offset, bytes_to_write, &quota_granted,
+ new QuotaRequest(quota_data, offset, bytes_to_write, &quota_granted,
&op_complete);
// The reverse service is running on a background thread and the PPAPI quota
// methods must be invoked only from the main thread.
@@ -529,7 +559,18 @@ void PluginReverseInterface::AddQuotaManagedFile(const nacl::string& file_id,
file_id.c_str(), resource);
nacl::MutexLocker take(&mu_);
uint64_t file_key = STRTOULL(file_id.c_str(), NULL, 10);
- quota_map_[file_key] = resource;
+ QuotaData data(plugin::PepperQuotaType, resource);
+ quota_map_[file_key] = data;
+}
+
+void PluginReverseInterface::AddTempQuotaManagedFile(
+ const nacl::string& file_id) {
+ PLUGIN_PRINTF(("PluginReverseInterface::AddTempQuotaManagedFile: "
+ "(file_id='%s')\n", file_id.c_str()));
+ nacl::MutexLocker take(&mu_);
+ uint64_t file_key = STRTOULL(file_id.c_str(), NULL, 10);
+ QuotaData data(plugin::TempQuotaType, 0);
+ quota_map_[file_key] = data;
}
ServiceRuntime::ServiceRuntime(Plugin* plugin,
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/service_runtime.h ('k') | ppapi/native_client/src/trusted/plugin/temporary_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698