// Copyright (c) 2009 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 "net/base/network_change_notifier_helper.h"
#include <algorithm>
#include "base/logging.h"

namespace net {

namespace internal {

NetworkChangeNotifierHelper::NetworkChangeNotifierHelper()
    : is_notifying_observers_(false) {}

NetworkChangeNotifierHelper::~NetworkChangeNotifierHelper() {
  DCHECK(observers_.empty());
}

void NetworkChangeNotifierHelper::AddObserver(Observer* observer) {
  DCHECK(!is_notifying_observers_);
  observers_.push_back(observer);
}

void NetworkChangeNotifierHelper::RemoveObserver(Observer* observer) {
  DCHECK(!is_notifying_observers_);
  observers_.erase(std::remove(observers_.begin(), observers_.end(), observer));
}

void NetworkChangeNotifierHelper::OnIPAddressChanged() {
  DCHECK(!is_notifying_observers_);
  is_notifying_observers_ = true;
  for (std::vector<Observer*>::iterator it = observers_.begin();
       it != observers_.end(); ++it) {
    (*it)->OnIPAddressChanged();
  }
  is_notifying_observers_ = false;
}

}  // namespace internal

}  // namespace net

// Copyright (c) 2009 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 "net/base/network_change_notifier_helper.h"
#include <algorithm>
#include "base/logging.h"

namespace net {

namespace internal {

NetworkChangeNotifierHelper::NetworkChangeNotifierHelper()
    : is_notifying_observers_(false) {}

NetworkChangeNotifierHelper::~NetworkChangeNotifierHelper() {
  // TODO(willchan): Re-enable this DCHECK after fixing http://crbug.com/34391
  // since we're leaking URLRequestContextGetters that cause this DCHECK to
  // fire.
  // DCHECK(observers_.empty());
}

void NetworkChangeNotifierHelper::AddObserver(Observer* observer) {
  DCHECK(!is_notifying_observers_);
  observers_.push_back(observer);
}

void NetworkChangeNotifierHelper::RemoveObserver(Observer* observer) {
  DCHECK(!is_notifying_observers_);
  observers_.erase(std::remove(observers_.begin(), observers_.end(), observer));
}

void NetworkChangeNotifierHelper::OnIPAddressChanged() {
  DCHECK(!is_notifying_observers_);
  is_notifying_observers_ = true;
  for (std::vector<Observer*>::iterator it = observers_.begin();
       it != observers_.end(); ++it) {
    (*it)->OnIPAddressChanged();
  }
  is_notifying_observers_ = false;
}

}  // namespace internal

}  // namespace net

Disable DCHECK'ing that all NetworkChangeNotifiers are removed. BUG=34391
Disable DCHECK'ing that all NetworkChangeNotifiers are removed.
BUG=34391

Review URL: http://codereview.chromium.org/560026

git-svn-id: dd90618784b6a4b323ea0c23a071cb1c9e6f2ac7@37982 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
