Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / network / host_resolver_impl_chromeos.h
blobdba4398f9ae272d056b3b44ae39582f0e6944a07
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 CHROMEOS_NETWORK_HOST_RESOLVER_IMPL_CHROMEOS_H_
6 #define CHROMEOS_NETWORK_HOST_RESOLVER_IMPL_CHROMEOS_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/threading/thread_checker.h"
10 #include "chromeos/chromeos_export.h"
11 #include "net/dns/host_resolver_impl.h"
13 namespace base {
14 class SingleThreadTaskRunner;
17 namespace chromeos {
18 class NetworkStateHandler;
21 namespace chromeos {
23 // HostResolverImplChromeOS overrides HostResolverImpl::Resolve in order to
24 // provide the correct IP addresses for localhost using the chromeos
25 // NetworkHandler interface. ('hostname' only returns 'localhost' on cros).
27 class CHROMEOS_EXPORT HostResolverImplChromeOS : public net::HostResolverImpl {
28 public:
29 // ChromeOS specific implementation of HostResolver::CreateSystemResolver.
30 // Assumes NetworkHandler has been initialized.
31 // This is expected to be constructed on the same thread that Resolve() is
32 // called from, i.e. the IO thread, which is presumed to differ from the
33 // thread that NetworkStateHandler is called on, i.e. the UI thread.
34 static scoped_ptr<net::HostResolver> CreateSystemResolver(
35 const Options& options,
36 net::NetLog* net_log);
38 // Creates a host resolver instance for testing.
39 static scoped_ptr<net::HostResolver> CreateHostResolverForTest(
40 scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner,
41 NetworkStateHandler* network_state_handler);
43 ~HostResolverImplChromeOS() override;
45 // HostResolverImpl
46 int Resolve(const RequestInfo& info,
47 net::RequestPriority priority,
48 net::AddressList* addresses,
49 const net::CompletionCallback& callback,
50 RequestHandle* out_req,
51 const net::BoundNetLog& source_net_log) override;
53 private:
54 friend class net::HostResolver;
55 class NetworkObserver;
57 HostResolverImplChromeOS(
58 scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner,
59 NetworkStateHandler* network_state_handler,
60 const Options& options,
61 net::NetLog* net_log);
63 void SetIPAddresses(const std::string& ipv4_address,
64 const std::string& ipv6_address);
66 bool ResolveLocalIPAddress(const RequestInfo& info,
67 net::AddressList* addresses);
69 std::string ipv4_address_;
70 std::string ipv6_address_;
71 base::ThreadChecker thread_checker_;
72 scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner_;
73 base::WeakPtrFactory<HostResolverImplChromeOS> weak_ptr_factory_;
75 DISALLOW_COPY_AND_ASSIGN(HostResolverImplChromeOS);
78 } // namespace chromeos
80 #endif // CHROMEOS_NETWORK_HOST_RESOLVER_IMPL_CHROMEOS_H_