Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef HostsUsingFeatures_h | 5 #ifndef HostsUsingFeatures_h |
| 6 #define HostsUsingFeatures_h | 6 #define HostsUsingFeatures_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 10 #include "wtf/HashMap.h" | 10 #include "wtf/HashMap.h" |
| 11 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
| 12 #include "wtf/text/StringHash.h" | 12 #include "wtf/text/StringHash.h" |
| 13 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class Document; | 17 class Document; |
| 18 class EventTarget; | 18 class EventTarget; |
| 19 class KURL; | |
| 19 class ScriptState; | 20 class ScriptState; |
| 20 | 21 |
| 21 class CORE_EXPORT HostsUsingFeatures { | 22 class CORE_EXPORT HostsUsingFeatures { |
| 22 DISALLOW_NEW(); | 23 DISALLOW_NEW(); |
| 23 public: | 24 public: |
| 24 ~HostsUsingFeatures(); | 25 ~HostsUsingFeatures(); |
| 25 | 26 |
| 26 // Features for RAPPOR. Do not reorder or remove! | 27 // Features for RAPPOR. Do not reorder or remove! |
| 27 enum class Feature { | 28 enum class Feature { |
| 28 ElementCreateShadowRoot, | 29 ElementCreateShadowRoot, |
| 29 DocumentRegisterElement, | 30 DocumentRegisterElement, |
| 30 EventPath, | 31 EventPath, |
| 31 DeviceMotionInsecureHost, | 32 DeviceMotionInsecureHost, |
| 32 DeviceOrientationInsecureHost, | 33 DeviceOrientationInsecureHost, |
| 33 FullscreenInsecureHost, | 34 FullscreenInsecureHost, |
| 34 GeolocationInsecureHost, | 35 GeolocationInsecureHost, |
| 35 GetUserMediaInsecureHost, | 36 GetUserMediaInsecureHost, |
| 36 GetUserMediaSecureHost, | 37 GetUserMediaSecureHost, |
| 37 ElementAttachShadow, | 38 ElementAttachShadow, |
| 38 ApplicationCacheManifestSelectInsecureHost, | 39 ApplicationCacheManifestSelectInsecureHost, |
| 39 ApplicationCacheAPIInsecureHost, | 40 ApplicationCacheAPIInsecureHost, |
| 41 GetUserMediaInsecureETLDPlus1, | |
| 42 GetUserMediaSecureETLDPlus1, | |
| 40 | 43 |
| 41 NumberOfFeatures // This must be the last item. | 44 NumberOfFeatures // This must be the last item. |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 static void countAnyWorld(Document&, Feature); | 47 static void countAnyWorld(Document&, Feature); |
| 45 static void countMainWorldOnly(const ScriptState*, Document&, Feature); | 48 static void countMainWorldOnly(const ScriptState*, Document&, Feature); |
| 46 static void countHostOrIsolatedWorldHumanReadableName(const ScriptState*, Ev entTarget&, Feature); | 49 static void countHostOrIsolatedWorldHumanReadableName(const ScriptState*, Ev entTarget&, Feature); |
| 47 | 50 |
| 48 void documentDetached(Document&); | 51 void documentDetached(Document&); |
| 49 void updateMeasurementsAndClear(); | 52 void updateMeasurementsAndClear(); |
| 50 | 53 |
| 51 class CORE_EXPORT Value { | 54 class CORE_EXPORT Value { |
| 52 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 55 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 53 public: | 56 public: |
| 54 Value(); | 57 Value(); |
| 55 | 58 |
| 56 bool isEmpty() const { return !m_countBits; } | 59 bool isEmpty() const { return !m_countBits; } |
| 57 void clear() { m_countBits = 0; } | 60 void clear() { m_countBits = 0; } |
| 58 | 61 |
| 59 void count(Feature); | 62 void count(Feature); |
| 60 bool get(Feature feature) const { return m_countBits & (1 << static_cast <unsigned>(feature)); } | 63 bool get(Feature feature) const { return m_countBits & (1 << static_cast <unsigned>(feature)); } |
| 61 | 64 |
| 62 void aggregate(Value); | 65 void aggregate(Value); |
| 63 void recordHostToRappor(const String& host); | 66 void recordURLToRappor(const KURL&); |
| 64 void recordNameToRappor(const String& name); | 67 void recordNameToRappor(const String& name); |
| 65 | 68 |
| 66 private: | 69 private: |
| 67 unsigned m_countBits : static_cast<unsigned>(Feature::NumberOfFeatures); | 70 unsigned m_countBits : static_cast<unsigned>(Feature::NumberOfFeatures); |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 void countName(Feature, const String&); | 73 void countName(Feature, const String&); |
| 71 HashMap<String, Value>& valueByName() { return m_valueByName; } | 74 HashMap<String, Value>& valueByName() { return m_valueByName; } |
| 72 void clear(); | 75 void clear(); |
| 73 | 76 |
| 74 private: | 77 private: |
| 75 void recordHostToRappor(); | 78 void recordURLToRappor(); |
| 76 void recordNamesToRappor(); | 79 void recordNamesToRappor(); |
| 77 | 80 |
| 78 Vector<std::pair<String, HostsUsingFeatures::Value>, 1> m_hostAndValues; | 81 Vector<std::pair<String, HostsUsingFeatures::Value>, 1> m_urlAndValues; |
|
jww
2016/06/11 18:43:21
nit: Why store the serialized URL and not just the
Guido Urdaneta
2016/06/12 11:06:22
Done.
| |
| 79 HashMap<String, HostsUsingFeatures::Value> m_valueByName; | 82 HashMap<String, HostsUsingFeatures::Value> m_valueByName; |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 } // namespace blink | 85 } // namespace blink |
| 83 | 86 |
| 84 #endif // HostsUsingFeatures_h | 87 #endif // HostsUsingFeatures_h |
| OLD | NEW |