| 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/android/offline_pages/offline_page_tab_helper.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 13 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 14 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 14 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 15 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" | 15 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
| 16 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" | 16 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "components/offline_pages/client_namespace_constants.h" | 18 #include "components/offline_pages/client_namespace_constants.h" |
| 19 #include "components/offline_pages/offline_page_item.h" |
| 19 #include "components/offline_pages/offline_page_model.h" | 20 #include "components/offline_pages/offline_page_model.h" |
| 20 #include "components/previews/previews_experiments.h" | 21 #include "components/previews/previews_experiments.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/base/network_change_notifier.h" | 29 #include "net/base/network_change_notifier.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // This is a new navigation so we can invalidate any previously scheduled | 96 // This is a new navigation so we can invalidate any previously scheduled |
| 96 // operations. | 97 // operations. |
| 97 weak_ptr_factory_.InvalidateWeakPtrs(); | 98 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 98 | 99 |
| 99 // Since this is a new navigation, we will reset the cached offline page, | 100 // Since this is a new navigation, we will reset the cached offline page, |
| 100 // unless we are currently looking at an offline page. | 101 // unless we are currently looking at an offline page. |
| 101 GURL navigated_url = navigation_handle->GetURL(); | 102 GURL navigated_url = navigation_handle->GetURL(); |
| 102 if (offline_page_ && navigated_url != offline_page_->GetOfflineURL()) | 103 if (offline_page_ && navigated_url != offline_page_->GetOfflineURL()) |
| 103 offline_page_ = nullptr; | 104 offline_page_ = nullptr; |
| 104 | 105 |
| 106 // If an offline download file is opened, don't do redirect per network |
| 107 // conditions. Also store a cached copy here such that Tab knows that |
| 108 // the offline page is opened. |
| 109 if (OfflinePageUtils::MightBeOfflineURL(navigated_url)) { |
| 110 OfflinePageModel* offline_page_model = |
| 111 OfflinePageModelFactory::GetForBrowserContext( |
| 112 web_contents()->GetBrowserContext()); |
| 113 if (offline_page_model) { |
| 114 const OfflinePageItem* offline_page = |
| 115 offline_page_model->MaybeGetPageByOfflineURL(navigated_url); |
| 116 if (offline_page && |
| 117 offline_page->client_id.name_space == kDownloadNamespace) { |
| 118 offline_page_ = base::MakeUnique<OfflinePageItem>(*offline_page); |
| 119 return; |
| 120 } |
| 121 } |
| 122 } |
| 123 |
| 105 // Ignore navigations that are forward or back transitions in the nav stack | 124 // Ignore navigations that are forward or back transitions in the nav stack |
| 106 // which are not at the head of the stack. | 125 // which are not at the head of the stack. |
| 107 // TODO(dimich): Not sure this is needed. Clarify and remove. Bug 624216. | 126 // TODO(dimich): Not sure this is needed. Clarify and remove. Bug 624216. |
| 108 const content::NavigationController& controller = | 127 const content::NavigationController& controller = |
| 109 web_contents()->GetController(); | 128 web_contents()->GetController(); |
| 110 if (controller.GetEntryCount() > 0 && | 129 if (controller.GetEntryCount() > 0 && |
| 111 controller.GetCurrentEntryIndex() != -1 && | 130 controller.GetCurrentEntryIndex() != -1 && |
| 112 controller.GetCurrentEntryIndex() < controller.GetEntryCount() - 1) { | 131 controller.GetCurrentEntryIndex() < controller.GetEntryCount() - 1) { |
| 113 return; | 132 return; |
| 114 } | 133 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 entry->GetRedirectChain().back() == to_url; | 318 entry->GetRedirectChain().back() == to_url; |
| 300 } | 319 } |
| 301 | 320 |
| 302 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { | 321 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { |
| 303 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", | 322 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", |
| 304 static_cast<int>(result), | 323 static_cast<int>(result), |
| 305 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); | 324 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); |
| 306 } | 325 } |
| 307 | 326 |
| 308 } // namespace offline_pages | 327 } // namespace offline_pages |
| OLD | NEW |