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

Unified Diff: Source/modules/beacon/NavigatorBeacon.cpp

Issue 417943005: Add navigator.sendBeacon() use counters. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Supply argument names in decl Created 6 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
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/beacon/NavigatorBeacon.cpp
diff --git a/Source/modules/beacon/NavigatorBeacon.cpp b/Source/modules/beacon/NavigatorBeacon.cpp
index e5182d72afedfef7bcd3ce687fa9fca8bb6af188..e02d84f79347f86348726114c3bd9864fd9fd407 100644
--- a/Source/modules/beacon/NavigatorBeacon.cpp
+++ b/Source/modules/beacon/NavigatorBeacon.cpp
@@ -11,6 +11,7 @@
#include "core/fileapi/Blob.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
+#include "core/frame/UseCounter.h"
#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/html/DOMFormData.h"
#include "core/loader/BeaconLoader.h"
@@ -76,10 +77,15 @@ int NavigatorBeacon::maxAllowance() const
return m_transmittedBytes;
}
-void NavigatorBeacon::updateTransmittedBytes(int length)
+bool NavigatorBeacon::beaconResult(ExecutionContext* context, bool allowed, int sentBytes)
{
- ASSERT(length >= 0);
- m_transmittedBytes += length;
+ if (allowed) {
+ ASSERT(sentBytes >= 0);
+ m_transmittedBytes += sentBytes;
+ } else {
+ UseCounter::count(context, UseCounter::SendBeaconQuotaExceeded);
+ }
+ return allowed;
}
bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, const String& data, ExceptionState& exceptionState)
@@ -95,10 +101,7 @@ bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr
int bytes = 0;
bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- if (result)
- updateTransmittedBytes(bytes);
-
- return result;
+ return beaconResult(context, result, bytes);
}
bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, PassRefPtr<ArrayBufferView> data, ExceptionState& exceptionState)
@@ -114,10 +117,7 @@ bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr
int bytes = 0;
bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- if (result)
- updateTransmittedBytes(bytes);
-
- return result;
+ return beaconResult(context, result, bytes);
}
bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, PassRefPtrWillBeRawPtr<Blob> data, ExceptionState& exceptionState)
@@ -133,10 +133,7 @@ bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr
int bytes = 0;
bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- if (result)
- updateTransmittedBytes(bytes);
-
- return result;
+ return beaconResult(context, result, bytes);
}
bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator, const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState)
@@ -152,10 +149,7 @@ bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr
int bytes = 0;
bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
- if (result)
- updateTransmittedBytes(bytes);
-
- return result;
+ return beaconResult(context, result, bytes);
}
} // namespace blink
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698