Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/WebKit/Source/core/frame/UseCounter.h

Issue 2680423006: UseCounter: Introduce UseCounter::Observer for layout tests (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
47 // UseCounter is used for counting the number of times features of 49 // UseCounter is used for counting the number of times features of
48 // Blink are used on real web pages and help us know commonly 50 // Blink are used on real web pages and help us know commonly
49 // features are used and thus when it's safe to remove or change them. 51 // features are used and thus when it's safe to remove or change them.
50 // 52 //
51 // The Chromium Content layer controls what is done with this data. 53 // The Chromium Content layer controls what is done with this data.
52 // 54 //
53 // For instance, in Google Chrome, these counts are submitted anonymously 55 // For instance, in Google Chrome, these counts are submitted anonymously
54 // through the UMA histogram recording system in Chrome for users who have the 56 // through the UMA histogram recording system in Chrome for users who have the
55 // "Automatically send usage statistics and crash reports to Google" setting 57 // "Automatically send usage statistics and crash reports to Google" setting
56 // enabled: 58 // enabled:
57 // http://www.google.com/chrome/intl/en/privacy.html 59 // http://www.google.com/chrome/intl/en/privacy.html
58 60 //
61 // Changes on UseCounter are observable by UseCounter::Observer.
59 class CORE_EXPORT UseCounter { 62 class CORE_EXPORT UseCounter {
60 DISALLOW_NEW(); 63 DISALLOW_NEW();
61 WTF_MAKE_NONCOPYABLE(UseCounter); 64 WTF_MAKE_NONCOPYABLE(UseCounter);
62 65
63 public: 66 public:
64 enum Context { 67 enum Context {
65 DefaultContext, 68 DefaultContext,
66 // Counters for SVGImages (lifetime independent from other pages). 69 // Counters for SVGImages (lifetime independent from other pages).
67 SVGImageContext 70 SVGImageContext
68 }; 71 };
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 V8DeprecatedStorageQuota_RequestQuota_Method = 1811, 1463 V8DeprecatedStorageQuota_RequestQuota_Method = 1811,
1461 V8FileReaderSync_Constructor = 1812, 1464 V8FileReaderSync_Constructor = 1812,
1462 1465
1463 // Add new features immediately above this line. Don't change assigned 1466 // Add new features immediately above this line. Don't change assigned
1464 // numbers of any item, and don't reuse removed slots. 1467 // numbers of any item, and don't reuse removed slots.
1465 // Also, run update_use_counter_feature_enum.py in 1468 // Also, run update_use_counter_feature_enum.py in
1466 // chromium/src/tools/metrics/histograms/ to update the UMA mapping. 1469 // chromium/src/tools/metrics/histograms/ to update the UMA mapping.
1467 NumberOfFeatures, // This enum value must be last. 1470 NumberOfFeatures, // This enum value must be last.
1468 }; 1471 };
1469 1472
1473 // An interface to observe UseCounter changes. Note that this is never
1474 // notified when the counter is disabled by |m_muteCount| or
1475 // |m_disableReporting|.
1476 class Observer : public GarbageCollected<Observer> {
1477 public:
1478 // Notified when a feature is counted for the first time. This should return
1479 // true if it no longer needs to observe changes so that the counter can
1480 // remove a reference to the observer and stop notifications.
1481 virtual bool onCountFeature(Feature) = 0;
1482
1483 DEFINE_INLINE_VIRTUAL_TRACE() {}
1484 };
1485
1470 // "count" sets the bit for this feature to 1. Repeated calls are ignored. 1486 // "count" sets the bit for this feature to 1. Repeated calls are ignored.
1471 static void count(const Frame*, Feature); 1487 static void count(const Frame*, Feature);
1472 static void count(const Document&, Feature); 1488 static void count(const Document&, Feature);
1473 static void count(ExecutionContext*, Feature); 1489 static void count(ExecutionContext*, Feature);
1474 1490
1475 void count(CSSParserMode, CSSPropertyID); 1491 void count(CSSParserMode, CSSPropertyID);
1476 void count(Feature); 1492 void count(Feature);
1477 1493
1478 // Count only features if they're being used in an iframe which does not 1494 // Count only features if they're being used in an iframe which does not
1479 // have script access into the top level document. 1495 // have script access into the top level document.
1480 static void countCrossOriginIframe(const Document&, Feature); 1496 static void countCrossOriginIframe(const Document&, Feature);
1481 1497
1482 // Return whether the Feature was previously counted for this document. 1498 // Return whether the Feature was previously counted for this document.
1483 // NOTE: only for use in testing. 1499 // NOTE: only for use in testing.
1484 static bool isCounted(Document&, Feature); 1500 static bool isCounted(Document&, Feature);
1485 // Return whether the CSSPropertyID was previously counted for this document. 1501 // Return whether the CSSPropertyID was previously counted for this document.
1486 // NOTE: only for use in testing. 1502 // NOTE: only for use in testing.
1487 static bool isCounted(Document&, const String&); 1503 static bool isCounted(Document&, const String&);
1488 bool isCounted(CSSPropertyID unresolvedProperty); 1504 bool isCounted(CSSPropertyID unresolvedProperty);
1489 1505
1506 // Adds an observer to Document's UseCounter. UseCounter retains a reference
1507 // to the observer.
1508 static void addObserver(Document&, Observer*);
1509
1490 // Invoked when a new document is loaded into the main frame of the page. 1510 // Invoked when a new document is loaded into the main frame of the page.
1491 void didCommitLoad(KURL); 1511 void didCommitLoad(KURL);
1492 1512
1493 static int mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID); 1513 static int mapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID);
1494 1514
1495 // When muted, all calls to "count" functions are ignoed. May be nested. 1515 // When muted, all calls to "count" functions are ignoed. May be nested.
1496 void muteForInspector(); 1516 void muteForInspector();
1497 void unmuteForInspector(); 1517 void unmuteForInspector();
1498 1518
1499 void recordMeasurement(Feature); 1519 void recordMeasurement(Feature);
1500 1520
1501 // Return whether the feature has been seen since the last page load 1521 // Return whether the feature has been seen since the last page load
1502 // (except when muted). Does include features seen in documents which have 1522 // (except when muted). Does include features seen in documents which have
1503 // reporting disabled. 1523 // reporting disabled.
1504 bool hasRecordedMeasurement(Feature) const; 1524 bool hasRecordedMeasurement(Feature) const;
1505 1525
1526 DECLARE_TRACE();
1527
1506 private: 1528 private:
1529 // Notifies that a feature is newly counted to |m_observers|. This shouldn't
1530 // be called when the counter is disabled by |m_muteCount| or
1531 // |m_disableReporting|.
1532 void notifyFeatureCounted(Feature);
1533
1507 EnumerationHistogram& featuresHistogram() const; 1534 EnumerationHistogram& featuresHistogram() const;
1508 EnumerationHistogram& cssHistogram() const; 1535 EnumerationHistogram& cssHistogram() const;
1509 1536
1510 // If non-zero, ignore all 'count' calls completely. 1537 // If non-zero, ignore all 'count' calls completely.
1511 unsigned m_muteCount; 1538 unsigned m_muteCount;
1512 1539
1513 // If true, disable reporting all histogram entries. 1540 // If true, disable reporting all histogram entries.
1514 bool m_disableReporting; 1541 bool m_disableReporting;
1515 1542
1516 // The scope represented by this UseCounter instance. 1543 // The scope represented by this UseCounter instance.
1517 Context m_context; 1544 Context m_context;
1518 1545
1519 // Track what features/properties have been reported to the (non-legacy) 1546 // Track what features/properties have been reported to the (non-legacy)
1520 // histograms. 1547 // histograms.
1521 BitVector m_featuresRecorded; 1548 BitVector m_featuresRecorded;
1522 BitVector m_CSSRecorded; 1549 BitVector m_CSSRecorded;
1523 1550
1551 HeapHashSet<Member<Observer>> m_observers;
1552
1524 // Encapsulates the work to preserve the old "FeatureObserver" histogram with 1553 // Encapsulates the work to preserve the old "FeatureObserver" histogram with
1525 // original semantics 1554 // original semantics
1526 // TODO(rbyers): remove this - http://crbug.com/676837 1555 // TODO(rbyers): remove this - http://crbug.com/676837
1527 class CORE_EXPORT LegacyCounter { 1556 class CORE_EXPORT LegacyCounter {
1528 public: 1557 public:
1529 LegacyCounter(); 1558 LegacyCounter();
1530 ~LegacyCounter(); 1559 ~LegacyCounter();
1531 void countFeature(Feature); 1560 void countFeature(Feature);
1532 void countCSS(CSSPropertyID); 1561 void countCSS(CSSPropertyID);
1533 void updateMeasurements(); 1562 void updateMeasurements();
1534 1563
1535 private: 1564 private:
1536 // Tracks what features/properties need to be reported to the legacy 1565 // Tracks what features/properties need to be reported to the legacy
1537 // histograms. 1566 // histograms.
1538 BitVector m_featureBits; 1567 BitVector m_featureBits;
1539 BitVector m_CSSBits; 1568 BitVector m_CSSBits;
1540 } m_legacyCounter; 1569 } m_legacyCounter;
1541 }; 1570 };
1542 1571
1543 } // namespace blink 1572 } // namespace blink
1544 1573
1545 #endif // UseCounter_h 1574 #endif // UseCounter_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698