OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/frame/OriginsUsingFeatures.h" |
| 7 |
| 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "public/platform/Platform.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 OriginsUsingFeatures::~OriginsUsingFeatures() |
| 15 { |
| 16 updateMeasurementsAndClear(); |
| 17 } |
| 18 |
| 19 OriginsUsingFeatures::Value::Value() |
| 20 : m_countBits(0) |
| 21 { |
| 22 } |
| 23 |
| 24 void OriginsUsingFeatures::count(const ScriptState* scriptState, Document& docum
ent, Feature feature) |
| 25 { |
| 26 if (!scriptState || !scriptState->world().isMainWorld()) |
| 27 return; |
| 28 document.originsUsingFeaturesValue().count(feature); |
| 29 } |
| 30 |
| 31 void OriginsUsingFeatures::Value::count(Feature feature) |
| 32 { |
| 33 ASSERT(feature < Feature::NumberOfFeatures); |
| 34 m_countBits |= 1 << static_cast<unsigned>(feature); |
| 35 } |
| 36 |
| 37 void OriginsUsingFeatures::documentDetached(Document& document) |
| 38 { |
| 39 OriginsUsingFeatures::Value counter = document.originsUsingFeaturesValue(); |
| 40 if (counter.isEmpty()) |
| 41 return; |
| 42 |
| 43 const KURL& url = document.url(); |
| 44 if (!url.protocolIsInHTTPFamily()) |
| 45 return; |
| 46 |
| 47 m_originAndValues.append(std::make_pair(url.host(), counter)); |
| 48 document.originsUsingFeaturesValue().clear(); |
| 49 ASSERT(document.originsUsingFeaturesValue().isEmpty()); |
| 50 } |
| 51 |
| 52 void OriginsUsingFeatures::updateMeasurementsAndClear() |
| 53 { |
| 54 if (m_originAndValues.isEmpty()) |
| 55 return; |
| 56 |
| 57 // Aggregate values by origins. |
| 58 HashMap<String, OriginsUsingFeatures::Value> aggregatedByOrigin; |
| 59 for (const auto& originAndValue : m_originAndValues) { |
| 60 ASSERT(!originAndValue.first.isEmpty()); |
| 61 auto result = aggregatedByOrigin.add(originAndValue.first, originAndValu
e.second); |
| 62 if (!result.isNewEntry) |
| 63 result.storedValue->value.aggregate(originAndValue.second); |
| 64 } |
| 65 |
| 66 // Report to RAPPOR. |
| 67 for (auto& originAndValue : aggregatedByOrigin) |
| 68 originAndValue.value.updateMeasurements(originAndValue.key); |
| 69 |
| 70 m_originAndValues.clear(); |
| 71 } |
| 72 |
| 73 void OriginsUsingFeatures::Value::aggregate(OriginsUsingFeatures::Value other) |
| 74 { |
| 75 m_countBits |= other.m_countBits; |
| 76 } |
| 77 |
| 78 void OriginsUsingFeatures::Value::updateMeasurements(const String& origin) |
| 79 { |
| 80 if (get(Feature::ElementCreateShadowRoot)) |
| 81 Platform::current()->recordRappor("WebComponents.ElementCreateShadowRoot
", origin); |
| 82 if (get(Feature::DocumentRegisterElement)) |
| 83 Platform::current()->recordRappor("WebComponents.DocumentRegisterElement
", origin); |
| 84 } |
| 85 |
| 86 } // namespace blink |
OLD | NEW |