Skip to content

Commit

Permalink
Storage Service: Add use counter for quota API reads.
Browse files Browse the repository at this point in the history
Bug: 1000932
Change-Id: Ied36040ffd506b13d03af6e64e0cd49c384e12f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789268
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694433}
  • Loading branch information
Staphany Park authored and Commit Bot committed Sep 6, 2019
1 parent c9c6384 commit 59a1198
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,7 @@ enum WebFeature {
kDeprecatedFileSystemWrite = 3026,
kPointerLockUnadjustedMovement = 3027,
kCreateObjectBlob = 3028,
kQuotaRead = 3029,

// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#include "base/location.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/modules/quota/deprecated_storage_quota.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"

namespace blink {

Expand All @@ -45,6 +47,10 @@ void DeprecatedStorageInfo::queryUsageAndQuota(
int storage_type,
V8StorageUsageCallback* success_callback,
V8StorageErrorCallback* error_callback) {
// The BlinkIDL definition for queryUsageAndQuota() already has a [Measure]
// attribute, so the kQuotaRead use counter must be explicitly updated.
UseCounter::Count(ExecutionContext::From(script_state),
WebFeature::kQuotaRead);
// Dispatching the request to DeprecatedStorageQuota, as this interface is
// deprecated in favor of DeprecatedStorageQuota.
DeprecatedStorageQuota* storage_quota = GetStorageQuota(storage_type);
Expand All @@ -64,6 +70,10 @@ void DeprecatedStorageInfo::requestQuota(
uint64_t new_quota_in_bytes,
V8StorageQuotaCallback* success_callback,
V8StorageErrorCallback* error_callback) {
// The BlinkIDL definition for requestQuota() already has a [Measure]
// attribute, so the kQuotaRead use counter must be explicitly updated.
UseCounter::Count(ExecutionContext::From(script_state),
WebFeature::kQuotaRead);
// Dispatching the request to DeprecatedStorageQuota, as this interface is
// deprecated in favor of DeprecatedStorageQuota.
DeprecatedStorageQuota* storage_quota = GetStorageQuota(storage_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_storage_usage_callback.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/modules/quota/dom_error.h"
#include "third_party/blink/renderer/modules/quota/quota_utils.h"
#include "third_party/blink/renderer/modules/quota/storage_estimate.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
Expand Down Expand Up @@ -131,6 +133,10 @@ void DeprecatedStorageQuota::queryUsageAndQuota(
ExecutionContext* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);

// The BlinkIDL definition for queryUsageAndQuota() already has a [Measure]
// attribute, so the kQuotaRead use counter must be explicitly updated.
UseCounter::Count(execution_context, WebFeature::kQuotaRead);

StorageType storage_type = GetStorageType(type_);
if (storage_type != StorageType::kTemporary &&
storage_type != StorageType::kPersistent) {
Expand Down Expand Up @@ -164,7 +170,10 @@ void DeprecatedStorageQuota::requestQuota(
uint64_t new_quota_in_bytes,
V8StorageQuotaCallback* success_callback,
V8StorageErrorCallback* error_callback) {
ExecutionContext& execution_context = *ExecutionContext::From(script_state);
ExecutionContext* execution_context = ExecutionContext::From(script_state);
// The BlinkIDL definition for requestQuota() already has a [Measure]
// attribute, so the kQuotaRead use counter must be explicitly updated.
UseCounter::Count(execution_context, WebFeature::kQuotaRead);

StorageType storage_type = GetStorageType(type_);
if (storage_type != StorageType::kTemporary &&
Expand All @@ -179,15 +188,15 @@ void DeprecatedStorageQuota::requestQuota(
WTF::Bind(&RequestStorageQuotaCallback, WrapPersistent(success_callback),
WrapPersistent(error_callback));

Document& document = To<Document>(execution_context);
Document& document = To<Document>(*execution_context);
const SecurityOrigin* security_origin = document.GetSecurityOrigin();
if (security_origin->IsOpaque()) {
// Unique origins cannot store persistent state.
std::move(callback).Run(blink::mojom::QuotaStatusCode::kErrorAbort, 0, 0);
return;
}

GetQuotaHost(&execution_context)
GetQuotaHost(execution_context)
->RequestStorageQuota(
WrapRefCounted(security_origin), storage_type, new_quota_in_bytes,
mojo::WrapCallbackWithDefaultInvokeIfNotRun(
Expand Down
7 changes: 7 additions & 0 deletions third_party/blink/renderer/modules/quota/storage_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/modules/permissions/permission_utils.h"
#include "third_party/blink/renderer/modules/quota/quota_utils.h"
#include "third_party/blink/renderer/modules/quota/storage_estimate.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"

Expand Down Expand Up @@ -132,6 +134,11 @@ ScriptPromise StorageManager::estimate(ScriptState* script_state) {
ScriptPromise promise = resolver->Promise();
ExecutionContext* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context->IsSecureContext()); // [SecureContext] in IDL

// The BlinkIDL definition for estimate() already has a [MeasureAs] attribute,
// so the kQuotaRead use counter must be explicitly updated.
UseCounter::Count(execution_context, WebFeature::kQuotaRead);

const SecurityOrigin* security_origin =
execution_context->GetSecurityOrigin();
if (security_origin->IsOpaque()) {
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24606,6 +24606,7 @@ Called by update_net_error_codes.py.-->
<int value="3026" label="DeprecatedFileSystemWrite"/>
<int value="3027" label="PointerLockUnadjustedMovement"/>
<int value="3028" label="CreateObjectBlob"/>
<int value="3029" label="QuotaRead"/>
</enum>

<enum name="FeaturePolicyAllowlistType">
Expand Down

0 comments on commit 59a1198

Please sign in to comment.