Index: components/data_reduction_proxy/content/data_reduction_proxy_resource_throttle.cc |
diff --git a/components/data_reduction_proxy/content/data_reduction_proxy_resource_throttle.cc b/components/data_reduction_proxy/content/data_reduction_proxy_resource_throttle.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ade8544f2bb4d849789431d8318c426538add3a1 |
--- /dev/null |
+++ b/components/data_reduction_proxy/content/data_reduction_proxy_resource_throttle.cc |
@@ -0,0 +1,127 @@ |
+// Copyright 2014 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/data_reduction_proxy_resource_throttle.h" |
+ |
+#include "components/data_reduction_proxy/content/data_reduction_proxy_ui_manager.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 "content/public/browser/web_contents.h" |
+#include "net/base/load_flags.h" |
+#include "net/http/http_response_headers.h" |
+#include "net/url_request/url_request.h" |
+ |
+using content::BrowserThread; |
+using content::ResourceThrottle; |
+ |
+namespace data_reduction_proxy { |
+ |
+DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle( |
+ net::URLRequest* request, |
+ content::ResourceType resource_type, |
bengr
2014/10/31 17:06:48
Needs #include
megjablon
2014/12/11 23:32:04
Done.
|
+ DataReductionProxyUIService* ui_service, |
bengr
2014/10/31 17:06:47
Needs #include
megjablon
2014/12/11 23:32:05
Done.
|
+ DataReductionProxyParams* params) |
+ : state_(NOT_BYPASSED), |
+ request_(request), |
+ ui_service_(ui_service), |
+ params_(params), |
+ is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { |
+} |
+ |
+DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { } |
+ |
+void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) { |
+ CHECK(state_ == NOT_BYPASSED); |
bengr
2014/10/31 17:06:47
Why CHECK and not DCHECK?
megjablon
2014/12/11 23:32:05
Whoops
|
+ |
+ if (!params_->AreDataReductionProxiesBypassed(*request_, NULL)) |
+ return; |
+ |
+ if (request_->load_flags() & net::LOAD_PREFETCH) { |
+ // Don't prefetch resources that bypass, disallow them. |
+ controller()->Cancel(); |
+ return; |
+ } |
+ |
+ if (params_->IsBypassedByDataReductionProxyLocalRules( |
+ *request_, ui_service_->data_reduction_proxy_config())) { |
+ state_ = LOCAL_BYPASS; |
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::WillRedirectRequest( |
+ const GURL& new_url, |
+ bool* defer) { |
+ if (state_ != NOT_BYPASSED || |
+ !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) { |
bengr
2014/10/31 17:06:48
What is the point of this check? Explain in a comm
megjablon
2014/12/11 23:32:05
Done.
|
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) { |
+ if(state_ != NOT_BYPASSED) |
+ return; |
+ |
+ if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) || |
bengr
2014/10/31 17:06:47
Is this the only scheme you'll want to ignore? Wha
megjablon
2014/12/11 23:32:04
Why would we want to ignore ws?
|
+ request_->url().SchemeIs("chrome")) { |
+ return; |
+ } |
+ |
+ DisplayBlockingPage(defer); |
+} |
+ |
+void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { |
+ const content::ResourceRequestInfo* info = |
+ content::ResourceRequestInfo::ForRequest(request_); |
+ |
bengr
2014/10/31 17:06:48
DCHECK(info)
megjablon
2014/12/11 23:32:05
Done.
|
+ state_ = REMOTE_BYPASS; |
+ DataReductionProxyUIManager::BypassResource resource; |
+ resource.url = request_->url(); |
+ resource.is_subresource = is_subresource_; |
+ // TODO(megjablon): Detect the page type. |
+ resource.blocking_page_type = DRP_TECHNICAL_DIFFICULTIES; |
+ resource.callback = base::Bind( |
+ &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); |
+ resource.render_process_host_id = info->GetChildID(); |
+ resource.render_view_id = info->GetRouteID(); |
+ |
+ *defer = true; |
+ |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind( |
+ &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, |
+ AsWeakPtr(), |
+ ui_service_->ui_manager(), |
+ resource)); |
+} |
+ |
+const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { |
+ return "DataReductionProxyResourceThrottle"; |
bengr
2014/10/31 17:06:47
define this as a constant in an anonymous namespac
megjablon
2014/12/11 23:32:05
Done.
|
+} |
+ |
+// static |
+void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( |
+ const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle, |
+ scoped_refptr<DataReductionProxyUIManager> ui_manager, |
+ const DataReductionProxyUIManager::BypassResource& resource) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ ui_manager->DisplayBlockingPage(resource); |
+} |
+ |
+void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { |
+ if (proceed) |
+ controller()->Resume(); |
+ else |
+ controller()->Cancel(); |
+} |
+ |
+} // namespace data_reduction_proxy |