Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: components/data_reduction_proxy/content/browser/data_reduction_proxy_resource_throttle.cc

Issue 684223003: Data Reduction Proxy Interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding tests and addressing comments Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/browser/data_reduction_proxy_r esource_throttle.h"
6
7 #include "components/data_reduction_proxy/content/browser/data_reduction_proxy_u i_service.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 "net/base/load_flags.h"
13 #include "net/http/http_response_headers.h"
14 #include "net/url_request/url_request.h"
15
16 namespace data_reduction_proxy {
17
18 namespace {
19
20 const char kResouceThrottleLogName[] = "DataReductionProxyResourceThrottle";
21
22 } // namespace
23
24 DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle(
25 const net::URLRequest* request,
26 content::ResourceType resource_type,
27 const DataReductionProxyUIService* ui_service,
28 const DataReductionProxyParams* params)
29 : state_(NOT_BYPASSED),
30 request_(request),
31 ui_service_(ui_service),
32 params_(params),
33 is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) {
34 DCHECK(request);
35 DCHECK(ui_service);
36 DCHECK(params);
37 }
38
39 DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() {
40 }
41
42 void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) {
43 DCHECK(state_ == NOT_BYPASSED);
44 if (!params_->AreDataReductionProxiesBypassed(*request_, NULL))
45 return;
46
47 if (request_->load_flags() & net::LOAD_PREFETCH) {
48 // Don't prefetch resources that bypass, disallow them.
49 controller()->Cancel();
50 return;
51 }
52
53 if (params_->IsBypassedByDataReductionProxyLocalRules(
54 *request_, ui_service_->data_reduction_proxy_config())) {
55 state_ = LOCAL_BYPASS;
56 return;
57 }
58
bengr 2014/12/29 18:45:41 This blank line and others in your methods aren't
megjablon 2014/12/30 23:39:59 Done.
59 DisplayBlockingPage(defer);
60 }
61
62 void DataReductionProxyResourceThrottle::WillRedirectRequest(
63 const GURL& new_url,
64 bool* defer) {
65 // If we have already shown the interstitial, do not show it again. The
66 // LOAD_BYPASS_PROXY flag makes it so that we do not resolve proxies. This
67 // override is used when downloading PAC files. If the request does not have
68 // the LOAD_BYPASS_PROXY flag, do not show the interstitial.
69 if (state_ != NOT_BYPASSED ||
70 !(request_->load_flags() & net::LOAD_BYPASS_PROXY)) {
71 return;
72 }
73
74 DisplayBlockingPage(defer);
75 }
76
77 void DataReductionProxyResourceThrottle::WillProcessResponse(bool* defer) {
78 if (state_ != NOT_BYPASSED)
79 return;
80
81 if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) ||
bengr 2014/12/29 18:45:41 I don't understand this. You proceed if the proxy
megjablon 2014/12/30 23:39:59 Acknowledged.
82 !request_->url().SchemeIs("http")) {
bengr 2014/12/29 18:45:41 The checks against the scheme are brittle, because
megjablon 2014/12/30 23:39:59 Done.
83 return;
84 }
85
86 DisplayBlockingPage(defer);
87 }
88
89 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) {
90 const content::ResourceRequestInfo* info =
91 content::ResourceRequestInfo::ForRequest(request_);
92 DCHECK(info);
93
94 state_ = REMOTE_BYPASS;
95 DataReductionProxyUIManager::BypassResource resource;
96 resource.url = request_->url();
97 resource.is_subresource = is_subresource_;
98 resource.callback = base::Bind(
99 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr());
100 resource.render_process_host_id = info->GetChildID();
101 resource.render_view_id = info->GetRouteID();
102
103 *defer = true;
104
105 content::BrowserThread::PostTask(
106 content::BrowserThread::UI, FROM_HERE,
107 base::Bind(
108 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage,
109 AsWeakPtr(), ui_service_->ui_manager(), resource));
110 }
111
112 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const {
113 return kResouceThrottleLogName;
114 }
115
116 // static
117 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage(
bengr 2014/12/29 18:45:41 Make sure the definition order matches the declara
megjablon 2014/12/30 23:39:59 Done.
118 const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle,
119 scoped_refptr<DataReductionProxyUIManager> ui_manager,
120 const DataReductionProxyUIManager::BypassResource& resource) {
121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
122 ui_manager->DisplayBlockingPage(resource);
123 }
124
125 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) {
126 state_ = NOT_BYPASSED;
127 if (proceed)
128 controller()->Resume();
129 else
130 controller()->Cancel();
131 }
132
133 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698