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/UseByOriginCounter.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 UseByOriginCounter::~UseByOriginCounter() | |
15 { | |
16 updateMeasurementsAndClear(); | |
17 } | |
18 | |
19 UseByOriginCounter::Value::Value() | |
20 : m_countBits(0) | |
21 { | |
22 } | |
23 | |
24 void UseByOriginCounter::count(const ScriptState* scriptState, Document& documen t, Feature feature) | |
25 { | |
26 if (!scriptState || !scriptState->world().isMainWorld()) | |
27 return; | |
28 document.useByOriginCounterValue().count(feature); | |
29 } | |
30 | |
31 void UseByOriginCounter::Value::count(Feature feature) | |
32 { | |
33 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.
| |
34 m_countBits |= 1 << (unsigned)feature; | |
35 } | |
36 | |
37 void UseByOriginCounter::documentDetached(Document& document) | |
38 { | |
39 UseByOriginCounter::Value counter = document.useByOriginCounterValue(); | |
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.useByOriginCounterValue().clear(); | |
49 ASSERT(document.useByOriginCounterValue().isEmpty()); | |
50 } | |
51 | |
52 void UseByOriginCounter::updateMeasurementsAndClear() | |
53 { | |
54 if (m_originAndValues.isEmpty()) | |
55 return; | |
56 | |
57 // Aggregate values by origins. | |
58 HashMap<String, UseByOriginCounter::Value> aggregatedByOrigin; | |
59 for (std::pair<String, UseByOriginCounter::Value>& originAndValue : m_origin AndValues) { | |
tkent
2015/03/16 00:30:19
nit: You can use |const auto&| here.
kojii
2015/03/16 03:52:51
Done.
| |
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 UseByOriginCounter::Value::aggregate(UseByOriginCounter::Value other) | |
74 { | |
75 m_countBits |= other.m_countBits; | |
76 } | |
77 | |
78 void UseByOriginCounter::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 |