Chromium Code Reviews| Index: chrome/browser/chromeos/net/chrome_network_watcher.cc |
| diff --git a/chrome/browser/chromeos/net/chrome_network_watcher.cc b/chrome/browser/chromeos/net/chrome_network_watcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7b722eb734820d16f829f2e5ff6f6212cec1fed |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/net/chrome_network_watcher.cc |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2014 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. |
| + |
| +#include "chrome/browser/chromeos/net/chrome_network_watcher.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/io_thread.h" |
| +#include "chromeos/network/network_handler.h" |
| +#include "chromeos/network/network_state.h" |
| +#include "chromeos/network/network_state_handler.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +void SetIPAddresses(const std::string& ipv4_address, |
| + const std::string& ipv6_address) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + 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
|
| + ipv4_address, ipv6_address); |
| +} |
| + |
| +} |
| + |
| +ChromeNetworkWatcher::ChromeNetworkWatcher() { |
| + NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
| + DefaultNetworkChanged( |
| + NetworkHandler::Get()->network_state_handler()->DefaultNetwork()); |
| +} |
| + |
| +ChromeNetworkWatcher::~ChromeNetworkWatcher() { |
| + NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| + FROM_HERE); |
| +} |
| + |
| +void ChromeNetworkWatcher::DefaultNetworkChanged(const NetworkState* network) { |
| + std::string ipv4_address = network ? network->ip_address() : ""; |
| + if (ipv4_address == last_ipv4_address_) |
| + return; |
| + last_ipv4_address_ = ipv4_address; |
| + std::string ipv6_address; // TODO(stevenjb): Fix this, crbug.com/365883 |
| + content::BrowserThread::PostTask(content::BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&SetIPAddresses, |
| + ipv4_address, ipv6_address)); |
| +} |
| + |
| +} // namespace chromeos |