Chromium Code Reviews| Index: components/previews/core/previews_io_data.cc |
| diff --git a/components/previews/core/previews_io_data.cc b/components/previews/core/previews_io_data.cc |
| index 67403a17c3d84fcaa3521e3f7ecb548178b8ef6b..5a34ec0a445623c8fa03315172f0990255676b01 100644 |
| --- a/components/previews/core/previews_io_data.cc |
| +++ b/components/previews/core/previews_io_data.cc |
| @@ -4,15 +4,18 @@ |
| #include "components/previews/core/previews_io_data.h" |
| +#include <string> |
|
tbansal1
2017/05/02 21:49:31
This is already included in the header file, so it
RyanSturm
2017/05/02 22:57:19
Done.
|
| + |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/files/file_path.h" |
| #include "base/location.h" |
| #include "base/memory/ptr_util.h" |
| -#include "base/metrics/histogram_macros.h" |
| +#include "base/metrics/histogram.h" |
| #include "base/sequenced_task_runner.h" |
| #include "base/time/default_clock.h" |
| #include "components/previews/core/previews_black_list.h" |
| +#include "components/previews/core/previews_experiments.h" |
| #include "components/previews/core/previews_opt_out_store.h" |
| #include "components/previews/core/previews_ui_service.h" |
| #include "net/base/load_flags.h" |
| @@ -27,25 +30,23 @@ namespace { |
| void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, |
| PreviewsType type) { |
| - switch (type) { |
| - case PreviewsType::OFFLINE: |
| - UMA_HISTOGRAM_ENUMERATION( |
| - "Previews.EligibilityReason.Offline", static_cast<int>(status), |
| - static_cast<int>(PreviewsEligibilityReason::LAST)); |
| - break; |
| - case PreviewsType::CLIENT_LOFI: |
| - UMA_HISTOGRAM_ENUMERATION( |
| - "Previews.EligibilityReason.ClientLoFi", static_cast<int>(status), |
| - static_cast<int>(PreviewsEligibilityReason::LAST)); |
| - break; |
| - default: |
| - NOTREACHED(); |
| - } |
| + std::string histogram_name("Previews.EligibilityReason."); |
| + histogram_name.append(GetStringNameForType(type)); |
|
tbansal1
2017/05/02 21:49:31
same here.
Use StringPiece of Printf as mentioned
RyanSturm
2017/05/02 22:57:19
Done.
|
| + int32_t max_limit = static_cast<int32_t>(PreviewsEligibilityReason::LAST); |
| + |
| + base::LinearHistogram::FactoryGet( |
| + histogram_name, 0, max_limit, max_limit + 1, |
|
tbansal1
2017/05/02 21:49:31
min_bucket should be >= 1.
https://cs.chromium.org
RyanSturm
2017/05/02 22:57:19
Done.
|
| + base::HistogramBase::kUmaTargetedHistogramFlag) |
| + ->Add(static_cast<int>(status)); |
| } |
| net::EffectiveConnectionType GetEffectiveConnectionTypeThresholdForPreviewsType( |
| PreviewsType type) { |
| switch (type) { |
| + // These types check network qualtiy on their own. |
|
tbansal1
2017/05/02 21:49:31
typo in quality.
RyanSturm
2017/05/02 22:57:19
Done.
|
| + case PreviewsType::LITE_PAGE: |
| + case PreviewsType::SERVER_LOFI: |
| + return net::EFFECTIVE_CONNECTION_TYPE_4G; |
| case PreviewsType::OFFLINE: |
| return params::EffectiveConnectionTypeThresholdForOffline(); |
| case PreviewsType::CLIENT_LOFI: |
| @@ -58,6 +59,24 @@ net::EffectiveConnectionType GetEffectiveConnectionTypeThresholdForPreviewsType( |
| return net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
| } |
| +bool AllowedOnReload(PreviewsType type) { |
| + switch (type) { |
| + // These types return new content on refresh. |
| + case PreviewsType::LITE_PAGE: |
| + case PreviewsType::SERVER_LOFI: |
| + case PreviewsType::CLIENT_LOFI: |
| + return true; |
| + // Loading these types will always be stale when refreshed. |
| + case PreviewsType::OFFLINE: |
| + return false; |
| + case PreviewsType::NONE: |
| + case PreviewsType::LAST: |
| + break; |
| + } |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| } // namespace |
| PreviewsIOData::PreviewsIOData( |
| @@ -119,7 +138,7 @@ bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, |
| return false; |
| // The blacklist will disallow certain hosts for periods of time based on |
| - // user's opting out of the preview |
| + // user's opting out of the preview. |
| PreviewsEligibilityReason status = |
| previews_black_list_->IsLoadedAndAllowed(request.url(), type); |
| if (status != PreviewsEligibilityReason::ALLOWED) { |
| @@ -144,13 +163,14 @@ bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, |
| } |
| // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page. |
| // If this is a query for offline previews, reloads should be disallowed. |
| - if (type == PreviewsType::OFFLINE && |
| - (request.load_flags() & |
| - (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE))) { |
| - LogPreviewsEligibilityReason( |
| - PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE, type); |
| + if (!AllowedOnReload(type) && |
| + request.load_flags() & |
| + (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) { |
| + LogPreviewsEligibilityReason(PreviewsEligibilityReason::RELOAD_DISALLOWED, |
| + type); |
| return false; |
| } |
| + |
| LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); |
| return true; |
| } |