Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / net / spdyproxy / data_reduction_proxy_chrome_configurator.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 CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_CONFIGURATOR_H_
6 #define CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_CONFIGURATOR_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/task_runner.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator.h"
14 #include "net/proxy/proxy_config.h"
15
16 namespace base {
17 class SequencedTaskRunner;
18 }
19
20 namespace net {
21 class ProxyInfo;
22 class ProxyService;
23 }
24
25 class PrefService;
26
27 class DataReductionProxyChromeConfigurator
28     : public data_reduction_proxy::DataReductionProxyConfigurator {
29  public:
30   explicit DataReductionProxyChromeConfigurator(
31       PrefService* prefs,
32       scoped_refptr<base::SequencedTaskRunner> network_task_runner);
33   ~DataReductionProxyChromeConfigurator() override;
34
35   // Removes the data reduction proxy configuration from the proxy preference.
36   // This disables use of the data reduction proxy. This method is public to
37   // disable the proxy on incognito. Disable() should be used otherwise.
38   static void DisableInProxyConfigPref(PrefService* prefs);
39
40   void Enable(bool primary_restricted,
41               bool fallback_restricted,
42               const std::string& primary_origin,
43               const std::string& fallback_origin,
44               const std::string& ssl_origin) override;
45   void Disable() override;
46
47   // Add a host pattern to bypass. This should follow the same syntax used
48   // in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix
49   // pattern, an IP literal, a CIDR block, or the magic string '<local>'.
50   // Bypass settings persist for the life of this object and are applied
51   // each time the proxy is enabled, but are not updated while it is enabled.
52   void AddHostPatternToBypass(const std::string& pattern) override;
53
54   // Add a URL pattern to bypass the proxy. The base implementation strips
55   // everything in |pattern| after the first single slash and then treats it
56   // as a hostname pattern. Subclasses may implement other semantics.
57   void AddURLPatternToBypass(const std::string& pattern) override;
58
59   // Updates the config for use on the IO thread.
60   void UpdateProxyConfigOnIO(const net::ProxyConfig& config);
61
62   // Returns the current data reduction proxy config, even if it is not the
63   // effective configuration used by the proxy service.
64   const net::ProxyConfig& GetProxyConfigOnIO() const;
65
66  private:
67   FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, TestBypassList);
68
69   // Check whether the |proxy_rules| contain any of the data reduction proxies.
70   static bool ContainsDataReductionProxy(
71       const net::ProxyConfig::ProxyRules& proxy_rules);
72
73   PrefService* prefs_;
74   scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
75
76   std::vector<std::string> bypass_rules_;
77   net::ProxyConfig config_;
78
79   DISALLOW_COPY_AND_ASSIGN(DataReductionProxyChromeConfigurator);
80 };
81
82 #endif  // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_CONFIGURATOR_H_