summaryrefslogtreecommitdiffstats
path: root/net/proxy/dhcp_proxy_script_fetcher_factory.h
blob: 147435d6f0bf6a3fb7578aa01daf7d514ff2c395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_PROXY_DHCP_SCRIPT_FETCHER_FACTORY_H_
#define NET_PROXY_DHCP_SCRIPT_FETCHER_FACTORY_H_

#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"

namespace net {

class DhcpProxyScriptFetcher;
class URLRequestContext;

// Factory object for creating the appropriate concrete base class of
// DhcpProxyScriptFetcher for your operating system and settings.
//
// You might think we could just implement a DHCP client at the protocol
// level and have cross-platform support for retrieving PAC configuration
// from DHCP, but unfortunately the DHCP protocol assumes there is a single
// client per machine (specifically per network interface card), and there
// is an implicit state machine between the client and server, so adding a
// second client to the machine would not be advisable (see e.g. some
// discussion of what can happen at this URL:
// http://www.net.princeton.edu/multi-dhcp-one-interface-handling.html).
//
// Therefore, we have platform-specific implementations, and so we use
// this factory to select the right one.
class NET_EXPORT DhcpProxyScriptFetcherFactory {
 public:
  // Creates a new factory object with default settings.
  DhcpProxyScriptFetcherFactory();

  // Ownership is transferred to the caller. url_request_context must be valid
  // and its lifetime must exceed that of the returned DhcpProxyScriptFetcher.
  //
  // Note that while a request is in progress, the fetcher may be holding a
  // reference to |url_request_context|. Be careful not to create cycles
  // between the fetcher and the context; you can break such cycles by calling
  // Cancel().
  DhcpProxyScriptFetcher* Create(URLRequestContext* url_request_context);

  // Attempts to enable/disable the DHCP WPAD feature.  Does nothing
  // if |IsSupported()| returns false.
  //
  // The default is |enabled() == true|.
  void set_enabled(bool enabled);

  // Returns true if the DHCP WPAD feature is enabled.  Always returns
  // false if |IsSupported()| is false.
  bool enabled() const;

  // Returns true if the DHCP WPAD feature is supported on the current
  // operating system.
  static bool IsSupported();

 private:
  bool feature_enabled_;

  DISALLOW_COPY_AND_ASSIGN(DhcpProxyScriptFetcherFactory);
};

}  // namespace net

#endif  // NET_PROXY_DHCP_SCRIPT_FETCHER_FACTORY_H_