Chromium Code Reviews| 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 // Support observing HTML, XHTML, and MHTML. Offline previews are served as | |
| 55 // MHTML (multipart/related). | |
| 56 return mime_type == "text/html" || mime_type == "application/xhtml+xml" || | |
|
Bryan McQuade
2017/02/21 18:50:15
let's have this chain to the base class impl first
| |
| 57 mime_type == "multipart/related" | |
| 58 ? CONTINUE_OBSERVING | |
| 59 : STOP_OBSERVING; | |
| 60 } | |
| 61 | |
| 53 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( | 62 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
| 54 const page_load_metrics::PageLoadTiming& timing, | 63 const page_load_metrics::PageLoadTiming& timing, |
| 55 const page_load_metrics::PageLoadExtraInfo& info) { | 64 const page_load_metrics::PageLoadExtraInfo& info) { |
| 56 if (!WasStartedInForegroundOptionalEventInForeground( | 65 if (!WasStartedInForegroundOptionalEventInForeground( |
| 57 timing.dom_content_loaded_event_start, info)) { | 66 timing.dom_content_loaded_event_start, info)) { |
| 58 return; | 67 return; |
| 59 } | 68 } |
| 60 PAGE_LOAD_HISTOGRAM( | 69 PAGE_LOAD_HISTOGRAM( |
| 61 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, | 70 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, |
| 62 timing.dom_content_loaded_event_start.value()); | 71 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) | 120 #if defined(OS_ANDROID) |
| 112 offline_pages::OfflinePageTabHelper* tab_helper = | 121 offline_pages::OfflinePageTabHelper* tab_helper = |
| 113 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); | 122 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); |
| 114 return tab_helper && tab_helper->IsShowingOfflinePreview(); | 123 return tab_helper && tab_helper->IsShowingOfflinePreview(); |
| 115 #else | 124 #else |
| 116 return false; | 125 return false; |
| 117 #endif // defined(OS_ANDROID) | 126 #endif // defined(OS_ANDROID) |
| 118 } | 127 } |
| 119 | 128 |
| 120 } // namespace previews | 129 } // namespace previews |
| OLD | NEW |