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.
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_INTERCEPTOR_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_INTERCEPTOR_H_
8 #include "net/url_request/url_request_interceptor.h"
10 namespace data_reduction_proxy {
11 class DataReductionProxyParams;
12 class DataReductionProxyUsageStats;
14 // Used to intercept responses that contain explicit and implicit signals
15 // to bypass the data reduction proxy. If the proxy should be bypassed,
16 // the interceptor returns a new URLRequestHTTPJob that fetches the resource
17 // without use of the proxy.
18 class DataReductionProxyInterceptor : public net::URLRequestInterceptor {
20 // Constructs the interceptor. |params| and |stats| must outlive |this|.
21 // |stats| may be NULL.
22 DataReductionProxyInterceptor(DataReductionProxyParams* params,
23 DataReductionProxyUsageStats* stats);
25 // Destroys the interceptor.
26 ~DataReductionProxyInterceptor() override;
28 // Overrides from net::URLRequestInterceptor:
29 net::URLRequestJob* MaybeInterceptRequest(
30 net::URLRequest* request,
31 net::NetworkDelegate* network_delegate) const override;
33 // Returns a new URLRequestHTTPJob if the response indicates that the data
34 // reduction proxy should be bypassed according to the rules in
35 // data_reduction_proxy_protocol.cc. Returns NULL otherwise. If a job is
36 // returned, the interceptor's URLRequestInterceptingJobFactory will restart
38 net::URLRequestJob* MaybeInterceptResponse(
39 net::URLRequest* request,
40 net::NetworkDelegate* network_delegate) const override;
43 // Must outlive |this|.
44 DataReductionProxyParams* params_;
46 // Must outlive |this| if non-NULL.
47 DataReductionProxyUsageStats* usage_stats_;
49 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyInterceptor);
52 } // namespace data_reduction_proxy
53 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_INTERCEPTOR_H_