Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(bmcquade): delete this class in October 2016, as it is deprecated by the | 5 // TODO(bmcquade): delete this class in October 2016, as it is deprecated by the |
| 6 // new PageLoad.* UMA histograms. | 6 // new PageLoad.* UMA histograms. |
| 7 | 7 |
| 8 #include "chrome/renderer/page_load_histograms.h" | 8 #include "chrome/renderer/page_load_histograms.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "content/public/renderer/render_frame.h" | 30 #include "content/public/renderer/render_frame.h" |
| 31 #include "content/public/renderer/render_thread.h" | 31 #include "content/public/renderer/render_thread.h" |
| 32 #include "content/public/renderer/render_view.h" | 32 #include "content/public/renderer/render_view.h" |
| 33 #include "extensions/common/url_pattern.h" | 33 #include "extensions/common/url_pattern.h" |
| 34 #include "net/base/url_util.h" | 34 #include "net/base/url_util.h" |
| 35 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
| 36 #include "third_party/WebKit/public/platform/URLConversion.h" | 36 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 38 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 38 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 39 #include "third_party/WebKit/public/web/WebDocument.h" | 39 #include "third_party/WebKit/public/web/WebDocument.h" |
| 40 #include "third_party/WebKit/public/web/WebFrame.h" | 40 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 41 #include "third_party/WebKit/public/web/WebPerformance.h" | 41 #include "third_party/WebKit/public/web/WebPerformance.h" |
| 42 #include "third_party/WebKit/public/web/WebView.h" | 42 #include "third_party/WebKit/public/web/WebView.h" |
| 43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 44 | 44 |
| 45 #if defined(ENABLE_EXTENSIONS) | 45 #if defined(ENABLE_EXTENSIONS) |
| 46 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" | 46 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" |
| 47 #include "extensions/renderer/dispatcher.h" | 47 #include "extensions/renderer/dispatcher.h" |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 using blink::WebDataSource; | 50 using blink::WebDataSource; |
| 51 using blink::WebFrame; | 51 using blink::WebLocalFrame; |
| 52 using blink::WebPerformance; | 52 using blink::WebPerformance; |
| 53 using blink::WebString; | 53 using blink::WebString; |
| 54 using base::Time; | 54 using base::Time; |
| 55 using base::TimeDelta; | 55 using base::TimeDelta; |
| 56 using content::DocumentState; | 56 using content::DocumentState; |
| 57 | 57 |
| 58 const size_t kPLTCount = 100; | 58 const size_t kPLTCount = 100; |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 URLPattern::SchemeMasks GetSupportedSchemeType(const GURL& url) { | 126 URLPattern::SchemeMasks GetSupportedSchemeType(const GURL& url) { |
| 127 if (url.SchemeIs("http")) | 127 if (url.SchemeIs("http")) |
| 128 return URLPattern::SCHEME_HTTP; | 128 return URLPattern::SCHEME_HTTP; |
| 129 else if (url.SchemeIs("https")) | 129 else if (url.SchemeIs("https")) |
| 130 return URLPattern::SCHEME_HTTPS; | 130 return URLPattern::SCHEME_HTTPS; |
| 131 return static_cast<URLPattern::SchemeMasks>(0); | 131 return static_cast<URLPattern::SchemeMasks>(0); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Helper function to check for string in 'via' header. Returns true if | 134 // Helper function to check for string in 'via' header. Returns true if |
| 135 // |via_value| is one of the values listed in the Via header. | 135 // |via_value| is one of the values listed in the Via header. |
| 136 bool ViaHeaderContains(WebFrame* frame, const std::string& via_value) { | 136 bool ViaHeaderContains(WebLocalFrame* frame, const std::string& via_value) { |
| 137 const char kViaHeaderName[] = "Via"; | 137 const char kViaHeaderName[] = "Via"; |
| 138 std::vector<std::string> values; | 138 std::vector<std::string> values; |
| 139 // Multiple via headers have already been coalesced and hence each value | 139 // Multiple via headers have already been coalesced and hence each value |
| 140 // separated by a comma corresponds to a proxy. The value added by a proxy is | 140 // separated by a comma corresponds to a proxy. The value added by a proxy is |
| 141 // not expected to contain any commas. | 141 // not expected to contain any commas. |
| 142 // Example., Via: 1.0 Compression proxy, 1.1 Google Instant Proxy Preview | 142 // Example., Via: 1.0 Compression proxy, 1.1 Google Instant Proxy Preview |
| 143 values = base::SplitString( | 143 values = base::SplitString( |
| 144 frame->dataSource()->response().httpHeaderField(kViaHeaderName).utf8(), | 144 frame->dataSource()->response().httpHeaderField(kViaHeaderName).utf8(), |
| 145 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 145 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 146 return std::find(values.begin(), values.end(), via_value) != values.end(); | 146 return std::find(values.begin(), values.end(), via_value) != values.end(); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 begin_to_finish_all_loads); | 521 begin_to_finish_all_loads); |
| 522 break; | 522 break; |
| 523 default: | 523 default: |
| 524 break; | 524 break; |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 } // namespace | 529 } // namespace |
| 530 | 530 |
| 531 PageLoadHistograms::PageLoadHistograms(content::RenderView* render_view) | 531 PageLoadHistograms::PageLoadHistograms(content::RenderFrame* render_frame) |
| 532 : content::RenderViewObserver(render_view) { | 532 : content::RenderFrameObserver(render_frame) {} |
| 533 } | |
| 534 | 533 |
| 535 PageLoadHistograms::~PageLoadHistograms() { | 534 PageLoadHistograms::~PageLoadHistograms() { |
| 536 } | 535 } |
| 537 | 536 |
| 538 void PageLoadHistograms::Dump(WebFrame* frame) { | 537 void PageLoadHistograms::Dump() { |
| 538 WebLocalFrame* frame = render_frame()->GetWebFrame(); | |
| 539 | |
| 539 // We only dump histograms for main frames. | 540 // We only dump histograms for main frames. |
| 540 // In the future, it may be interesting to tag subframes and dump them too. | 541 // In the future, it may be interesting to tag subframes and dump them too. |
| 541 if (!frame || frame->parent()) | 542 DCHECK(frame && !frame->parent()); |
|
dcheng
2016/09/30 06:20:42
In theory this should always be true. Hopefully th
| |
| 542 return; | |
| 543 | |
| 544 // If the main frame lives in a different process, don't do anything. | |
| 545 // Histogram data will be recorded by the real main frame. | |
| 546 if (frame->isWebRemoteFrame()) | |
| 547 return; | |
| 548 | 543 |
| 549 // Only dump for supported schemes. | 544 // Only dump for supported schemes. |
| 550 URLPattern::SchemeMasks scheme_type = | 545 URLPattern::SchemeMasks scheme_type = |
| 551 GetSupportedSchemeType(frame->document().url()); | 546 GetSupportedSchemeType(frame->document().url()); |
| 552 if (scheme_type == 0) | 547 if (scheme_type == 0) |
| 553 return; | 548 return; |
| 554 | 549 |
| 555 // Don't dump stats for the NTP, as PageLoadHistograms should only be recorded | 550 // Don't dump stats for the NTP, as PageLoadHistograms should only be recorded |
| 556 // for pages visited due to an explicit user navigation. | 551 // for pages visited due to an explicit user navigation. |
| 557 if (SearchBouncer::GetInstance()->IsNewTabPage(frame->document().url())) { | 552 if (SearchBouncer::GetInstance()->IsNewTabPage(frame->document().url())) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 // sure that we send the histograms generated. Without this call, pages | 585 // sure that we send the histograms generated. Without this call, pages |
| 591 // that don't have an on-close-handler might generate data that is lost if | 586 // that don't have an on-close-handler might generate data that is lost if |
| 592 // the renderer is shutdown abruptly (e.g. the user closed the tab). | 587 // the renderer is shutdown abruptly (e.g. the user closed the tab). |
| 593 // TODO(bcwhite): Remove completely when persistence is on-by-default. | 588 // TODO(bcwhite): Remove completely when persistence is on-by-default. |
| 594 if (!base::GlobalHistogramAllocator::Get()) { | 589 if (!base::GlobalHistogramAllocator::Get()) { |
| 595 content::RenderThread::Get()->UpdateHistograms( | 590 content::RenderThread::Get()->UpdateHistograms( |
| 596 content::kHistogramSynchronizerReservedSequenceNumber); | 591 content::kHistogramSynchronizerReservedSequenceNumber); |
| 597 } | 592 } |
| 598 } | 593 } |
| 599 | 594 |
| 600 void PageLoadHistograms::FrameWillClose(WebFrame* frame) { | 595 void PageLoadHistograms::WillCommitProvisionalLoad() { |
| 601 Dump(frame); | 596 Dump(); |
| 602 } | 597 } |
| 603 | 598 |
| 604 void PageLoadHistograms::ClosePage() { | 599 void PageLoadHistograms::FrameDetached() { |
| 605 // TODO(davemoore) This code should be removed once willClose() gets | 600 Dump(); |
| 606 // called when a page is destroyed. page_load_histograms_.Dump() is safe | |
| 607 // to call multiple times for the same frame, but it will simplify things. | |
| 608 Dump(render_view()->GetWebView()->mainFrame()); | |
| 609 } | 601 } |
| 610 | 602 |
| 611 void PageLoadHistograms::LogPageLoadTime(const DocumentState* document_state, | 603 void PageLoadHistograms::LogPageLoadTime(const DocumentState* document_state, |
| 612 const WebDataSource* ds) const { | 604 const WebDataSource* ds) const { |
| 613 // Because this function gets called on every page load, | 605 // Because this function gets called on every page load, |
| 614 // take extra care to optimize it away if logging is turned off. | 606 // take extra care to optimize it away if logging is turned off. |
| 615 if (logging::LOG_INFO < logging::GetMinLogLevel()) | 607 if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 616 return; | 608 return; |
| 617 | 609 |
| 618 DCHECK(document_state); | 610 DCHECK(document_state); |
| 619 DCHECK(ds); | 611 DCHECK(ds); |
| 620 GURL url(ds->request().url()); | 612 GURL url(ds->request().url()); |
| 621 Time start = document_state->start_load_time(); | 613 Time start = document_state->start_load_time(); |
| 622 Time finish = document_state->finish_load_time(); | 614 Time finish = document_state->finish_load_time(); |
| 623 // TODO(mbelshe): should we log more stats? | 615 // TODO(mbelshe): should we log more stats? |
| 624 VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms " | 616 VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms " |
| 625 << url.spec(); | 617 << url.spec(); |
| 626 } | 618 } |
| 627 | 619 |
| 628 void PageLoadHistograms::OnDestruct() { | 620 void PageLoadHistograms::OnDestruct() { |
| 629 delete this; | 621 delete this; |
| 630 } | 622 } |
| OLD | NEW |