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

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: Addressing comments Created 6 years 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 using content::BrowserThread;
17 using content::ResourceThrottle;
18
19 namespace data_reduction_proxy {
20
21 namespace {
22
23 const char* kResouceThrottleLogName = "DataReductionProxyResourceThrottle";
bengr 2014/12/17 00:30:19 const char kResouceThrottleLogName[] = "DataReduct
megjablon 2014/12/23 02:18:04 Done.
24
25 } // namespace
26
27 DataReductionProxyResourceThrottle::DataReductionProxyResourceThrottle(
28 net::URLRequest* request,
29 content::ResourceType resource_type,
30 DataReductionProxyUIService* ui_service,
31 const DataReductionProxyParams* params)
32 : state_(NOT_BYPASSED),
33 request_(request),
34 ui_service_(ui_service),
35 params_(params),
36 is_subresource_(resource_type != content::RESOURCE_TYPE_MAIN_FRAME) {
bengr 2014/12/17 00:30:19 DCHECK(request) DCHECK(params) and anything else
megjablon 2014/12/23 02:18:04 Done.
37 }
38
39 DataReductionProxyResourceThrottle::~DataReductionProxyResourceThrottle() { }
bengr 2014/12/17 00:30:20 Move closing brace to new line.
megjablon 2014/12/23 02:18:04 Done.
40
41 void DataReductionProxyResourceThrottle::WillStartUsingNetwork(bool* defer) {
42 DCHECK(state_ == NOT_BYPASSED);
43
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
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)
bengr 2014/12/17 00:30:20 Fix the space after "if" and the indent of "return
megjablon 2014/12/23 02:18:04 Done.
79 return;
80
81 if (params_->IsDataReductionProxy(request_->proxy_server(), NULL) ||
82 request_->url().SchemeIs("chrome") ||
83 request_->url().SchemeIs("about") ||
84 request_->url().SchemeIs("file")) {
bengr 2014/12/17 00:30:19 Where did this list of schemes come from? what abo
megjablon 2014/12/23 02:18:04 I wanted to skip any local requests. We can skip w
85 return;
86 }
87
88 DisplayBlockingPage(defer);
89 }
90
91 void DataReductionProxyResourceThrottle::DisplayBlockingPage(bool* defer) {
92 const content::ResourceRequestInfo* info =
93 content::ResourceRequestInfo::ForRequest(request_);
94 DCHECK(info);
95
96 state_ = REMOTE_BYPASS;
97 DataReductionProxyUIManager::BypassResource resource;
98 resource.url = request_->url();
99 resource.is_subresource = is_subresource_;
100 resource.callback = base::Bind(
101 &DataReductionProxyResourceThrottle::OnBlockingPageComplete, AsWeakPtr());
102 resource.render_process_host_id = info->GetChildID();
103 resource.render_view_id = info->GetRouteID();
104
105 *defer = true;
106
107 content::BrowserThread::PostTask(
108 content::BrowserThread::UI,
109 FROM_HERE,
bengr 2014/12/17 00:30:20 Move up with previous line.
megjablon 2014/12/23 02:18:04 Done.
110 base::Bind(
111 &DataReductionProxyResourceThrottle::StartDisplayingBlockingPage,
112 AsWeakPtr(),
113 ui_service_->ui_manager(),
114 resource));
bengr 2014/12/17 00:30:20 Move these up onto same like as "AsWeakPtr()"
megjablon 2014/12/23 02:18:04 Done.
115 }
116
117 const char* DataReductionProxyResourceThrottle::GetNameForLogging() const {
118 return kResouceThrottleLogName;
119 }
120
121 // static
122 void DataReductionProxyResourceThrottle::StartDisplayingBlockingPage(
123 const base::WeakPtr<DataReductionProxyResourceThrottle>& throttle,
124 scoped_refptr<DataReductionProxyUIManager> ui_manager,
125 const DataReductionProxyUIManager::BypassResource& resource) {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
127 ui_manager->DisplayBlockingPage(resource);
128 }
129
130 void DataReductionProxyResourceThrottle::OnBlockingPageComplete(bool proceed) {
131 state_ = NOT_BYPASSED;
132 if (proceed)
133 controller()->Resume();
134 else
135 controller()->Cancel();
136 }
137
138 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698