| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 // This is a new navigation so we can invalidate any previously scheduled | 77 // This is a new navigation so we can invalidate any previously scheduled |
| 78 // operations. | 78 // operations. |
| 79 weak_ptr_factory_.InvalidateWeakPtrs(); | 79 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 80 | 80 |
| 81 // Since this is a new navigation, we will reset the cached offline page, | 81 // Since this is a new navigation, we will reset the cached offline page, |
| 82 // unless we are currently looking at an offline page. | 82 // unless we are currently looking at an offline page. |
| 83 GURL navigated_url = navigation_handle->GetURL(); | 83 GURL navigated_url = navigation_handle->GetURL(); |
| 84 if (offline_page_ && navigated_url != offline_page_->GetOfflineURL()) | 84 if (offline_page_ && navigated_url != offline_page_->GetOfflineURL()) |
| 85 offline_page_ = nullptr; | 85 offline_page_ = nullptr; |
| 86 | |
| 87 // Ignore navigations that are forward or back transitions in the nav stack | |
| 88 // which are not at the head of the stack. | |
| 89 // TODO(dimich): Not sure this is needed. Clarify and remove. Bug 624216. | |
| 90 const content::NavigationController& controller = | |
| 91 web_contents()->GetController(); | |
| 92 if (controller.GetEntryCount() > 0 && | |
| 93 controller.GetCurrentEntryIndex() != -1 && | |
| 94 controller.GetCurrentEntryIndex() < controller.GetEntryCount() - 1) { | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 content::BrowserContext* context = web_contents()->GetBrowserContext(); | |
| 99 if (net::NetworkChangeNotifier::IsOffline()) { | |
| 100 GetPagesForRedirectToOffline( | |
| 101 RedirectResult::REDIRECTED_ON_DISCONNECTED_NETWORK, navigated_url); | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 OfflinePageModel* offline_page_model = | |
| 106 OfflinePageModelFactory::GetForBrowserContext(context); | |
| 107 if (!offline_page_model) | |
| 108 return; | |
| 109 | |
| 110 offline_page_model->GetPageByOfflineURL( | |
| 111 navigated_url, base::Bind(&OfflinePageTabHelper::RedirectToOnline, | |
| 112 weak_ptr_factory_.GetWeakPtr(), navigated_url)); | |
| 113 } | 86 } |
| 114 | 87 |
| 115 void OfflinePageTabHelper::DidFinishNavigation( | 88 void OfflinePageTabHelper::DidFinishNavigation( |
| 116 content::NavigationHandle* navigation_handle) { | 89 content::NavigationHandle* navigation_handle) { |
| 117 // Skips non-main frame. | 90 // Skips non-main frame. |
| 118 if (!navigation_handle->IsInMainFrame()) | 91 if (!navigation_handle->IsInMainFrame()) |
| 119 return; | 92 return; |
| 120 | 93 |
| 121 GURL navigated_url = navigation_handle->GetURL(); | 94 GURL navigated_url = navigation_handle->GetURL(); |
| 122 net::Error error_code = navigation_handle->GetNetErrorCode(); | 95 net::Error error_code = navigation_handle->GetNetErrorCode(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 !entry->GetRedirectChain().empty() && | 239 !entry->GetRedirectChain().empty() && |
| 267 entry->GetRedirectChain().back() == to_url; | 240 entry->GetRedirectChain().back() == to_url; |
| 268 } | 241 } |
| 269 | 242 |
| 270 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { | 243 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { |
| 271 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", | 244 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", |
| 272 static_cast<int>(result), | 245 static_cast<int>(result), |
| 273 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); | 246 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); |
| 274 } | 247 } |
| 275 } // namespace offline_pages | 248 } // namespace offline_pages |
| OLD | NEW |