Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / components / data_reduction_proxy / core / browser / data_reduction_proxy_interceptor.h
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 #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_
7
8 #include "net/url_request/url_request_interceptor.h"
9
10 namespace data_reduction_proxy {
11 class DataReductionProxyParams;
12 class DataReductionProxyUsageStats;
13
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 {
19  public:
20   // Constructs the interceptor. |params| and |stats| must outlive |this|.
21   // |stats| may be NULL.
22   DataReductionProxyInterceptor(DataReductionProxyParams* params,
23                                 DataReductionProxyUsageStats* stats);
24
25   // Destroys the interceptor.
26   ~DataReductionProxyInterceptor() override;
27
28   // Overrides from net::URLRequestInterceptor:
29   net::URLRequestJob* MaybeInterceptRequest(
30       net::URLRequest* request,
31       net::NetworkDelegate* network_delegate) const override;
32
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
37   // the request.
38   net::URLRequestJob* MaybeInterceptResponse(
39       net::URLRequest* request,
40       net::NetworkDelegate* network_delegate) const override;
41
42  private:
43   // Must outlive |this|.
44   DataReductionProxyParams* params_;
45
46   // Must outlive |this| if non-NULL.
47   DataReductionProxyUsageStats* usage_stats_;
48
49   DISALLOW_COPY_AND_ASSIGN(DataReductionProxyInterceptor);
50 };
51
52 }  // namespace data_reduction_proxy
53 #endif  // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_INTERCEPTOR_H_