| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv
ice.h" |
| 6 | 6 |
| 7 #include "base/sequenced_task_runner.h" | 7 #include "base/sequenced_task_runner.h" |
| 8 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" | 8 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" |
| 9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/url_request/url_fetcher.h" | |
| 11 #include "net/url_request/url_request_status.h" | |
| 12 | 10 |
| 13 namespace data_reduction_proxy { | 11 namespace data_reduction_proxy { |
| 14 | 12 |
| 15 DataReductionProxyService::DataReductionProxyService( | 13 DataReductionProxyService::DataReductionProxyService( |
| 16 scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, | 14 scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, |
| 17 DataReductionProxySettings* settings, | 15 DataReductionProxySettings* settings) |
| 18 net::URLRequestContextGetter* request_context_getter) | 16 : settings_(settings), |
| 19 : url_request_context_getter_(request_context_getter), | |
| 20 settings_(settings), | |
| 21 weak_factory_(this) { | 17 weak_factory_(this) { |
| 22 DCHECK(settings); | 18 DCHECK(settings); |
| 23 statistics_prefs_ = statistics_prefs.Pass(); | 19 statistics_prefs_ = statistics_prefs.Pass(); |
| 24 } | 20 } |
| 25 | 21 |
| 26 DataReductionProxyService::~DataReductionProxyService() { | 22 DataReductionProxyService::~DataReductionProxyService() { |
| 27 } | 23 } |
| 28 | 24 |
| 29 void DataReductionProxyService::Shutdown() { | 25 void DataReductionProxyService::Shutdown() { |
| 30 DCHECK(CalledOnValidThread()); | 26 DCHECK(CalledOnValidThread()); |
| 31 weak_factory_.InvalidateWeakPtrs(); | 27 weak_factory_.InvalidateWeakPtrs(); |
| 32 } | 28 } |
| 33 | 29 |
| 34 void DataReductionProxyService::EnableCompressionStatisticsLogging( | 30 void DataReductionProxyService::EnableCompressionStatisticsLogging( |
| 35 PrefService* prefs, | 31 PrefService* prefs, |
| 36 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 32 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 37 const base::TimeDelta& commit_delay) { | 33 const base::TimeDelta& commit_delay) { |
| 38 DCHECK(!statistics_prefs_); | 34 DCHECK(!statistics_prefs_); |
| 39 statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( | 35 statistics_prefs_.reset(new DataReductionProxyStatisticsPrefs( |
| 40 prefs, ui_task_runner, commit_delay)); | 36 prefs, ui_task_runner, commit_delay)); |
| 41 } | 37 } |
| 42 | 38 |
| 43 base::WeakPtr<DataReductionProxyService> | 39 base::WeakPtr<DataReductionProxyService> |
| 44 DataReductionProxyService::GetWeakPtr() { | 40 DataReductionProxyService::GetWeakPtr() { |
| 45 DCHECK(CalledOnValidThread()); | 41 DCHECK(CalledOnValidThread()); |
| 46 return weak_factory_.GetWeakPtr(); | 42 return weak_factory_.GetWeakPtr(); |
| 47 } | 43 } |
| 48 | 44 |
| 49 void DataReductionProxyService::OnURLFetchComplete( | |
| 50 const net::URLFetcher* source) { | |
| 51 DCHECK(source == fetcher_.get()); | |
| 52 net::URLRequestStatus status = source->GetStatus(); | |
| 53 | |
| 54 std::string response; | |
| 55 source->GetResponseAsString(&response); | |
| 56 | |
| 57 fetcher_callback_.Run(response, status); | |
| 58 } | |
| 59 | |
| 60 net::URLFetcher* DataReductionProxyService::GetURLFetcherForSecureProxyCheck( | |
| 61 const GURL& secure_proxy_check_url) { | |
| 62 net::URLFetcher* fetcher = net::URLFetcher::Create( | |
| 63 secure_proxy_check_url, net::URLFetcher::GET, this); | |
| 64 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_BYPASS_PROXY); | |
| 65 DCHECK(url_request_context_getter_); | |
| 66 fetcher->SetRequestContext(url_request_context_getter_); | |
| 67 // Configure max retries to be at most kMaxRetries times for 5xx errors. | |
| 68 static const int kMaxRetries = 5; | |
| 69 fetcher->SetMaxRetriesOn5xx(kMaxRetries); | |
| 70 fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); | |
| 71 // The secure proxy check should not be redirected. Since the secure proxy | |
| 72 // check will inevitably fail if it gets redirected somewhere else (e.g. by a | |
| 73 // captive portal), short circuit that by giving up on the secure proxy check | |
| 74 // if it gets redirected. | |
| 75 fetcher->SetStopOnRedirect(true); | |
| 76 return fetcher; | |
| 77 } | |
| 78 | |
| 79 void DataReductionProxyService::SecureProxyCheck( | |
| 80 const GURL& secure_proxy_check_url, | |
| 81 FetcherResponseCallback fetcher_callback) { | |
| 82 DCHECK(CalledOnValidThread()); | |
| 83 net::URLFetcher* fetcher = | |
| 84 GetURLFetcherForSecureProxyCheck(secure_proxy_check_url); | |
| 85 if (!fetcher) | |
| 86 return; | |
| 87 fetcher_.reset(fetcher); | |
| 88 fetcher_callback_ = fetcher_callback; | |
| 89 fetcher_->Start(); | |
| 90 } | |
| 91 | |
| 92 } // namespace data_reduction_proxy | 45 } // namespace data_reduction_proxy |
| OLD | NEW |