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

Side by Side Diff: sky/engine/core/frame/UseCounter.cpp

Issue 867903002: Remove UseCounter (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/engine/core/frame/UseCounter.h ('k') | sky/engine/core/html/HTMLAnchorElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright (C) 2012 Google, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "sky/engine/config.h"
28 #include "sky/engine/core/frame/UseCounter.h"
29
30 #include "sky/engine/core/css/CSSStyleSheet.h"
31 #include "sky/engine/core/css/StyleSheetContents.h"
32 #include "sky/engine/core/dom/Document.h"
33 #include "sky/engine/core/dom/ExecutionContext.h"
34 #include "sky/engine/core/frame/FrameConsole.h"
35 #include "sky/engine/core/frame/FrameHost.h"
36 #include "sky/engine/core/frame/LocalDOMWindow.h"
37 #include "sky/engine/core/frame/LocalFrame.h"
38 #include "sky/engine/core/inspector/ConsoleMessage.h"
39 #include "sky/engine/public/platform/Platform.h"
40
41 namespace blink {
42
43 int UseCounter::m_muteCount = 0;
44
45 void UseCounter::muteForInspector()
46 {
47 UseCounter::m_muteCount++;
48 }
49
50 void UseCounter::unmuteForInspector()
51 {
52 UseCounter::m_muteCount--;
53 }
54
55 UseCounter::UseCounter()
56 {
57 m_CSSFeatureBits.ensureSize(lastCSSProperty + 1);
58 m_CSSFeatureBits.clearAll();
59 }
60
61 UseCounter::~UseCounter()
62 {
63 // We always log PageDestruction so that we have a scale for the rest of the features.
64 blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver", PageDestruction, NumberOfFeatures);
65
66 updateMeasurements();
67 }
68
69 void UseCounter::updateMeasurements()
70 {
71 blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver", PageVisits, NumberOfFeatures);
72
73 if (m_countBits) {
74 for (unsigned i = 0; i < NumberOfFeatures; ++i) {
75 if (m_countBits->quickGet(i))
76 blink::Platform::current()->histogramEnumeration("WebCore.Featur eObserver", i, NumberOfFeatures);
77 }
78 // Clearing count bits is timing sensitive.
79 m_countBits->clearAll();
80 }
81
82 m_CSSFeatureBits.clearAll();
83 }
84
85 void UseCounter::didCommitLoad()
86 {
87 updateMeasurements();
88 }
89
90 void UseCounter::count(const Document& document, Feature feature)
91 {
92 FrameHost* host = document.frameHost();
93 if (!host)
94 return;
95
96 ASSERT(host->useCounter().deprecationMessage(feature).isEmpty());
97 host->useCounter().recordMeasurement(feature);
98 }
99
100 void UseCounter::count(const ExecutionContext* context, Feature feature)
101 {
102 if (!context)
103 return;
104 count(*toDocument(context), feature);
105 }
106
107 void UseCounter::countDeprecation(ExecutionContext* context, Feature feature)
108 {
109 if (!context)
110 return;
111 UseCounter::countDeprecation(*toDocument(context), feature);
112 }
113
114 void UseCounter::countDeprecation(const LocalDOMWindow* window, Feature feature)
115 {
116 if (!window || !window->document())
117 return;
118 UseCounter::countDeprecation(*window->document(), feature);
119 }
120
121 void UseCounter::countDeprecation(const Document& document, Feature feature)
122 {
123 FrameHost* host = document.frameHost();
124 LocalFrame* frame = document.frame();
125 if (!host || !frame)
126 return;
127
128 if (host->useCounter().recordMeasurement(feature)) {
129 ASSERT(!host->useCounter().deprecationMessage(feature).isEmpty());
130 frame->console().addMessage(ConsoleMessage::create(DeprecationMessageSou rce, WarningMessageLevel, host->useCounter().deprecationMessage(feature)));
131 }
132 }
133
134 // FIXME: Update other UseCounter::deprecationMessage() cases to use this.
135 static String replacedBy(const char* oldString, const char* newString)
136 {
137 return String::format("'%s' is deprecated. Please use '%s' instead.", oldStr ing, newString);
138 }
139
140 String UseCounter::deprecationMessage(Feature feature)
141 {
142 switch (feature) {
143 // Quota
144 case PrefixedStorageInfo:
145 return "'window.webkitStorageInfo' is deprecated. Please use 'navigator. webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.";
146
147 // Keyboard Event (DOM Level 3)
148 case KeyboardEventKeyLocation:
149 return replacedBy("KeyboardEvent.keyLocation", "KeyboardEvent.location") ;
150
151 case ConsoleMarkTimeline:
152 return "console.markTimeline is deprecated. Please use the console.timeS tamp instead.";
153
154 case FileError:
155 return "FileError is deprecated. Please use the 'name' or 'message' attr ibutes of DOMError rather than 'code'.";
156
157 case CSSStyleSheetInsertRuleOptionalArg:
158 return "Calling CSSStyleSheet.insertRule() with one argument is deprecat ed. Please pass the index argument as well: insertRule(x, 0).";
159
160 case PrefixedIndexedDB:
161 return replacedBy("webkitIndexedDB", "indexedDB");
162
163 case PrefixedIDBCursorConstructor:
164 return replacedBy("webkitIDBCursor", "IDBCursor");
165
166 case PrefixedIDBDatabaseConstructor:
167 return replacedBy("webkitIDBDatabase", "IDBDatabase");
168
169 case PrefixedIDBFactoryConstructor:
170 return replacedBy("webkitIDBFactory", "IDBFactory");
171
172 case PrefixedIDBIndexConstructor:
173 return replacedBy("webkitIDBIndex", "IDBIndex");
174
175 case PrefixedIDBKeyRangeConstructor:
176 return replacedBy("webkitIDBKeyRange", "IDBKeyRange");
177
178 case PrefixedIDBObjectStoreConstructor:
179 return replacedBy("webkitIDBObjectStore", "IDBObjectStore");
180
181 case PrefixedIDBRequestConstructor:
182 return replacedBy("webkitIDBRequest", "IDBRequest");
183
184 case PrefixedIDBTransactionConstructor:
185 return replacedBy("webkitIDBTransaction", "IDBTransaction");
186
187 case PrefixedRequestAnimationFrame:
188 return "'webkitRequestAnimationFrame' is vendor-specific. Please use the standard 'requestAnimationFrame' instead.";
189
190 case PrefixedCancelAnimationFrame:
191 return "'webkitCancelAnimationFrame' is vendor-specific. Please use the standard 'cancelAnimationFrame' instead.";
192
193 case PrefixedCancelRequestAnimationFrame:
194 return "'webkitCancelRequestAnimationFrame' is vendor-specific. Please u se the standard 'cancelAnimationFrame' instead.";
195
196 case DocumentCreateAttributeNS:
197 return "'Document.createAttributeNS' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).";
198
199 case AttributeOwnerElement:
200 return "'Attr.ownerElement' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).";
201
202 case AttrTextContent:
203 return replacedBy("Attr.textContent", "value");
204
205 case RangeDetach:
206 return "'Range.detach' is now a no-op, as per DOM (http://dom.spec.whatw g.org/#dom-range-detach).";
207
208 case HTMLHeadElementProfile:
209 return "'HTMLHeadElement.profile' is deprecated. The reflected attribute has no effect.";
210
211 case ElementSetPrefix:
212 return "Setting 'Element.prefix' is deprecated, as it is read-only per D OM (http://dom.spec.whatwg.org/#element).";
213
214 case WebSocketURL:
215 return "'WebSocket.URL' is deprecated. Please use 'WebSocket.url' instea d.";
216
217 case PictureSourceSrc:
218 return "<source src> with a <picture> parent is invalid and therefore ig nored. Please use <source srcset> instead.";
219
220 // Features that aren't deprecated don't have a deprecation message.
221 default:
222 return String();
223 }
224 }
225
226 void UseCounter::count(CSSParserContext context, CSSPropertyID feature)
227 {
228 ASSERT(feature >= firstCSSProperty);
229 ASSERT(feature <= lastCSSProperty);
230 ASSERT(!isInternalProperty(feature));
231
232 m_CSSFeatureBits.quickSet(feature);
233 }
234
235 void UseCounter::count(Feature feature)
236 {
237 ASSERT(deprecationMessage(feature).isEmpty());
238 recordMeasurement(feature);
239 }
240
241 UseCounter* UseCounter::getFrom(const Document* document)
242 {
243 if (document && document->frameHost())
244 return &document->frameHost()->useCounter();
245 return 0;
246 }
247
248 UseCounter* UseCounter::getFrom(const CSSStyleSheet* sheet)
249 {
250 if (sheet)
251 return getFrom(sheet->contents());
252 return 0;
253 }
254
255 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents)
256 {
257 // TODO(esprehn): Support this in Sky.
258 return 0;
259 }
260
261 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/frame/UseCounter.h ('k') | sky/engine/core/html/HTMLAnchorElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698