OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/data_reduction_proxy/content/data_reduction_proxy_resource_ throttle.h" | |
6 | |
7 #include "components/data_reduction_proxy/content/data_reduction_proxy_ui_manage r.h" | |
8 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/resource_controller.h" | |
11 #include "content/public/browser/resource_request_info.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 #include "net/base/load_flags.h" | |
14 #include "net/http/http_response_headers.h" | |
15 #include "net/url_request/url_request.h" | |
16 | |
17 using content::BrowserThread; | |
18 using content::ResourceThrottle; | |
19 | |
20 namespace data_reduction_proxy { | |
21 | |
22 DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle( | |
23 net::URLRequest* request, | |
24 content::ResourceType resource_type, | |
bengr
2014/10/31 17:06:48
Needs #include
megjablon
2014/12/11 23:32:04
Done.
| |
25 DataReductionProxyUIService* ui_service, | |
bengr
2014/10/31 17:06:47
Needs #include
megjablon
2014/12/11 23:32:05
Done.
| |
26 DataReductionProxyParams* params) | |
27 : state_(NOT_BYPASSED), | |
28 request_(request), | |
29 ui_service_(ui_service), | |
30 params_(params), | |
31 is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) { | |
32 } | |
33 | |
34 DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { } | |
35 | |
36 void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) { | |
37 CHECK(state_ == NOT_BYPASSED); | |
bengr
2014/10/31 17:06:47
Why CHECK and not DCHECK?
megjablon
2014/12/11 23:32:05
Whoops
| |
38 | |
39 if (!params_->AreDataReductionProxiesBypassed(*request_, NULL)) | |
40 return; | |
41 | |
42 if (request_->load_flags() & net::LOAD_PREFETCH) { | |
43 // Don't prefetch resources that bypass, disallow them. | |
44 controller()->Cancel(); | |
45 return; | |
46 } | |
47 | |
48 if (params_->IsBypassedByDataReductionProxyLocalRules( | |
49 *request_, ui_service_->data_reduction_proxy_config())) { | |
50 state_ = LOCAL_BYPASS; | |
51 return; | |
52 } | |
53 | |
54 DisplayBlockingPage(defer); | |
55 } | |
56 | |
57 void DataReductionProxyResourceThrottle::WillRedirectRequest( | |
58 const GURL& new_url, | |
59 bool* defer) { | |
60 if (state_ != NOT_BYPASSED || | |
61 !(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.
| |
62 return; | |
63 } | |
64 | |
65 DisplayBlockingPage(defer); | |
66 } | |
67 | |
68 void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) { | |
69 if(state_ != NOT_BYPASSED) | |
70 return; | |
71 | |
72 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?
| |
73 request_->url().SchemeIs("chrome")) { | |
74 return; | |
75 } | |
76 | |
77 DisplayBlockingPage(defer); | |
78 } | |
79 | |
80 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) { | |
81 const content::ResourceRequestInfo* info = | |
82 content::ResourceRequestInfo::ForRequest(request_); | |
83 | |
bengr
2014/10/31 17:06:48
DCHECK(info)
megjablon
2014/12/11 23:32:05
Done.
| |
84 state_ = REMOTE_BYPASS; | |
85 DataReductionProxyUIManager::BypassResource resource; | |
86 resource.url = request_->url(); | |
87 resource.is_subresource = is_subresource_; | |
88 // TODO(megjablon): Detect the page type. | |
89 resource.blocking_page_type = DRP_TECHNICAL_DIFFICULTIES; | |
90 resource.callback = base::Bind( | |
91 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr()); | |
92 resource.render_process_host_id = info->GetChildID(); | |
93 resource.render_view_id = info->GetRouteID(); | |
94 | |
95 *defer = true; | |
96 | |
97 content::BrowserThread::PostTask( | |
98 content::BrowserThread::UI, | |
99 FROM_HERE, | |
100 base::Bind( | |
101 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage, | |
102 AsWeakPtr(), | |
103 ui_service_->ui_manager(), | |
104 resource)); | |
105 } | |
106 | |
107 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const { | |
108 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.
| |
109 } | |
110 | |
111 // static | |
112 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage( | |
113 const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle, | |
114 scoped_refptr<DataReductionProxyUIManager> ui_manager, | |
115 const DataReductionProxyUIManager::BypassResource& resource) { | |
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
117 ui_manager->DisplayBlockingPage(resource); | |
118 } | |
119 | |
120 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) { | |
121 if (proceed) | |
122 controller()->Resume(); | |
123 else | |
124 controller()->Cancel(); | |
125 } | |
126 | |
127 } // namespace data_reduction_proxy | |
OLD | NEW |