| 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 "components/previews/core/previews_io_data.h" | 5 #include "components/previews/core/previews_io_data.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/time/default_clock.h" | 14 #include "base/time/default_clock.h" |
| 15 #include "components/previews/core/previews_black_list.h" | 15 #include "components/previews/core/previews_black_list.h" |
| 16 #include "components/previews/core/previews_opt_out_store.h" | 16 #include "components/previews/core/previews_opt_out_store.h" |
| 17 #include "components/previews/core/previews_ui_service.h" | 17 #include "components/previews/core/previews_ui_service.h" |
| 18 #include "net/base/load_flags.h" |
| 18 #include "net/nqe/network_quality_estimator.h" | 19 #include "net/nqe/network_quality_estimator.h" |
| 19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace previews { | 24 namespace previews { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, | 28 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 LogPreviewsEligibilityReason( | 111 LogPreviewsEligibilityReason( |
| 111 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type); | 112 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type); |
| 112 return false; | 113 return false; |
| 113 } | 114 } |
| 114 if (network_quality_estimator->GetEffectiveConnectionType() > | 115 if (network_quality_estimator->GetEffectiveConnectionType() > |
| 115 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G) { | 116 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G) { |
| 116 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW, | 117 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW, |
| 117 type); | 118 type); |
| 118 return false; | 119 return false; |
| 119 } | 120 } |
| 121 // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page. |
| 122 // If this is a query for offline previews, reloads should be disallowed. |
| 123 if (type == PreviewsType::OFFLINE && |
| 124 request.load_flags() & |
| 125 (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) { |
| 126 LogPreviewsEligibilityReason( |
| 127 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE, type); |
| 128 return false; |
| 129 } |
| 120 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); | 130 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); |
| 121 return true; | 131 return true; |
| 122 } | 132 } |
| 123 | 133 |
| 124 } // namespace previews | 134 } // namespace previews |
| OLD | NEW |