| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/network/host_resolver_impl_chromeos.h" | 5 #include "chromeos/network/host_resolver_impl_chromeos.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chromeos/network/device_state.h" | 13 #include "chromeos/network/device_state.h" |
| 14 #include "chromeos/network/network_handler.h" | 14 #include "chromeos/network/network_handler.h" |
| 15 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
| 16 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
| 17 #include "chromeos/network/network_state_handler_observer.h" | 17 #include "chromeos/network/network_state_handler_observer.h" |
| 18 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 | 24 |
| 25 // HostResolverImplChromeOS::NetworkStateHandlerObserver | 25 // HostResolverImplChromeOS::NetworkStateHandlerObserver |
| 26 // | 26 // |
| 27 // An instance of this class is created on the NetworkHandler (UI) thread and | 27 // An instance of this class is created on the NetworkHandler (UI) thread and |
| 28 // manages its own lifetime, destroying itself when NetworkStateHandlerObserver | 28 // manages its own lifetime, destroying itself when NetworkStateHandlerObserver |
| 29 // ::IsShuttingDown() gets called. | 29 // ::OnShuttingDown() gets called. |
| 30 | 30 |
| 31 class HostResolverImplChromeOS::NetworkObserver | 31 class HostResolverImplChromeOS::NetworkObserver |
| 32 : public chromeos::NetworkStateHandlerObserver { | 32 : public chromeos::NetworkStateHandlerObserver { |
| 33 public: | 33 public: |
| 34 static void Create( | 34 static void Create( |
| 35 const base::WeakPtr<HostResolverImplChromeOS>& resolver, | 35 const base::WeakPtr<HostResolverImplChromeOS>& resolver, |
| 36 scoped_refptr<base::SingleThreadTaskRunner> resolver_task_runner, | 36 scoped_refptr<base::SingleThreadTaskRunner> resolver_task_runner, |
| 37 NetworkStateHandler* network_state_handler) { | 37 NetworkStateHandler* network_state_handler) { |
| 38 new NetworkObserver(resolver, resolver_task_runner, network_state_handler); | 38 new NetworkObserver(resolver, resolver_task_runner, network_state_handler); |
| 39 } | 39 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } else { | 89 } else { |
| 90 LOG(ERROR) << "DefaultNetworkChanged: IPConfigs missing properties: " | 90 LOG(ERROR) << "DefaultNetworkChanged: IPConfigs missing properties: " |
| 91 << network->path(); | 91 << network->path(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 DVLOG(2) << "DefaultNetworkChanged: " << network->name() | 94 DVLOG(2) << "DefaultNetworkChanged: " << network->name() |
| 95 << " IPv4: " << ipv4_address << " IPv6: " << ipv6_address; | 95 << " IPv4: " << ipv4_address << " IPv6: " << ipv6_address; |
| 96 CallResolverSetIpAddress(ipv4_address, ipv6_address); | 96 CallResolverSetIpAddress(ipv4_address, ipv6_address); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void IsShuttingDown() override { delete this; } | 99 void OnShuttingDown() override { delete this; } |
| 100 | 100 |
| 101 void CallResolverSetIpAddress(const std::string& ipv4_address, | 101 void CallResolverSetIpAddress(const std::string& ipv4_address, |
| 102 const std::string& ipv6_address) { | 102 const std::string& ipv6_address) { |
| 103 resolver_task_runner_->PostTask( | 103 resolver_task_runner_->PostTask( |
| 104 FROM_HERE, base::Bind(&NetworkObserver::SetIpAddressOnResolverThread, | 104 FROM_HERE, base::Bind(&NetworkObserver::SetIpAddressOnResolverThread, |
| 105 weak_ptr_factory_resolver_thread_.GetWeakPtr(), | 105 weak_ptr_factory_resolver_thread_.GetWeakPtr(), |
| 106 ipv4_address, ipv6_address)); | 106 ipv4_address, ipv6_address)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void SetIpAddressOnResolverThread(const std::string& ipv4_address, | 109 void SetIpAddressOnResolverThread(const std::string& ipv4_address, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 scoped_ptr<net::HostResolver> | 201 scoped_ptr<net::HostResolver> |
| 202 HostResolverImplChromeOS::CreateHostResolverForTest( | 202 HostResolverImplChromeOS::CreateHostResolverForTest( |
| 203 scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner, | 203 scoped_refptr<base::SingleThreadTaskRunner> network_handler_task_runner, |
| 204 NetworkStateHandler* network_state_handler) { | 204 NetworkStateHandler* network_state_handler) { |
| 205 Options options; | 205 Options options; |
| 206 return scoped_ptr<net::HostResolver>(new HostResolverImplChromeOS( | 206 return scoped_ptr<net::HostResolver>(new HostResolverImplChromeOS( |
| 207 network_handler_task_runner, network_state_handler, options, NULL)); | 207 network_handler_task_runner, network_state_handler, options, NULL)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace chromeos | 210 } // namespace chromeos |
| OLD | NEW |