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/previews_page_load_metrics_
observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/previews_page_load_metrics_
observer.h" |
6 | 6 |
7 #include <string> | |
8 | |
9 #include "base/optional.h" | 7 #include "base/optional.h" |
10 #include "base/time/time.h" | 8 #include "base/time/time.h" |
11 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 9 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
12 #include "chrome/common/page_load_metrics/page_load_timing.h" | 10 #include "chrome/common/page_load_metrics/page_load_timing.h" |
13 #include "content/public/browser/navigation_handle.h" | 11 #include "content/public/browser/navigation_handle.h" |
14 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
15 | 13 |
16 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
17 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 15 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
18 #endif // defined(OS_ANDROID) | 16 #endif // defined(OS_ANDROID) |
(...skipping 24 matching lines...) Expand all Loading... |
43 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} | 41 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} |
44 | 42 |
45 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 43 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
46 PreviewsPageLoadMetricsObserver::OnCommit( | 44 PreviewsPageLoadMetricsObserver::OnCommit( |
47 content::NavigationHandle* navigation_handle) { | 45 content::NavigationHandle* navigation_handle) { |
48 return IsOfflinePreview(navigation_handle->GetWebContents()) | 46 return IsOfflinePreview(navigation_handle->GetWebContents()) |
49 ? CONTINUE_OBSERVING | 47 ? CONTINUE_OBSERVING |
50 : STOP_OBSERVING; | 48 : STOP_OBSERVING; |
51 } | 49 } |
52 | 50 |
| 51 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 52 PreviewsPageLoadMetricsObserver::ShouldObserveMimeType( |
| 53 const std::string& mime_type) const { |
| 54 // On top of base-supported types, support MHTML. Offline previews are served |
| 55 // as MHTML (multipart/related). |
| 56 return PageLoadMetricsObserver::ShouldObserveMimeType(mime_type) == |
| 57 CONTINUE_OBSERVING || |
| 58 mime_type == "multipart/related" |
| 59 ? CONTINUE_OBSERVING |
| 60 : STOP_OBSERVING; |
| 61 } |
| 62 |
53 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( | 63 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
54 const page_load_metrics::PageLoadTiming& timing, | 64 const page_load_metrics::PageLoadTiming& timing, |
55 const page_load_metrics::PageLoadExtraInfo& info) { | 65 const page_load_metrics::PageLoadExtraInfo& info) { |
56 if (!WasStartedInForegroundOptionalEventInForeground( | 66 if (!WasStartedInForegroundOptionalEventInForeground( |
57 timing.dom_content_loaded_event_start, info)) { | 67 timing.dom_content_loaded_event_start, info)) { |
58 return; | 68 return; |
59 } | 69 } |
60 PAGE_LOAD_HISTOGRAM( | 70 PAGE_LOAD_HISTOGRAM( |
61 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, | 71 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, |
62 timing.dom_content_loaded_event_start.value()); | 72 timing.dom_content_loaded_event_start.value()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
112 offline_pages::OfflinePageTabHelper* tab_helper = | 122 offline_pages::OfflinePageTabHelper* tab_helper = |
113 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); | 123 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); |
114 return tab_helper && tab_helper->IsShowingOfflinePreview(); | 124 return tab_helper && tab_helper->IsShowingOfflinePreview(); |
115 #else | 125 #else |
116 return false; | 126 return false; |
117 #endif // defined(OS_ANDROID) | 127 #endif // defined(OS_ANDROID) |
118 } | 128 } |
119 | 129 |
120 } // namespace previews | 130 } // namespace previews |
OLD | NEW |