| 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 76fb5789b4794f97717eb5d86b752d9bc9e2fa74..844f382771578084d32fb6645c91a78efba79a12 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, "a_granted,
|
| + new QuotaRequest(quota_data, offset, bytes_to_write, "a_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,
|
|
|