Chromium Code Reviews| Index: components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc |
| diff --git a/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0c56cc4045cf1d21078e6c37e08b5834111ee5a7 |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.cc |
| @@ -0,0 +1,149 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_debug_resource_throttle.h" |
| + |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_debug_ui_service.h" |
| +#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" |
| +#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/resource_controller.h" |
| +#include "content/public/browser/resource_request_info.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/http/http_response_headers.h" |
| +#include "net/url_request/url_request.h" |
| + |
| +namespace data_reduction_proxy { |
| + |
| +namespace { |
| + |
|
bengr
2015/02/05 00:23:47
Remove blank line.
megjablon
2015/02/07 05:15:14
Done.
|
| +const char kResourceThrottleLogName[] = |
| + "DataReductionProxyDebugResourceThrottle"; |
| + |
|
bengr
2015/02/05 00:23:46
Remove blank line.
megjablon
2015/02/07 05:15:13
Done.
|
| +} // namespace |
| + |
| +DataReductionProxyDebugResourceThrottle:: |
| +DataReductionProxyDebugResourceThrottle( |
| + const net::URLRequest* request, |
| + content::ResourceType resource_type, |
| + const DataReductionProxyDebugUIService* ui_service, |
| + const DataReductionProxyParams* params) |
| + : state_(NOT_BYPASSED), |
| + request_(request), |
| + ui_service_(ui_service), |
| + params_(params), |
| + is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { |
| + DCHECK(request); |
| + DCHECK(ui_service); |
| + DCHECK(params); |
| +} |
| + |
| +DataReductionProxyDebugResourceThrottle:: |
| +~DataReductionProxyDebugResourceThrottle() { |
| +} |
| + |
| +// static |
| +scoped_ptr<DataReductionProxyDebugResourceThrottle> |
|
bengr
2015/02/05 00:23:46
Move static methods above constructor, here and in
megjablon
2015/02/07 05:15:14
Done.
|
| +DataReductionProxyDebugResourceThrottle::MaybeCreate( |
| + const net::URLRequest* request, |
| + content::ResourceType resource_type, |
| + const DataReductionProxyIOData* io_data) { |
|
bengr
2015/02/05 00:23:46
DCHECK request?
megjablon
2015/02/07 05:15:14
Done.
|
| + if (io_data->IsEnabled() && |
| + data_reduction_proxy::DataReductionProxyParams:: |
| + WarnIfNoDataReductionProxy()) { |
| + DCHECK(io_data->params()); |
| + DCHECK(io_data->debug_ui_service()); |
| + return scoped_ptr<DataReductionProxyDebugResourceThrottle>( |
| + new DataReductionProxyDebugResourceThrottle(request, resource_type, |
| + io_data->debug_ui_service(), |
| + io_data->params())); |
| + } |
| + return nullptr; |
| +} |
| + |
| +// Displays an interstitial when the proxy will not be used for a request |
| +// because it isn't configured. |
| +void DataReductionProxyDebugResourceThrottle::WillStartUsingNetwork( |
| + bool* defer) { |
| + DCHECK_EQ(NOT_BYPASSED, state_); |
| + if (!params_->AreDataReductionProxiesBypassed( |
| + *request_, ui_service_->data_reduction_proxy_config(), NULL)) { |
| + return; |
| + } |
| + if (request_->load_flags() & net::LOAD_PREFETCH) { |
| + // Don't prefetch resources that bypass, disallow them. |
| + controller()->Cancel(); |
| + return; |
| + } |
| + // Do not display the interstitial if bypassed by local rules. |
| + if (params_->IsBypassedByDataReductionProxyLocalRules( |
| + *request_, ui_service_->data_reduction_proxy_config())) { |
| + state_ = LOCAL_BYPASS; |
| + return; |
| + } |
| + DisplayBlockingPage(defer); |
| +} |
| + |
| +// Displays an intersitital when the Data Reduction Proxy explicitly returns a |
| +// response that triggers a bypass. |
| +void DataReductionProxyDebugResourceThrottle::WillRedirectRequest( |
| + const GURL& new_url, |
| + bool* defer) { |
| + // If the interstitial has already been shown, do not show it again. The |
| + // LOAD_BYPASS_PROXY flag makes it so that proxies are not resolved. This |
| + // override is used when downloading PAC files. If the request does not have |
| + // the LOAD_BYPASS_PROXY flag, do not show the interstitial. |
| + if (state_ != NOT_BYPASSED || |
| + !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) { |
| + return; |
| + } |
| + DisplayBlockingPage(defer); |
| +} |
| + |
| +const char* DataReductionProxyDebugResourceThrottle::GetNameForLogging() const { |
| + return kResourceThrottleLogName; |
| +} |
| + |
| +// static |
| +void DataReductionProxyDebugResourceThrottle::StartDisplayingBlockingPage( |
| + scoped_refptr<DataReductionProxyDebugUIManager> ui_manager, |
| + const DataReductionProxyDebugUIManager::BypassResource& resource) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + ui_manager->DisplayBlockingPage(resource); |
| +} |
| + |
| +void DataReductionProxyDebugResourceThrottle::DisplayBlockingPage(bool* defer) { |
| + const content::ResourceRequestInfo* info = |
| + content::ResourceRequestInfo::ForRequest(request_); |
| + DCHECK(info); |
| + |
| + state_ = REMOTE_BYPASS; |
| + *defer = true; |
| + |
| + DataReductionProxyDebugUIManager::BypassResource resource; |
| + resource.url = request_->url(); |
| + resource.is_subresource = is_subresource_; |
| + resource.callback = base::Bind( |
| + &DataReductionProxyDebugResourceThrottle::OnBlockingPageComplete, |
| + AsWeakPtr()); |
| + resource.render_process_host_id = info->GetChildID(); |
| + resource.render_view_id = info->GetRouteID(); |
| + |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::UI, FROM_HERE, |
| + base::Bind( |
| + &DataReductionProxyDebugResourceThrottle::StartDisplayingBlockingPage, |
| + ui_service_->ui_manager(), resource)); |
| +} |
| + |
| +void |
| +DataReductionProxyDebugResourceThrottle::OnBlockingPageComplete(bool proceed) { |
| + state_ = NOT_BYPASSED; |
| + if (proceed) |
| + controller()->Resume(); |
| + else |
| + controller()->Cancel(); |
| +} |
| + |
| +} // namespace data_reduction_proxy |