Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #include "chrome/browser/chromeos/net/chrome_network_watcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/io_thread.h" | |
| 11 #include "chromeos/network/network_handler.h" | |
| 12 #include "chromeos/network/network_state.h" | |
| 13 #include "chromeos/network/network_state_handler.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 | |
| 16 namespace chromeos { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void SetIPAddresses(const std::string& ipv4_address, | |
| 21 const std::string& ipv6_address) { | |
| 22 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
| 23 g_browser_process->io_thread()->globals()->host_resolver->SetMyIpAddresses( | |
|
eroman
2014/05/02 01:48:18
This is not correct: g_browser_process is non-thre
| |
| 24 ipv4_address, ipv6_address); | |
| 25 } | |
| 26 | |
| 27 } | |
| 28 | |
| 29 ChromeNetworkWatcher::ChromeNetworkWatcher() { | |
| 30 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); | |
| 31 DefaultNetworkChanged( | |
| 32 NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); | |
| 33 } | |
| 34 | |
| 35 ChromeNetworkWatcher::~ChromeNetworkWatcher() { | |
| 36 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | |
| 37 FROM_HERE); | |
| 38 } | |
| 39 | |
| 40 void ChromeNetworkWatcher::DefaultNetworkChanged(const NetworkState* network) { | |
| 41 std::string ipv4_address = network ? network->ip_address() : ""; | |
| 42 if (ipv4_address == last_ipv4_address_) | |
| 43 return; | |
| 44 last_ipv4_address_ = ipv4_address; | |
| 45 std::string ipv6_address; // TODO(stevenjb): Fix this, crbug.com/365883 | |
| 46 content::BrowserThread::PostTask(content::BrowserThread::IO, | |
| 47 FROM_HERE, | |
| 48 base::Bind(&SetIPAddresses, | |
| 49 ipv4_address, ipv6_address)); | |
| 50 } | |
| 51 | |
| 52 } // namespace chromeos | |
| OLD | NEW |