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

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.cc

Issue 1441393002: Add UMA to count the number of Google CAPTCHA pages shown and solved by users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding missing files (whoops) Created 5 years, 1 month 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/user_metrics.h"
10 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" 11 #include "components/page_load_metrics/browser/page_load_metrics_macros.h"
11 #include "components/page_load_metrics/common/page_load_metrics_messages.h" 12 #include "components/page_load_metrics/common/page_load_metrics_messages.h"
12 #include "components/page_load_metrics/common/page_load_timing.h" 13 #include "components/page_load_metrics/common/page_load_timing.h"
13 #include "components/rappor/rappor_service.h" 14 #include "components/rappor/rappor_service.h"
14 #include "components/rappor/rappor_utils.h" 15 #include "components/rappor/rappor_utils.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
17 #include "content/public/browser/navigation_handle.h" 18 #include "content/public/browser/navigation_handle.h"
18 #include "content/public/browser/render_frame_host.h" 19 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 url_ = navigation_handle->GetURL(); 154 url_ = navigation_handle->GetURL();
154 // We log the event that this load started. Because we don't know if a load is 155 // We log the event that this load started. Because we don't know if a load is
155 // relevant or if it will commit before now, we have to log this event at 156 // relevant or if it will commit before now, we have to log this event at
156 // commit time. 157 // commit time.
157 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_); 158 RecordCommittedEvent(COMMITTED_LOAD_STARTED, !started_in_foreground_);
158 159
159 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_, 160 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_,
160 OnCommit(navigation_handle)); 161 OnCommit(navigation_handle));
161 } 162 }
162 163
164 void PageLoadTracker::Redirect(content::NavigationHandle* navigation_handle) {
165 FOR_EACH_OBSERVER(PageLoadMetricsObserver, *observers_,
166 OnRedirect(navigation_handle));
167 }
168
163 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) { 169 bool PageLoadTracker::UpdateTiming(const PageLoadTiming& new_timing) {
164 // Throw away IPCs that are not relevant to the current navigation. 170 // Throw away IPCs that are not relevant to the current navigation.
165 // Two timing structures cannot refer to the same navigation if they indicate 171 // Two timing structures cannot refer to the same navigation if they indicate
166 // that a navigation started at different times, so a new timing struct with a 172 // that a navigation started at different times, so a new timing struct with a
167 // different start time from an earlier struct is considered invalid. 173 // different start time from an earlier struct is considered invalid.
168 bool valid_timing_descendent = 174 bool valid_timing_descendent =
169 timing_.navigation_start.is_null() || 175 timing_.navigation_start.is_null() ||
170 timing_.navigation_start == new_timing.navigation_start; 176 timing_.navigation_start == new_timing.navigation_start;
171 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) { 177 if (IsValidPageLoadTiming(new_timing) && valid_timing_descendent) {
172 timing_ = new_timing; 178 timing_ = new_timing;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 const std::string& mime_type = web_contents()->GetContentsMimeType(); 480 const std::string& mime_type = web_contents()->GetContentsMimeType();
475 DCHECK(!browser_url.is_empty()); 481 DCHECK(!browser_url.is_empty());
476 DCHECK(!mime_type.empty()); 482 DCHECK(!mime_type.empty());
477 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) 483 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type))
478 return; 484 return;
479 485
480 committed_load_ = finished_nav.Pass(); 486 committed_load_ = finished_nav.Pass();
481 committed_load_->Commit(navigation_handle); 487 committed_load_->Commit(navigation_handle);
482 } 488 }
483 489
490 void MetricsWebContentsObserver::DidRedirectNavigation(
491 content::NavigationHandle* navigation_handle) {
492 if (!navigation_handle->IsInMainFrame())
493 return;
494 auto it = provisional_loads_.find(navigation_handle);
495 if (it == provisional_loads_.end())
496 return;
497 it->second->Redirect(navigation_handle);
498 }
499
484 void MetricsWebContentsObserver::WasShown() { 500 void MetricsWebContentsObserver::WasShown() {
485 in_foreground_ = true; 501 in_foreground_ = true;
486 if (committed_load_) 502 if (committed_load_)
487 committed_load_->WebContentsShown(); 503 committed_load_->WebContentsShown();
488 for (const auto& kv : provisional_loads_) { 504 for (const auto& kv : provisional_loads_) {
489 kv.second->WebContentsShown(); 505 kv.second->WebContentsShown();
490 } 506 }
491 } 507 }
492 508
493 void MetricsWebContentsObserver::WasHidden() { 509 void MetricsWebContentsObserver::WasHidden() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 552
537 if (!committed_load_->UpdateTiming(timing)) { 553 if (!committed_load_->UpdateTiming(timing)) {
538 // If the page load tracker cannot update its timing, something is wrong 554 // If the page load tracker cannot update its timing, something is wrong
539 // with the IPC (it's from another load, or it's invalid in some other way). 555 // with the IPC (it's from another load, or it's invalid in some other way).
540 // We expect this to be a rare occurrence. 556 // We expect this to be a rare occurrence.
541 RecordInternalError(ERR_BAD_TIMING_IPC); 557 RecordInternalError(ERR_BAD_TIMING_IPC);
542 } 558 }
543 } 559 }
544 560
545 } // namespace page_load_metrics 561 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698