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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Whether using offline pages for slow networks is allowed and the network is | 47 // Whether using offline pages for slow networks is allowed and the network is |
48 // currently estimated to be prohibitively slow. | 48 // currently estimated to be prohibitively slow. |
49 bool ShouldUseOfflineForSlowNetwork(content::BrowserContext* context) { | 49 bool ShouldUseOfflineForSlowNetwork(content::BrowserContext* context) { |
50 if (!previews::IsOfflinePreviewsEnabled()) | 50 if (!previews::IsOfflinePreviewsEnabled()) |
51 return false; | 51 return false; |
52 Profile* profile = Profile::FromBrowserContext(context); | 52 Profile* profile = Profile::FromBrowserContext(context); |
53 UINetworkQualityEstimatorService* nqe_service = | 53 UINetworkQualityEstimatorService* nqe_service = |
54 UINetworkQualityEstimatorServiceFactory::GetForProfile(profile); | 54 UINetworkQualityEstimatorServiceFactory::GetForProfile(profile); |
55 if (!nqe_service) | 55 if (!nqe_service) |
56 return false; | 56 return false; |
57 net::NetworkQualityEstimator::EffectiveConnectionType | 57 net::EffectiveConnectionType effective_connection_type = |
58 effective_connection_type = nqe_service->GetEffectiveConnectionType(); | 58 nqe_service->GetEffectiveConnectionType(); |
59 return effective_connection_type >= | 59 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && |
60 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_OFFLINE && | 60 effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
61 effective_connection_type <= | |
62 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; | |
63 } | 61 } |
64 | 62 |
65 class DefaultDelegate : public OfflinePageTabHelper::Delegate { | 63 class DefaultDelegate : public OfflinePageTabHelper::Delegate { |
66 public: | 64 public: |
67 DefaultDelegate() {} | 65 DefaultDelegate() {} |
68 // offline_pages::OfflinePageTabHelper::Delegate implementation: | 66 // offline_pages::OfflinePageTabHelper::Delegate implementation: |
69 bool GetTabId(content::WebContents* web_contents, | 67 bool GetTabId(content::WebContents* web_contents, |
70 std::string* tab_id) const override { | 68 std::string* tab_id) const override { |
71 int temp_tab_id; | 69 int temp_tab_id; |
72 if (!OfflinePageUtils::GetTabId(web_contents, &temp_tab_id)) | 70 if (!OfflinePageUtils::GetTabId(web_contents, &temp_tab_id)) |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 entry->GetRedirectChain().back() == to_url; | 321 entry->GetRedirectChain().back() == to_url; |
324 } | 322 } |
325 | 323 |
326 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { | 324 void OfflinePageTabHelper::ReportRedirectResultUMA(RedirectResult result) { |
327 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", | 325 UMA_HISTOGRAM_ENUMERATION("OfflinePages.RedirectResult", |
328 static_cast<int>(result), | 326 static_cast<int>(result), |
329 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); | 327 static_cast<int>(RedirectResult::REDIRECT_RESULT_MAX)); |
330 } | 328 } |
331 | 329 |
332 } // namespace offline_pages | 330 } // namespace offline_pages |
OLD | NEW |