OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google, Inc. All rights reserved. | 2 * Copyright (C) 2012 Google, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 // For instance, in Google Chrome, these counts are submitted | 53 // For instance, in Google Chrome, these counts are submitted |
54 // anonymously through the Histogram recording system in Chrome | 54 // anonymously through the Histogram recording system in Chrome |
55 // for users who opt-in to "Usage Statistics" submission | 55 // for users who opt-in to "Usage Statistics" submission |
56 // during their install of Google Chrome: | 56 // during their install of Google Chrome: |
57 // http://www.google.com/chrome/intl/en/privacy.html | 57 // http://www.google.com/chrome/intl/en/privacy.html |
58 | 58 |
59 class CORE_EXPORT UseCounter { | 59 class CORE_EXPORT UseCounter { |
60 DISALLOW_NEW(); | 60 DISALLOW_NEW(); |
61 WTF_MAKE_NONCOPYABLE(UseCounter); | 61 WTF_MAKE_NONCOPYABLE(UseCounter); |
62 public: | 62 public: |
63 UseCounter(); | 63 UseCounter() |
64 ~UseCounter(); | 64 : m_featuresReported(NumberOfFeatures) |
65 , m_CSSFeaturesReported(lastUnresolvedCSSProperty + 1) | |
66 {} | |
65 | 67 |
66 enum Feature { | 68 enum Feature { |
67 // Do not change assigned numbers of existing items: add new features | 69 // Do not change assigned numbers of existing items: add new features |
68 // to the end of the list. | 70 // to the end of the list. |
69 PageDestruction = 0, | 71 PageDestruction = 0, |
70 PrefixedIndexedDB = 3, | 72 PrefixedIndexedDB = 3, |
71 WorkerStart = 4, | 73 WorkerStart = 4, |
72 SharedWorkerStart = 5, | 74 SharedWorkerStart = 5, |
73 UnprefixedIndexedDB = 9, | 75 UnprefixedIndexedDB = 9, |
74 OpenWebDatabase = 10, | 76 OpenWebDatabase = 10, |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 | 1232 |
1231 // Return whether the Feature was previously counted for this document. | 1233 // Return whether the Feature was previously counted for this document. |
1232 // NOTE: only for use in testing. | 1234 // NOTE: only for use in testing. |
1233 static bool isCounted(Document&, Feature); | 1235 static bool isCounted(Document&, Feature); |
1234 // Return whether the CSSPropertyID was previously counted for this document . | 1236 // Return whether the CSSPropertyID was previously counted for this document . |
1235 // NOTE: only for use in testing. | 1237 // NOTE: only for use in testing. |
1236 static bool isCounted(Document&, const String&); | 1238 static bool isCounted(Document&, const String&); |
1237 bool isCounted(CSSPropertyID unresolvedProperty); | 1239 bool isCounted(CSSPropertyID unresolvedProperty); |
1238 | 1240 |
1239 void didCommitLoad(); | 1241 void didCommitLoad(); |
1242 void deprecatedDidCommitFrameLoad() { m_legacyCounter.updateMeasurements(); } | |
1243 | |
1244 void recordMeasurement(Feature); | |
1245 bool hasRecordedMeasurement(Feature feature) const { return m_featuresReport ed.quickGet(feature); } | |
dtapuska
2016/05/31 01:10:51
The semantics of this are changing wrt muted count
| |
1240 | 1246 |
1241 static UseCounter* getFrom(const Document*); | 1247 static UseCounter* getFrom(const Document*); |
1242 static UseCounter* getFrom(const CSSStyleSheet*); | 1248 static UseCounter* getFrom(const CSSStyleSheet*); |
1243 static UseCounter* getFrom(const StyleSheetContents*); | 1249 static UseCounter* getFrom(const StyleSheetContents*); |
1244 | 1250 |
1245 static int mapCSSPropertyIdToCSSSampleIdForHistogram(int id); | 1251 static int mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID); |
1246 | 1252 |
1247 static void muteForInspector(); | 1253 static void muteForInspector(); |
1248 static void unmuteForInspector(); | 1254 static void unmuteForInspector(); |
1249 | 1255 static bool isMuted() { return m_muteCount; } |
1250 void recordMeasurement(Feature feature) { m_countBits.recordMeasurement(feat ure); } | |
1251 void updateMeasurements(); | |
1252 | |
1253 bool hasRecordedMeasurement(Feature feature) const { return m_countBits.hasR ecordedMeasurement(feature); } | |
1254 | |
1255 class CountBits { | |
1256 DISALLOW_NEW(); | |
1257 public: | |
1258 CountBits() : m_bits(NumberOfFeatures) { } | |
1259 | |
1260 bool hasRecordedMeasurement(Feature feature) const | |
1261 { | |
1262 if (UseCounter::m_muteCount) | |
1263 return false; | |
1264 ASSERT(feature != PageDestruction); // PageDestruction is reserved a s a scaling factor. | |
1265 ASSERT(feature < NumberOfFeatures); | |
1266 | |
1267 return m_bits.quickGet(feature); | |
1268 } | |
1269 | |
1270 void recordMeasurement(Feature feature) | |
1271 { | |
1272 if (UseCounter::m_muteCount) | |
1273 return; | |
1274 ASSERT(feature != PageDestruction); // PageDestruction is reserved a s a scaling factor. | |
1275 ASSERT(feature < NumberOfFeatures); | |
1276 | |
1277 m_bits.quickSet(feature); | |
1278 } | |
1279 | |
1280 void updateMeasurements(); | |
1281 | |
1282 private: | |
1283 BitVector m_bits; | |
1284 }; | |
1285 | 1256 |
1286 protected: | 1257 protected: |
1258 BitVector m_featuresReported; | |
1259 BitVector m_CSSFeaturesReported; | |
1260 | |
1287 friend class UseCounterTest; | 1261 friend class UseCounterTest; |
1288 static int m_muteCount; | 1262 static int m_muteCount; |
1289 | 1263 |
1290 CountBits m_countBits; | 1264 private: |
1291 BitVector m_CSSFeatureBits; | 1265 // Encapsulates the work to preserve the old "FeatureObserver" histogram wit h original (buggy) |
1266 // semantics. Will be removed eventually. http://crbug.com/597963 | |
1267 class LegacyCounter { | |
1268 public: | |
1269 LegacyCounter(); | |
1270 ~LegacyCounter(); | |
1271 void recordMeasurement(Feature); | |
1272 void updateMeasurements(); | |
1273 bool hasRecordedMeasurement(Feature) const; | |
dtapuska
2016/05/31 01:10:51
Is this method called anywhere?
| |
1274 void countCSS(CSSPropertyID feature); | |
dtapuska
2016/05/31 01:10:51
Likely using a consistent verbage here is good. Co
| |
1275 | |
1276 private: | |
1277 BitVector m_countBits; | |
1278 BitVector m_CSSFeatureBits; | |
1279 } m_legacyCounter; | |
1292 }; | 1280 }; |
1293 | 1281 |
1294 } // namespace blink | 1282 } // namespace blink |
1295 | 1283 |
1296 #endif // UseCounter_h | 1284 #endif // UseCounter_h |
OLD | NEW |