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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/modules/beacon/NavigatorBeacon.h ('k') | Source/modules/beacon/NavigatorBeacon.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/beacon/NavigatorBeacon.h" 6 #include "modules/beacon/NavigatorBeacon.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "core/dom/ExceptionCode.h" 9 #include "core/dom/ExceptionCode.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
11 #include "core/fileapi/Blob.h" 11 #include "core/fileapi/Blob.h"
12 #include "core/frame/LocalFrame.h" 12 #include "core/frame/LocalFrame.h"
13 #include "core/frame/Settings.h" 13 #include "core/frame/Settings.h"
14 #include "core/frame/UseCounter.h"
14 #include "core/frame/csp/ContentSecurityPolicy.h" 15 #include "core/frame/csp/ContentSecurityPolicy.h"
15 #include "core/html/DOMFormData.h" 16 #include "core/html/DOMFormData.h"
16 #include "core/loader/BeaconLoader.h" 17 #include "core/loader/BeaconLoader.h"
17 #include "wtf/ArrayBufferView.h" 18 #include "wtf/ArrayBufferView.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 NavigatorBeacon::NavigatorBeacon(Navigator& navigator) 22 NavigatorBeacon::NavigatorBeacon(Navigator& navigator)
22 : m_transmittedBytes(0) 23 : m_transmittedBytes(0)
23 , m_navigator(navigator) 24 , m_navigator(navigator)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const Settings* settings = m_navigator.frame()->settings(); 70 const Settings* settings = m_navigator.frame()->settings();
70 if (settings) { 71 if (settings) {
71 int maxAllowed = settings->maxBeaconTransmission(); 72 int maxAllowed = settings->maxBeaconTransmission();
72 if (maxAllowed < m_transmittedBytes) 73 if (maxAllowed < m_transmittedBytes)
73 return 0; 74 return 0;
74 return maxAllowed - m_transmittedBytes; 75 return maxAllowed - m_transmittedBytes;
75 } 76 }
76 return m_transmittedBytes; 77 return m_transmittedBytes;
77 } 78 }
78 79
79 void NavigatorBeacon::updateTransmittedBytes(int length) 80 bool NavigatorBeacon::beaconResult(ExecutionContext* context, bool allowed, int sentBytes)
80 { 81 {
81 ASSERT(length >= 0); 82 if (allowed) {
82 m_transmittedBytes += length; 83 ASSERT(sentBytes >= 0);
84 m_transmittedBytes += sentBytes;
85 } else {
86 UseCounter::count(context, UseCounter::SendBeaconQuotaExceeded);
87 }
88 return allowed;
83 } 89 }
84 90
85 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, const String& data, ExceptionState& exceptionState) 91 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, const String& data, ExceptionState& exceptionState)
86 { 92 {
87 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 93 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
88 } 94 }
89 95
90 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, const String& data, ExceptionState& exceptionState) 96 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, const String& data, ExceptionState& exceptionState)
91 { 97 {
92 KURL url = context->completeURL(urlstring); 98 KURL url = context->completeURL(urlstring);
93 if (!canSendBeacon(context, url, exceptionState)) 99 if (!canSendBeacon(context, url, exceptionState))
94 return false; 100 return false;
95 101
96 int bytes = 0; 102 int bytes = 0;
97 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); 103 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
98 if (result) 104 return beaconResult(context, result, bytes);
99 updateTransmittedBytes(bytes);
100
101 return result;
102 } 105 }
103 106
104 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtr<ArrayBufferView> data, ExceptionState& exc eptionState) 107 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtr<ArrayBufferView> data, ExceptionState& exc eptionState)
105 { 108 {
106 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 109 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
107 } 110 }
108 111
109 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtr<ArrayBufferView> data, ExceptionState& exceptionState) 112 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtr<ArrayBufferView> data, ExceptionState& exceptionState)
110 { 113 {
111 KURL url = context->completeURL(urlstring); 114 KURL url = context->completeURL(urlstring);
112 if (!canSendBeacon(context, url, exceptionState)) 115 if (!canSendBeacon(context, url, exceptionState))
113 return false; 116 return false;
114 117
115 int bytes = 0; 118 int bytes = 0;
116 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); 119 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
117 if (result) 120 return beaconResult(context, result, bytes);
118 updateTransmittedBytes(bytes);
119
120 return result;
121 } 121 }
122 122
123 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtrWillBeRawPtr<Blob> data, ExceptionState& ex ceptionState) 123 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtrWillBeRawPtr<Blob> data, ExceptionState& ex ceptionState)
124 { 124 {
125 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 125 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
126 } 126 }
127 127
128 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtrWillBeRawPtr<Blob> data, ExceptionState& exceptionState) 128 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtrWillBeRawPtr<Blob> data, ExceptionState& exceptionState)
129 { 129 {
130 KURL url = context->completeURL(urlstring); 130 KURL url = context->completeURL(urlstring);
131 if (!canSendBeacon(context, url, exceptionState)) 131 if (!canSendBeacon(context, url, exceptionState))
132 return false; 132 return false;
133 133
134 int bytes = 0; 134 int bytes = 0;
135 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); 135 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
136 if (result) 136 return beaconResult(context, result, bytes);
137 updateTransmittedBytes(bytes);
138
139 return result;
140 } 137 }
141 138
142 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionSt ate& exceptionState) 139 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, Navigator& navigator , const String& urlstring, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionSt ate& exceptionState)
143 { 140 {
144 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState); 141 return NavigatorBeacon::from(navigator).sendBeacon(context, urlstring, data, exceptionState);
145 } 142 }
146 143
147 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState) 144 bool NavigatorBeacon::sendBeacon(ExecutionContext* context, const String& urlstr ing, PassRefPtrWillBeRawPtr<DOMFormData> data, ExceptionState& exceptionState)
148 { 145 {
149 KURL url = context->completeURL(urlstring); 146 KURL url = context->completeURL(urlstring);
150 if (!canSendBeacon(context, url, exceptionState)) 147 if (!canSendBeacon(context, url, exceptionState))
151 return false; 148 return false;
152 149
153 int bytes = 0; 150 int bytes = 0;
154 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes); 151 bool result = BeaconLoader::sendBeacon(m_navigator.frame(), maxAllowance(), url, data, bytes);
155 if (result) 152 return beaconResult(context, result, bytes);
156 updateTransmittedBytes(bytes);
157
158 return result;
159 } 153 }
160 154
161 } // namespace blink 155 } // namespace blink
OLDNEW
« 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