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/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
14 #include "components/previews/core/previews_black_list.h" | 14 #include "components/previews/core/previews_black_list.h" |
15 #include "components/previews/core/previews_experiments.h" | |
16 #include "components/previews/core/previews_opt_out_store.h" | 15 #include "components/previews/core/previews_opt_out_store.h" |
17 #include "components/previews/core/previews_ui_service.h" | 16 #include "components/previews/core/previews_ui_service.h" |
18 #include "net/nqe/network_quality_estimator.h" | 17 #include "net/nqe/network_quality_estimator.h" |
19 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
20 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
22 | 21 |
23 namespace previews { | 22 namespace previews { |
24 | 23 |
25 PreviewsIOData::PreviewsIOData( | 24 PreviewsIOData::PreviewsIOData( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 62 } |
64 | 63 |
65 void PreviewsIOData::ClearBlackList(base::Time begin_time, | 64 void PreviewsIOData::ClearBlackList(base::Time begin_time, |
66 base::Time end_time) { | 65 base::Time end_time) { |
67 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 66 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
68 previews_black_list_->ClearBlackList(begin_time, end_time); | 67 previews_black_list_->ClearBlackList(begin_time, end_time); |
69 } | 68 } |
70 | 69 |
71 bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, | 70 bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, |
72 PreviewsType type) const { | 71 PreviewsType type) const { |
73 if (!IsOfflinePreviewsEnabled()) | 72 if (!IsPreviewsTypeEnabled(type)) |
74 return false; | 73 return false; |
75 // The blacklist will disallow certain hosts for periods of time based on | 74 // The blacklist will disallow certain hosts for periods of time based on |
76 // user's opting out of the preview | 75 // user's opting out of the preview |
77 if (!previews_black_list_ || | 76 if (!previews_black_list_ || |
78 !previews_black_list_->IsLoadedAndAllowed(request.url(), type)) { | 77 !previews_black_list_->IsLoadedAndAllowed(request.url(), type)) { |
79 return false; | 78 return false; |
80 } | 79 } |
81 net::NetworkQualityEstimator* network_quality_estimator = | 80 net::NetworkQualityEstimator* network_quality_estimator = |
82 request.context()->network_quality_estimator(); | 81 request.context()->network_quality_estimator(); |
83 if (!network_quality_estimator) | 82 if (!network_quality_estimator) |
84 return false; | 83 return false; |
85 | 84 |
86 net::EffectiveConnectionType effective_connection_type = | 85 net::EffectiveConnectionType effective_connection_type = |
87 network_quality_estimator->GetEffectiveConnectionType(); | 86 network_quality_estimator->GetEffectiveConnectionType(); |
88 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && | 87 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && |
89 effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; | 88 effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
90 } | 89 } |
91 | 90 |
92 } // namespace previews | 91 } // namespace previews |
OLD | NEW |