| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/net/spdyproxy/proxy_advisor.h" | 5 #include "chrome/browser/net/spdyproxy/proxy_advisor.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
| 17 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
| 18 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
| 19 #include "net/proxy/proxy_info.h" | 20 #include "net/proxy/proxy_info.h" |
| 20 #include "net/proxy/proxy_service.h" | 21 #include "net/proxy/proxy_service.h" |
| 21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
| 23 | 24 |
| 25 // TODO(marq): Remove this class because it is not being used. |
| 26 |
| 24 // Ensure data reduction features are available. | 27 // Ensure data reduction features are available. |
| 25 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 28 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 26 #error proxy_advisor should only be included in Android or iOS builds. | 29 #error proxy_advisor should only be included in Android or iOS builds. |
| 27 #endif | 30 #endif |
| 28 | 31 |
| 29 using content::BrowserThread; | 32 using content::BrowserThread; |
| 30 using data_reduction_proxy::DataReductionProxySettings; | 33 using data_reduction_proxy::DataReductionProxySettings; |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 const char kOmniboxMotivation[] = "omnibox"; | 36 const char kOmniboxMotivation[] = "omnibox"; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 chrome_browser_net::UrlInfo::ResolutionMotivation motivation, | 115 chrome_browser_net::UrlInfo::ResolutionMotivation motivation, |
| 113 bool is_preconnect) { | 116 bool is_preconnect) { |
| 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 115 | 118 |
| 116 if (!WouldProxyURL(url)) | 119 if (!WouldProxyURL(url)) |
| 117 return; | 120 return; |
| 118 | 121 |
| 119 std::string motivation_name(MotivationName(motivation, is_preconnect)); | 122 std::string motivation_name(MotivationName(motivation, is_preconnect)); |
| 120 std::string header_value = motivation_name + " " + url.spec(); | 123 std::string header_value = motivation_name + " " + url.spec(); |
| 121 net::URLRequestContext* context = context_getter_->GetURLRequestContext(); | 124 net::URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 125 data_reduction_proxy::DataReductionProxyParams params( |
| 126 data_reduction_proxy::DataReductionProxyParams::kAllowed | |
| 127 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed | |
| 128 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed); |
| 122 std::string endpoint = | 129 std::string endpoint = |
| 123 DataReductionProxySettings::GetDataReductionProxyOrigin() + "preconnect"; | 130 params.origin().spec() + "preconnect"; |
| 124 scoped_ptr<net::URLRequest> request = context->CreateRequest( | 131 scoped_ptr<net::URLRequest> request = context->CreateRequest( |
| 125 GURL(endpoint), net::DEFAULT_PRIORITY, this, NULL); | 132 GURL(endpoint), net::DEFAULT_PRIORITY, this, NULL); |
| 126 request->set_method("HEAD"); | 133 request->set_method("HEAD"); |
| 127 request->SetExtraRequestHeaderByName( | 134 request->SetExtraRequestHeaderByName( |
| 128 "Proxy-Host-Advisory", header_value, false); | 135 "Proxy-Host-Advisory", header_value, false); |
| 129 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 136 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 130 net::LOAD_DO_NOT_SAVE_COOKIES | | 137 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 131 net::LOAD_BYPASS_PROXY | | 138 net::LOAD_BYPASS_PROXY | |
| 132 net::LOAD_DISABLE_CACHE); | 139 net::LOAD_DISABLE_CACHE); |
| 133 net::URLRequest* raw_request = request.get(); | 140 net::URLRequest* raw_request = request.get(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 153 scoped_ptr<net::URLRequest> scoped_request_for_deletion(request); | 160 scoped_ptr<net::URLRequest> scoped_request_for_deletion(request); |
| 154 inflight_requests_.erase(request); | 161 inflight_requests_.erase(request); |
| 155 // |scoped_request_for_deletion| will delete |request| | 162 // |scoped_request_for_deletion| will delete |request| |
| 156 } | 163 } |
| 157 | 164 |
| 158 void ProxyAdvisor::UpdateProxyState() { | 165 void ProxyAdvisor::UpdateProxyState() { |
| 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 160 // Delete all inflight requests. Each request's destructor will call Cancel(). | 167 // Delete all inflight requests. Each request's destructor will call Cancel(). |
| 161 STLDeleteElements(&inflight_requests_); | 168 STLDeleteElements(&inflight_requests_); |
| 162 } | 169 } |
| OLD | NEW |