| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_page_load_metrics_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_page_load_metrics_observer.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_service_factory.h" | 8 #include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_service_factory.h" |
| 9 #include "url/url_constants.h" | 9 #include "url/url_constants.h" |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 content::NavigationHandle* navigation_handle, | 25 content::NavigationHandle* navigation_handle, |
| 26 const GURL& currently_committed_url, | 26 const GURL& currently_committed_url, |
| 27 bool started_in_foreground) { | 27 bool started_in_foreground) { |
| 28 if (started_in_foreground) | 28 if (started_in_foreground) |
| 29 OnShown(); | 29 OnShown(); |
| 30 return CONTINUE_OBSERVING; | 30 return CONTINUE_OBSERVING; |
| 31 } | 31 } |
| 32 | 32 |
| 33 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 33 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 34 HttpsEngagementPageLoadMetricsObserver::OnHidden( | 34 HttpsEngagementPageLoadMetricsObserver::OnHidden( |
| 35 const page_load_metrics::PageLoadTiming& timing, | 35 const page_load_metrics::mojom::PageLoadTiming& timing, |
| 36 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 36 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
| 37 if (currently_in_foreground_) { | 37 if (currently_in_foreground_) { |
| 38 foreground_time_ += base::TimeTicks::Now() - last_time_shown_; | 38 foreground_time_ += base::TimeTicks::Now() - last_time_shown_; |
| 39 currently_in_foreground_ = false; | 39 currently_in_foreground_ = false; |
| 40 } | 40 } |
| 41 return CONTINUE_OBSERVING; | 41 return CONTINUE_OBSERVING; |
| 42 } | 42 } |
| 43 | 43 |
| 44 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 44 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 45 HttpsEngagementPageLoadMetricsObserver::OnShown() { | 45 HttpsEngagementPageLoadMetricsObserver::OnShown() { |
| 46 last_time_shown_ = base::TimeTicks::Now(); | 46 last_time_shown_ = base::TimeTicks::Now(); |
| 47 currently_in_foreground_ = true; | 47 currently_in_foreground_ = true; |
| 48 return CONTINUE_OBSERVING; | 48 return CONTINUE_OBSERVING; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void HttpsEngagementPageLoadMetricsObserver::OnComplete( | 51 void HttpsEngagementPageLoadMetricsObserver::OnComplete( |
| 52 const page_load_metrics::PageLoadTiming& timing, | 52 const page_load_metrics::mojom::PageLoadTiming& timing, |
| 53 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 53 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
| 54 if (!extra_info.did_commit || !extra_info.url.is_valid()) { | 54 if (!extra_info.did_commit || !extra_info.url.is_valid()) { |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Don't record anything if the user never saw it. | 58 // Don't record anything if the user never saw it. |
| 59 if (!currently_in_foreground_ && foreground_time_.is_zero()) | 59 if (!currently_in_foreground_ && foreground_time_.is_zero()) |
| 60 return; | 60 return; |
| 61 | 61 |
| 62 if (currently_in_foreground_) | 62 if (currently_in_foreground_) |
| 63 OnHidden(timing, extra_info); | 63 OnHidden(timing, extra_info); |
| 64 | 64 |
| 65 if (extra_info.url.SchemeIs(url::kHttpsScheme)) { | 65 if (extra_info.url.SchemeIs(url::kHttpsScheme)) { |
| 66 if (engagement_service_) | 66 if (engagement_service_) |
| 67 engagement_service_->RecordTimeOnPage(foreground_time_, | 67 engagement_service_->RecordTimeOnPage(foreground_time_, |
| 68 HttpsEngagementService::HTTPS); | 68 HttpsEngagementService::HTTPS); |
| 69 UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpsEngagementHistogram, | 69 UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpsEngagementHistogram, |
| 70 foreground_time_); | 70 foreground_time_); |
| 71 } else if (extra_info.url.SchemeIs(url::kHttpScheme)) { | 71 } else if (extra_info.url.SchemeIs(url::kHttpScheme)) { |
| 72 if (engagement_service_) | 72 if (engagement_service_) |
| 73 engagement_service_->RecordTimeOnPage(foreground_time_, | 73 engagement_service_->RecordTimeOnPage(foreground_time_, |
| 74 HttpsEngagementService::HTTP); | 74 HttpsEngagementService::HTTP); |
| 75 UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpEngagementHistogram, | 75 UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpEngagementHistogram, |
| 76 foreground_time_); | 76 foreground_time_); |
| 77 } | 77 } |
| 78 } | 78 } |
| OLD | NEW |