| 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..b4f25e30cac7311c6369a454427c14e5eed90b75
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/net/chrome_network_watcher.cc
|
| @@ -0,0 +1,49 @@
|
| +// 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 SetIPAddress(const std::string& ip_address) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
| + g_browser_process->io_thread()->globals()->host_resolver->set_my_ip_address(
|
| + ip_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 ip_address = network ? network->ip_address() : "";
|
| + if (ip_address == last_ip_address_)
|
| + return;
|
| + last_ip_address_ = ip_address;
|
| + content::BrowserThread::PostTask(content::BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&SetIPAddress, ip_address));
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|