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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef UseCounter_h | 26 #ifndef UseCounter_h |
27 #define UseCounter_h | 27 #define UseCounter_h |
28 | 28 |
| 29 #include <v8.h> |
29 #include "core/CSSPropertyNames.h" | 30 #include "core/CSSPropertyNames.h" |
30 #include "core/CoreExport.h" | 31 #include "core/CoreExport.h" |
31 #include "core/css/parser/CSSParserMode.h" | 32 #include "core/css/parser/CSSParserMode.h" |
| 33 #include "platform/heap/GarbageCollected.h" |
| 34 #include "platform/heap/HeapAllocator.h" |
32 #include "platform/weborigin/KURL.h" | 35 #include "platform/weborigin/KURL.h" |
33 #include "wtf/BitVector.h" | 36 #include "wtf/BitVector.h" |
34 #include "wtf/Noncopyable.h" | 37 #include "wtf/Noncopyable.h" |
35 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
36 #include <v8.h> | |
37 | 39 |
38 namespace blink { | 40 namespace blink { |
39 | 41 |
40 class CSSStyleSheet; | 42 class CSSStyleSheet; |
41 class Document; | 43 class Document; |
42 class EnumerationHistogram; | 44 class EnumerationHistogram; |
43 class ExecutionContext; | 45 class ExecutionContext; |
44 class Frame; | 46 class Frame; |
45 class StyleSheetContents; | 47 class StyleSheetContents; |
46 | 48 |
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 PointerEventSetCaptureOutsideDispatch = 1806, | 1459 PointerEventSetCaptureOutsideDispatch = 1806, |
1458 NotificationPermissionRequestedInsecureOrigin = 1807, | 1460 NotificationPermissionRequestedInsecureOrigin = 1807, |
1459 | 1461 |
1460 // Add new features immediately above this line. Don't change assigned | 1462 // Add new features immediately above this line. Don't change assigned |
1461 // numbers of any item, and don't reuse removed slots. | 1463 // numbers of any item, and don't reuse removed slots. |
1462 // Also, run update_use_counter_feature_enum.py in | 1464 // Also, run update_use_counter_feature_enum.py in |
1463 // chromium/src/tools/metrics/histograms/ to update the UMA mapping. | 1465 // chromium/src/tools/metrics/histograms/ to update the UMA mapping. |
1464 NumberOfFeatures, // This enum value must be last. | 1466 NumberOfFeatures, // This enum value must be last. |
1465 }; | 1467 }; |
1466 | 1468 |
| 1469 // An interface to observe UseCounter changes. |
| 1470 class Observer : public GarbageCollected<Observer> { |
| 1471 public: |
| 1472 // Returns true if this observer no longer needs to observe the counter. |
| 1473 virtual bool onCountFeature(Feature) = 0; |
| 1474 |
| 1475 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 1476 }; |
| 1477 |
1467 // "count" sets the bit for this feature to 1. Repeated calls are ignored. | 1478 // "count" sets the bit for this feature to 1. Repeated calls are ignored. |
1468 static void count(const Frame*, Feature); | 1479 static void count(const Frame*, Feature); |
1469 static void count(const Document&, Feature); | 1480 static void count(const Document&, Feature); |
1470 static void count(ExecutionContext*, Feature); | 1481 static void count(ExecutionContext*, Feature); |
1471 | 1482 |
1472 void count(CSSParserMode, CSSPropertyID); | 1483 void count(CSSParserMode, CSSPropertyID); |
1473 void count(Feature); | 1484 void count(Feature); |
1474 | 1485 |
1475 // Count only features if they're being used in an iframe which does not | 1486 // Count only features if they're being used in an iframe which does not |
1476 // have script access into the top level document. | 1487 // have script access into the top level document. |
1477 static void countCrossOriginIframe(const Document&, Feature); | 1488 static void countCrossOriginIframe(const Document&, Feature); |
1478 | 1489 |
1479 // Return whether the Feature was previously counted for this document. | 1490 // Return whether the Feature was previously counted for this document. |
1480 // NOTE: only for use in testing. | 1491 // NOTE: only for use in testing. |
1481 static bool isCounted(Document&, Feature); | 1492 static bool isCounted(Document&, Feature); |
1482 // Return whether the CSSPropertyID was previously counted for this document. | 1493 // Return whether the CSSPropertyID was previously counted for this document. |
1483 // NOTE: only for use in testing. | 1494 // NOTE: only for use in testing. |
1484 static bool isCounted(Document&, const String&); | 1495 static bool isCounted(Document&, const String&); |
1485 bool isCounted(CSSPropertyID unresolvedProperty); | 1496 bool isCounted(CSSPropertyID unresolvedProperty); |
1486 | 1497 |
| 1498 // Adds an observer that observes UseCounter changes. |
| 1499 static void addObserver(Document&, Observer*); |
| 1500 |
1487 // Invoked when a new document is loaded into the main frame of the page. | 1501 // Invoked when a new document is loaded into the main frame of the page. |
1488 void didCommitLoad(KURL); | 1502 void didCommitLoad(KURL); |
1489 | 1503 |
1490 static int mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID); | 1504 static int mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID); |
1491 | 1505 |
1492 // When muted, all calls to "count" functions are ignoed. May be nested. | 1506 // When muted, all calls to "count" functions are ignoed. May be nested. |
1493 void muteForInspector(); | 1507 void muteForInspector(); |
1494 void unmuteForInspector(); | 1508 void unmuteForInspector(); |
1495 | 1509 |
1496 void recordMeasurement(Feature); | 1510 void recordMeasurement(Feature); |
1497 | 1511 |
1498 // Return whether the feature has been seen since the last page load | 1512 // Return whether the feature has been seen since the last page load |
1499 // (except when muted). Does include features seen in documents which have | 1513 // (except when muted). Does include features seen in documents which have |
1500 // reporting disabled. | 1514 // reporting disabled. |
1501 bool hasRecordedMeasurement(Feature) const; | 1515 bool hasRecordedMeasurement(Feature) const; |
1502 | 1516 |
| 1517 DECLARE_TRACE(); |
| 1518 |
1503 private: | 1519 private: |
1504 EnumerationHistogram& featuresHistogram() const; | 1520 EnumerationHistogram& featuresHistogram() const; |
1505 EnumerationHistogram& cssHistogram() const; | 1521 EnumerationHistogram& cssHistogram() const; |
1506 | 1522 |
1507 // If non-zero, ignore all 'count' calls completely. | 1523 // If non-zero, ignore all 'count' calls completely. |
1508 unsigned m_muteCount; | 1524 unsigned m_muteCount; |
1509 | 1525 |
1510 // If true, disable reporting all histogram entries. | 1526 // If true, disable reporting all histogram entries. |
1511 bool m_disableReporting; | 1527 bool m_disableReporting; |
1512 | 1528 |
1513 // The scope represented by this UseCounter instance. | 1529 // The scope represented by this UseCounter instance. |
1514 Context m_context; | 1530 Context m_context; |
1515 | 1531 |
1516 // Track what features/properties have been reported to the (non-legacy) | 1532 // Track what features/properties have been reported to the (non-legacy) |
1517 // histograms. | 1533 // histograms. |
1518 BitVector m_featuresRecorded; | 1534 BitVector m_featuresRecorded; |
1519 BitVector m_CSSRecorded; | 1535 BitVector m_CSSRecorded; |
1520 | 1536 |
| 1537 HeapHashSet<Member<Observer>> m_observers; |
| 1538 |
1521 // Encapsulates the work to preserve the old "FeatureObserver" histogram with | 1539 // Encapsulates the work to preserve the old "FeatureObserver" histogram with |
1522 // original semantics | 1540 // original semantics |
1523 // TODO(rbyers): remove this - http://crbug.com/676837 | 1541 // TODO(rbyers): remove this - http://crbug.com/676837 |
1524 class CORE_EXPORT LegacyCounter { | 1542 class CORE_EXPORT LegacyCounter { |
1525 public: | 1543 public: |
1526 LegacyCounter(); | 1544 LegacyCounter(); |
1527 ~LegacyCounter(); | 1545 ~LegacyCounter(); |
1528 void countFeature(Feature); | 1546 void countFeature(Feature); |
1529 void countCSS(CSSPropertyID); | 1547 void countCSS(CSSPropertyID); |
1530 void updateMeasurements(); | 1548 void updateMeasurements(); |
1531 | 1549 |
1532 private: | 1550 private: |
1533 // Tracks what features/properties need to be reported to the legacy | 1551 // Tracks what features/properties need to be reported to the legacy |
1534 // histograms. | 1552 // histograms. |
1535 BitVector m_featureBits; | 1553 BitVector m_featureBits; |
1536 BitVector m_CSSBits; | 1554 BitVector m_CSSBits; |
1537 } m_legacyCounter; | 1555 } m_legacyCounter; |
1538 }; | 1556 }; |
1539 | 1557 |
1540 } // namespace blink | 1558 } // namespace blink |
1541 | 1559 |
1542 #endif // UseCounter_h | 1560 #endif // UseCounter_h |
OLD | NEW |