| 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 SetIPAddress(const std::string& ip_address) { |
| 21 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 22 g_browser_process->io_thread()->globals()->host_resolver->set_my_ip_address( |
| 23 ip_address); |
| 24 } |
| 25 |
| 26 } |
| 27 |
| 28 ChromeNetworkWatcher::ChromeNetworkWatcher() { |
| 29 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| 30 DefaultNetworkChanged( |
| 31 NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); |
| 32 } |
| 33 |
| 34 ChromeNetworkWatcher::~ChromeNetworkWatcher() { |
| 35 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 36 FROM_HERE); |
| 37 } |
| 38 |
| 39 void ChromeNetworkWatcher::DefaultNetworkChanged(const NetworkState* network) { |
| 40 std::string ip_address = network ? network->ip_address() : ""; |
| 41 if (ip_address == last_ip_address_) |
| 42 return; |
| 43 last_ip_address_ = ip_address; |
| 44 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 45 FROM_HERE, |
| 46 base::Bind(&SetIPAddress, ip_address)); |
| 47 } |
| 48 |
| 49 } // namespace chromeos |
| OLD | NEW |