OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 String text = | 292 String text = |
293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode); | 293 SerializeNodes<EditingStrategy>(accumulator, document, kIncludeNode); |
294 | 294 |
295 CString frame_html = | 295 CString frame_html = |
296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables); | 296 document.Encoding().Encode(text, WTF::kEntitiesForUnencodables); |
297 resources_->push_back(SerializedResource( | 297 resources_->push_back(SerializedResource( |
298 url, document.SuggestedMIMEType(), | 298 url, document.SuggestedMIMEType(), |
299 SharedBuffer::Create(frame_html.data(), frame_html.length()))); | 299 SharedBuffer::Create(frame_html.data(), frame_html.length()))); |
300 } | 300 } |
301 | 301 |
302 int total_image_count = 0; | |
303 int loaded_image_count = 0; | |
304 int total_css_count = 0; | |
305 int loaded_css_count = 0; | |
306 bool should_collect_problem_metric = | |
307 delegate_.ShouldCollectProblemMetric() && frame.IsMainFrame(); | |
Łukasz Anforowicz
2017/06/07 21:11:35
You are obviously in a better position than me to
romax
2017/06/08 02:25:22
I think it was mainly because in the offline page
Łukasz Anforowicz
2017/06/08 16:08:45
Sounds good. One final thought - how would the na
romax
2017/06/08 20:02:07
Adding suffixes sounds good to me, and it is somet
Łukasz Anforowicz
2017/06/08 20:48:53
I don't have a strong opinion - I am fine with wha
| |
302 for (Node* node : serialized_nodes) { | 308 for (Node* node : serialized_nodes) { |
303 DCHECK(node); | 309 DCHECK(node); |
304 if (!node->IsElementNode()) | 310 if (!node->IsElementNode()) |
305 continue; | 311 continue; |
306 | 312 |
307 Element& element = ToElement(*node); | 313 Element& element = ToElement(*node); |
308 // We have to process in-line style as it might contain some resources | 314 // We have to process in-line style as it might contain some resources |
309 // (typically background images). | 315 // (typically background images). |
310 if (element.IsStyledElement()) { | 316 if (element.IsStyledElement()) { |
311 RetrieveResourcesForProperties(element.InlineStyle(), document); | 317 RetrieveResourcesForProperties(element.InlineStyle(), document); |
312 RetrieveResourcesForProperties(element.PresentationAttributeStyle(), | 318 RetrieveResourcesForProperties(element.PresentationAttributeStyle(), |
313 document); | 319 document); |
314 } | 320 } |
315 | 321 |
316 if (isHTMLImageElement(element)) { | 322 if (isHTMLImageElement(element)) { |
317 HTMLImageElement& image_element = toHTMLImageElement(element); | 323 HTMLImageElement& image_element = toHTMLImageElement(element); |
318 KURL url = | 324 KURL url = |
319 document.CompleteURL(image_element.getAttribute(HTMLNames::srcAttr)); | 325 document.CompleteURL(image_element.getAttribute(HTMLNames::srcAttr)); |
326 if (should_collect_problem_metric) { | |
327 total_image_count++; | |
328 if (image_element.complete()) | |
Łukasz Anforowicz
2017/06/07 21:11:35
I see that FrameSerializer::AddImageToResources ch
romax
2017/06/08 02:25:22
Done.
Your mental model is correct. And I wasn't s
| |
329 loaded_image_count++; | |
330 } | |
Łukasz Anforowicz
2017/06/07 21:11:35
Have you thought about avoiding counting resources
romax
2017/06/08 02:25:22
I didn't think about it before seeing comments. An
| |
320 ImageResourceContent* cached_image = image_element.CachedImage(); | 331 ImageResourceContent* cached_image = image_element.CachedImage(); |
321 AddImageToResources(cached_image, url); | 332 AddImageToResources(cached_image, url); |
322 } else if (isHTMLInputElement(element)) { | 333 } else if (isHTMLInputElement(element)) { |
323 HTMLInputElement& input_element = toHTMLInputElement(element); | 334 HTMLInputElement& input_element = toHTMLInputElement(element); |
324 if (input_element.type() == InputTypeNames::image && | 335 if (input_element.type() == InputTypeNames::image && |
325 input_element.ImageLoader()) { | 336 input_element.ImageLoader()) { |
326 KURL url = input_element.Src(); | 337 KURL url = input_element.Src(); |
327 ImageResourceContent* cached_image = | 338 ImageResourceContent* cached_image = |
328 input_element.ImageLoader()->GetImage(); | 339 input_element.ImageLoader()->GetImage(); |
329 AddImageToResources(cached_image, url); | 340 AddImageToResources(cached_image, url); |
330 } | 341 } |
331 } else if (isHTMLLinkElement(element)) { | 342 } else if (isHTMLLinkElement(element)) { |
332 HTMLLinkElement& link_element = toHTMLLinkElement(element); | 343 HTMLLinkElement& link_element = toHTMLLinkElement(element); |
333 if (CSSStyleSheet* sheet = link_element.sheet()) { | 344 if (CSSStyleSheet* sheet = link_element.sheet()) { |
334 KURL url = document.CompleteURL( | 345 KURL url = document.CompleteURL( |
335 link_element.getAttribute(HTMLNames::hrefAttr)); | 346 link_element.getAttribute(HTMLNames::hrefAttr)); |
336 SerializeCSSStyleSheet(*sheet, url); | 347 SerializeCSSStyleSheet(*sheet, url); |
337 } | 348 } |
338 } else if (isHTMLStyleElement(element)) { | 349 } else if (isHTMLStyleElement(element)) { |
339 HTMLStyleElement& style_element = toHTMLStyleElement(element); | 350 HTMLStyleElement& style_element = toHTMLStyleElement(element); |
340 if (CSSStyleSheet* sheet = style_element.sheet()) | 351 CSSStyleSheet* sheet = style_element.sheet(); |
352 if (sheet) | |
341 SerializeCSSStyleSheet(*sheet, KURL()); | 353 SerializeCSSStyleSheet(*sheet, KURL()); |
354 if (should_collect_problem_metric) { | |
355 total_css_count++; | |
356 if (sheet && sheet->IsLoading()) | |
357 loaded_css_count++; | |
Łukasz Anforowicz
2017/06/07 21:11:35
"loading" vs "loaded" seems out of sync - can you
romax
2017/06/08 02:25:22
Done.
| |
358 } | |
342 } | 359 } |
343 } | 360 } |
361 if (should_collect_problem_metric) { | |
362 // Report detectors through UMA. | |
363 // We're having exact 21 buckets for percentage because we want to have 5% | |
364 // in each bucket to avoid potential spikes in the distribution. | |
365 DCHECK_LE(loaded_image_count, total_image_count); | |
366 UMA_HISTOGRAM_EXACT_LINEAR( | |
367 "PageSerialization.ProblemDetection.LoadedImagePercentage", | |
368 static_cast<int64_t>(loaded_image_count * 100 / total_image_count), 21); | |
Steven Holte
2017/06/07 22:36:42
You are using 21 buckets, but these buckets are no
romax
2017/06/08 02:25:22
Done.
Changed to CustomCountHistogram in Blink, si
Steven Holte
2017/06/08 20:43:00
CustomCountHistogram is also not going to give you
romax
2017/06/08 23:30:46
I've added the LinearHistogram in Webkit/Platforms
| |
369 UMA_HISTOGRAM_COUNTS_100( | |
370 "PageSerialization.ProblemDetection.TotalImageCount", | |
371 static_cast<int64_t>(total_image_count)); | |
372 | |
373 DCHECK_LE(loaded_css_count, total_css_count); | |
374 UMA_HISTOGRAM_EXACT_LINEAR( | |
375 "PageSerialization.ProblemDetection.LoadedCSSPercentage", | |
376 static_cast<int64_t>(loaded_css_count * 100 / total_css_count), 21); | |
377 UMA_HISTOGRAM_COUNTS_100("PageSerialization.ProblemDetection.TotalCSSCount", | |
378 static_cast<int64_t>(total_css_count)); | |
379 } | |
344 } | 380 } |
345 | 381 |
346 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, | 382 void FrameSerializer::SerializeCSSStyleSheet(CSSStyleSheet& style_sheet, |
347 const KURL& url) { | 383 const KURL& url) { |
348 // If the URL is invalid or if it is a data URL this means that this CSS is | 384 // If the URL is invalid or if it is a data URL this means that this CSS is |
349 // defined inline, respectively in a <style> tag or in the data URL itself. | 385 // defined inline, respectively in a <style> tag or in the data URL itself. |
350 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); | 386 bool is_inline_css = !url.IsValid() || url.ProtocolIsData(); |
351 // If this CSS is not inline then it is identifiable by its URL. So just skip | 387 // If this CSS is not inline then it is identifiable by its URL. So just skip |
352 // it if it has already been analyzed before. | 388 // it if it has already been analyzed before. |
353 if (!is_inline_css && (resource_urls_.Contains(url) || | 389 if (!is_inline_css && (resource_urls_.Contains(url) || |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 emits_minus = ch == '-'; | 615 emits_minus = ch == '-'; |
580 builder.Append(ch); | 616 builder.Append(ch); |
581 } | 617 } |
582 CString escaped_url = builder.ToString().Ascii(); | 618 CString escaped_url = builder.ToString().Ascii(); |
583 return String::Format("saved from url=(%04d)%s", | 619 return String::Format("saved from url=(%04d)%s", |
584 static_cast<int>(escaped_url.length()), | 620 static_cast<int>(escaped_url.length()), |
585 escaped_url.data()); | 621 escaped_url.data()); |
586 } | 622 } |
587 | 623 |
588 } // namespace blink | 624 } // namespace blink |
OLD | NEW |