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 "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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace previews { | 24 namespace previews { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, | 28 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, |
| 29 PreviewsType type) { | 29 PreviewsType type) { |
| 30 switch (type) { | 30 switch (type) { |
| 31 case PreviewsType::LITE_PAGE: | |
| 32 UMA_HISTOGRAM_ENUMERATION( | |
| 33 "Previews.EligibilityReason.LitePage", static_cast<int>(status), | |
|
tbansal1
2017/03/20 22:55:13
Maybe use histogram factory here to avoid code dup
RyanSturm
2017/05/02 20:08:12
Done.
| |
| 34 static_cast<int>(PreviewsEligibilityReason::LAST)); | |
| 35 break; | |
| 36 case PreviewsType::SERVER_LOFI: | |
| 37 UMA_HISTOGRAM_ENUMERATION( | |
| 38 "Previews.EligibilityReason.ServerLoFi", static_cast<int>(status), | |
| 39 static_cast<int>(PreviewsEligibilityReason::LAST)); | |
| 40 break; | |
| 31 case PreviewsType::OFFLINE: | 41 case PreviewsType::OFFLINE: |
| 32 UMA_HISTOGRAM_ENUMERATION( | 42 UMA_HISTOGRAM_ENUMERATION( |
| 33 "Previews.EligibilityReason.Offline", static_cast<int>(status), | 43 "Previews.EligibilityReason.Offline", static_cast<int>(status), |
| 34 static_cast<int>(PreviewsEligibilityReason::LAST)); | 44 static_cast<int>(PreviewsEligibilityReason::LAST)); |
| 35 break; | 45 break; |
| 36 default: | 46 case PreviewsType::NONE: |
| 47 case PreviewsType::LAST: | |
| 37 NOTREACHED(); | 48 NOTREACHED(); |
| 38 } | 49 } |
| 39 } | 50 } |
| 40 | 51 |
| 52 bool ShouldCheckNetworkQuality(PreviewsType type) { | |
|
tbansal1
2017/03/20 22:55:13
May be change it to return the ECT threshold?
and
RyanSturm
2017/05/02 20:08:12
Acknowledged.
| |
| 53 switch (type) { | |
| 54 // These types check network qualtiy on their own. | |
| 55 case PreviewsType::LITE_PAGE: | |
| 56 case PreviewsType::SERVER_LOFI: | |
| 57 return false; | |
| 58 // These types use the default previews network quality behavior. | |
| 59 case PreviewsType::OFFLINE: | |
| 60 return true; | |
| 61 case PreviewsType::NONE: | |
| 62 case PreviewsType::LAST: | |
| 63 break; | |
| 64 } | |
| 65 NOTREACHED(); | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 bool AllowedOnReload(PreviewsType type) { | |
| 70 switch (type) { | |
| 71 // These types return new content on refresh. | |
| 72 case PreviewsType::LITE_PAGE: | |
| 73 case PreviewsType::SERVER_LOFI: | |
| 74 return true; | |
| 75 // Loading these types will always be stale when refreshed. | |
| 76 case PreviewsType::OFFLINE: | |
| 77 return false; | |
| 78 case PreviewsType::NONE: | |
| 79 case PreviewsType::LAST: | |
| 80 break; | |
| 81 } | |
| 82 NOTREACHED(); | |
| 83 return false; | |
| 84 } | |
| 85 | |
| 41 } // namespace | 86 } // namespace |
| 42 | 87 |
| 43 PreviewsIOData::PreviewsIOData( | 88 PreviewsIOData::PreviewsIOData( |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 89 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 45 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 90 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 46 : ui_task_runner_(ui_task_runner), | 91 : ui_task_runner_(ui_task_runner), |
| 47 io_task_runner_(io_task_runner), | 92 io_task_runner_(io_task_runner), |
| 48 weak_factory_(this) {} | 93 weak_factory_(this) {} |
| 49 | 94 |
| 50 PreviewsIOData::~PreviewsIOData() {} | 95 PreviewsIOData::~PreviewsIOData() {} |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 return false; | 144 return false; |
| 100 | 145 |
| 101 // The blacklist will disallow certain hosts for periods of time based on | 146 // The blacklist will disallow certain hosts for periods of time based on |
| 102 // user's opting out of the preview | 147 // user's opting out of the preview |
| 103 PreviewsEligibilityReason status = | 148 PreviewsEligibilityReason status = |
| 104 previews_black_list_->IsLoadedAndAllowed(request.url(), type); | 149 previews_black_list_->IsLoadedAndAllowed(request.url(), type); |
| 105 if (status != PreviewsEligibilityReason::ALLOWED) { | 150 if (status != PreviewsEligibilityReason::ALLOWED) { |
| 106 LogPreviewsEligibilityReason(status, type); | 151 LogPreviewsEligibilityReason(status, type); |
| 107 return false; | 152 return false; |
| 108 } | 153 } |
| 109 net::NetworkQualityEstimator* network_quality_estimator = | 154 if (ShouldCheckNetworkQuality(type)) { |
|
tbansal1
2017/03/20 22:55:13
nit: it might be more readable to move this (inclu
RyanSturm
2017/05/02 20:08:12
Done.
| |
| 110 request.context()->network_quality_estimator(); | 155 net::NetworkQualityEstimator* network_quality_estimator = |
| 111 if (!network_quality_estimator || | 156 request.context()->network_quality_estimator(); |
| 112 network_quality_estimator->GetEffectiveConnectionType() < | 157 if (!network_quality_estimator || |
| 113 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) { | 158 network_quality_estimator->GetEffectiveConnectionType() < |
| 114 LogPreviewsEligibilityReason( | 159 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) { |
| 115 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type); | 160 LogPreviewsEligibilityReason( |
| 116 return false; | 161 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type); |
| 117 } | 162 return false; |
| 118 if (network_quality_estimator->GetEffectiveConnectionType() > | 163 } |
| 119 params::EffectiveConnectionTypeThreshold()) { | 164 if (network_quality_estimator->GetEffectiveConnectionType() > |
| 120 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW, | 165 params::EffectiveConnectionTypeThreshold()) { |
| 121 type); | 166 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW, |
| 122 return false; | 167 type); |
| 123 } | 168 return false; |
| 124 // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page. | 169 } |
| 125 // If this is a query for offline previews, reloads should be disallowed. | 170 // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page. |
| 126 if (type == PreviewsType::OFFLINE && | 171 // If this is a query for offline previews, reloads should be disallowed. |
| 127 request.load_flags() & | 172 if (!AllowedOnReload(type) && |
| 128 (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) { | 173 request.load_flags() & |
| 129 LogPreviewsEligibilityReason( | 174 (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) { |
| 130 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE, type); | 175 LogPreviewsEligibilityReason(PreviewsEligibilityReason::RELOAD_DISALLOWED, |
| 131 return false; | 176 type); |
| 177 return false; | |
| 178 } | |
| 132 } | 179 } |
| 133 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); | 180 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); |
| 134 return true; | 181 return true; |
| 135 } | 182 } |
| 136 | 183 |
| 137 } // namespace previews | 184 } // namespace previews |
| OLD | NEW |