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

Unified Diff: Source/core/frame/UseByOriginCounter.cpp

Issue 986583002: Collect host of Web Component usage to send to RAPPOR (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move to Platform to align with other histogram/UMA methods Created 5 years, 9 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
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..6be2da0b66a2e0c7ec2ffd0c4e4f4f42b61ad69f
--- /dev/null
+++ b/Source/core/frame/UseByOriginCounter.cpp
@@ -0,0 +1,86 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/frame/UseByOriginCounter.h"
+
+#include "bindings/core/v8/ScriptState.h"
+#include "core/dom/Document.h"
+#include "public/platform/Platform.h"
+
+namespace blink {
+
+UseByOriginCounter::~UseByOriginCounter()
+{
+ updateMeasurementsAndClear();
+}
+
+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);
tkent 2015/03/16 00:30:19 We don't use C-style cast. (unsigned) -> static_c
kojii 2015/03/16 03:52:51 Done.
+ 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) {
tkent 2015/03/16 00:30:19 nit: You can use |const auto&| here.
kojii 2015/03/16 03:52:51 Done.
+ ASSERT(!originAndValue.first.isEmpty());
+ auto result = aggregatedByOrigin.add(originAndValue.first, originAndValue.second);
+ if (!result.isNewEntry)
+ result.storedValue->value.aggregate(originAndValue.second);
+ }
+
+ // Report to RAPPOR.
+ for (auto& originAndValue : aggregatedByOrigin)
+ originAndValue.value.updateMeasurements(originAndValue.key);
+
+ m_originAndValues.clear();
+}
+
+void UseByOriginCounter::Value::aggregate(UseByOriginCounter::Value other)
+{
+ m_countBits |= other.m_countBits;
+}
+
+void UseByOriginCounter::Value::updateMeasurements(const String& origin)
+{
+ if (get(Feature::ElementCreateShadowRoot))
+ Platform::current()->recordRappor("WebComponents.ElementCreateShadowRoot", origin);
+ if (get(Feature::DocumentRegisterElement))
+ Platform::current()->recordRappor("WebComponents.DocumentRegisterElement", origin);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698