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/browser/data_reduction_proxy_configurator.h"
14#include "net/proxy/proxy_config.h"
15
16namespace base {
17class SequencedTaskRunner;
18}
19
20namespace net {
21class ProxyInfo;
22class ProxyService;
23}
24
25class PrefService;
26
27class DataReductionProxyChromeConfigurator
28    : public data_reduction_proxy::DataReductionProxyConfigurator {
29 public:
30  explicit DataReductionProxyChromeConfigurator(
31      PrefService* prefs,
32      scoped_refptr<base::SequencedTaskRunner> network_task_runner);
33  virtual ~DataReductionProxyChromeConfigurator();
34
35  virtual void Enable(bool primary_restricted,
36                      bool fallback_restricted,
37                      const std::string& primary_origin,
38                      const std::string& fallback_origin,
39                      const std::string& ssl_origin) OVERRIDE;
40  virtual void Disable() OVERRIDE;
41
42  // Add a host pattern to bypass. This should follow the same syntax used
43  // in net::ProxyBypassRules; that is, a hostname pattern, a hostname suffix
44  // pattern, an IP literal, a CIDR block, or the magic string '<local>'.
45  // Bypass settings persist for the life of this object and are applied
46  // each time the proxy is enabled, but are not updated while it is enabled.
47  virtual void AddHostPatternToBypass(const std::string& pattern) OVERRIDE;
48
49  // Add a URL pattern to bypass the proxy. The base implementation strips
50  // everything in |pattern| after the first single slash and then treats it
51  // as a hostname pattern. Subclasses may implement other semantics.
52  virtual void AddURLPatternToBypass(const std::string& pattern) OVERRIDE;
53
54  // Updates the config for use on the IO thread.
55  void UpdateProxyConfigOnIO(const net::ProxyConfig& config);
56
57  // Returns the current data reduction proxy config, even if it is not the
58  // effective configuration used by the proxy service.
59  const net::ProxyConfig& GetProxyConfigOnIO() const;
60
61 private:
62  FRIEND_TEST_ALL_PREFIXES(DataReductionProxyConfigTest, TestBypassList);
63
64  PrefService* prefs_;
65  scoped_refptr<base::SequencedTaskRunner> network_task_runner_;
66
67  std::vector<std::string> bypass_rules_;
68  net::ProxyConfig config_;
69
70  DISALLOW_COPY_AND_ASSIGN(DataReductionProxyChromeConfigurator);
71};
72
73#endif  // CHROME_BROWSER_NET_SPDYPROXY_DATA_REDUCTION_PROXY_CHROME_CONFIGURATOR_H_
74