Index: Source/core/frame/UseByOriginCounter.cpp |
diff --git a/Source/core/frame/UseByOriginCounter.cpp b/Source/core/frame/UseByOriginCounter.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f4e44973e112e611e016116a1601e07428695fa |
--- /dev/null |
+++ b/Source/core/frame/UseByOriginCounter.cpp |
@@ -0,0 +1,93 @@ |
+/* |
bashi
2015/03/09 23:42:31
nit: Use the 3-line license header.
kojii
2015/03/10 05:06:16
Done, thank you, I missed that.
|
+ * Copyright (C) 2015 Google, Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions |
+ * are met: |
+ * 1. Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * 2. Redistributions in binary form must reproduce the above copyright |
+ * notice, this list of conditions and the following disclaimer in the |
+ * documentation and/or other materials provided with the distribution. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+#include "core/frame/UseByOriginCounter.h" |
+ |
+#include "bindings/core/v8/ScriptState.h" |
+#include "core/dom/Document.h" |
+#include "core/dom/ExecutionContext.h" |
+#include "core/frame/UseCounter.h" |
+ |
+namespace blink { |
+ |
+UseByOriginCounter::Value::Value() |
+ : m_countBits(0) |
+{ |
+} |
+ |
+void UseByOriginCounter::count(const ScriptState* scriptState, Document& document, Feature feature) |
+{ |
+ if (!scriptState || !scriptState->world().isMainWorld()) |
+ return; |
+ document.useByOriginCounterValue().count(feature); |
+} |
+ |
+void UseByOriginCounter::Value::count(Feature feature) |
+{ |
+ ASSERT((unsigned)feature >= 0 && feature < Feature::NumberOfFeatures); |
+ m_countBits |= 1 << (unsigned)feature; |
+} |
+ |
+void UseByOriginCounter::documentDetached(Document& document) |
+{ |
+ UseByOriginCounter::Value counter = document.useByOriginCounterValue(); |
+ if (counter.isEmpty()) |
+ return; |
+ const KURL& url = document.url(); |
+ if (!url.protocolIsInHTTPFamily()) |
+ return; |
+ m_originAndValues.append(std::make_pair(url.host(), counter)); |
+ document.useByOriginCounterValue().clear(); |
+ ASSERT(document.useByOriginCounterValue().isEmpty()); |
+} |
+ |
+void UseByOriginCounter::updateMeasurementsAndClear() |
+{ |
+ if (m_originAndValues.isEmpty()) |
+ return; |
+ |
+ // Aggregate values by origins. |
+ HashMap<String, UseByOriginCounter::Value> aggregatedByOrigin; |
+ for (std::pair<String, UseByOriginCounter::Value>& originAndValue : m_originAndValues) { |
+ ASSERT(!originAndValue.first.isEmpty()); |
+ auto result = aggregatedByOrigin.add(originAndValue.first, originAndValue.second); |
+ if (!result.isNewEntry) |
+ result.storedValue->value.aggregate(originAndValue.second); |
+ } |
+ |
+ // FIXME: Reporting to RAPPOR is not implemented yet. |
+ // for (auto& counter : aggregatedByOrigin) { |
+ // } |
+ |
+ m_originAndValues.clear(); |
+} |
+ |
+void UseByOriginCounter::Value::aggregate(UseByOriginCounter::Value other) |
+{ |
+ m_countBits |= other.m_countBits; |
+} |
+ |
+} // namespace blink |