Commit b0002b84 authored by fdoray's avatar fdoray Committed by Commit bot

Observe network changes from network thread in DomainReliabilityMonitor.

From observer_list_threadsafe.h:
  // If the observer to be removed is in the list, RemoveObserver MUST
  // be called from the same thread which called AddObserver.

This rule is currently not respected by DomainReliabilityMonitor, which
prevents the addition of a DCHECK.

With this CL, the rule is respected and |last_network_change_time_|
is read/written from the same thread (no data race).

BUG=

Review-Url: https://codereview.chromium.org/2627523003
Cr-Commit-Position: refs/heads/master@{#443283}
parent 1fc7b35e
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
......@@ -90,7 +91,6 @@ DomainReliabilityMonitor::DomainReliabilityMonitor(
discard_uploads_set_(false),
weak_factory_(this) {
DCHECK(OnPrefThread());
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
DomainReliabilityMonitor::DomainReliabilityMonitor(
......@@ -110,22 +110,25 @@ DomainReliabilityMonitor::DomainReliabilityMonitor(
discard_uploads_set_(false),
weak_factory_(this) {
DCHECK(OnPrefThread());
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
}
DomainReliabilityMonitor::~DomainReliabilityMonitor() {
if (moved_to_network_thread_)
if (moved_to_network_thread_) {
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
DCHECK(OnNetworkThread());
else
} else {
DCHECK(OnPrefThread());
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
}
}
void DomainReliabilityMonitor::MoveToNetworkThread() {
DCHECK(OnPrefThread());
DCHECK(!moved_to_network_thread_);
network_task_runner_->PostTask(
FROM_HERE,
base::Bind(&net::NetworkChangeNotifier::AddNetworkChangeObserver,
base::Unretained(this)));
moved_to_network_thread_ = true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment