diff options
Diffstat (limited to 'net/base/network_change_notifier.cc')
-rw-r--r-- | net/base/network_change_notifier.cc | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc index aeca2ab..a0bc6b5 100644 --- a/net/base/network_change_notifier.cc +++ b/net/base/network_change_notifier.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -14,9 +14,22 @@ namespace net { -// static -NetworkChangeNotifier* -NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() { +namespace { + +// The actual singleton notifier. The class contract forbids usage of the API +// in ways that would require us to place locks around access to this object. +// (The prohibition on global non-POD objects makes it tricky to do such a thing +// anyway.) +NetworkChangeNotifier* g_network_change_notifier = NULL; + +} // namespace + +NetworkChangeNotifier::~NetworkChangeNotifier() { + DCHECK_EQ(this, g_network_change_notifier); + g_network_change_notifier = NULL; +} + +NetworkChangeNotifier* NetworkChangeNotifier::Create() { #if defined(OS_WIN) return new NetworkChangeNotifierWin(); #elif defined(OS_LINUX) @@ -29,4 +42,27 @@ NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() { #endif } +void NetworkChangeNotifier::AddObserver(Observer* observer) { + if (g_network_change_notifier) + g_network_change_notifier->observer_list_->AddObserver(observer); +} + +void NetworkChangeNotifier::RemoveObserver(Observer* observer) { + if (g_network_change_notifier) + g_network_change_notifier->observer_list_->RemoveObserver(observer); +} + +NetworkChangeNotifier::NetworkChangeNotifier() + : observer_list_(new ObserverListThreadSafe<Observer>()) { + DCHECK(!g_network_change_notifier); + g_network_change_notifier = this; +} + +void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { + if (g_network_change_notifier) { + g_network_change_notifier->observer_list_->Notify( + &Observer::OnIPAddressChanged); + } +} + } // namespace net |