Use sequence instead of thread to get network id in NetworkQualityEstimator and DataReductionProxyConfig.

Sequences should be used instead of threads when possible
https://chromium.googlesource.com/chromium/src/+/lkcr/docs/threading_and_tasks.md#Prefer-Sequences-to-Threads

Furthermore, performing a blocking operation on a
SingleThreadTaskRunner assigned to a shared thread is dangerous because
it can prevent all other work assigned to that thread from running.

[email protected]

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I93995e80c9ae8f527747a2601fb56be967df77f5
Reviewed-on: https://chromium-review.googlesource.com/1065011
Reviewed-by: Helen Li <[email protected]>
Reviewed-by: Tarun Bansal <[email protected]>
Reviewed-by: David Roger <[email protected]>
Commit-Queue: François Doray <[email protected]>
Cr-Commit-Position: refs/heads/master@{#563413}
diff --git a/net/base/address_tracker_linux.cc b/net/base/address_tracker_linux.cc
index 2848b56..33b22781 100644
--- a/net/base/address_tracker_linux.cc
+++ b/net/base/address_tracker_linux.cc
@@ -14,6 +14,7 @@
 #include "base/logging.h"
 #include "base/message_loop/message_loop_current.h"
 #include "base/posix/eintr_wrapper.h"
+#include "base/threading/scoped_blocking_call.h"
 #include "base/threading/thread_restrictions.h"
 #include "net/base/network_interfaces_linux.h"
 
@@ -290,24 +291,28 @@
   *tunnel_changed = false;
   char buffer[4096];
   bool first_loop = true;
-  for (;;) {
-    int rv = HANDLE_EINTR(recv(netlink_fd_,
-                               buffer,
-                               sizeof(buffer),
-                               // Block the first time through loop.
-                               first_loop ? 0 : MSG_DONTWAIT));
-    first_loop = false;
-    if (rv == 0) {
-      LOG(ERROR) << "Unexpected shutdown of NETLINK socket.";
-      return;
+  {
+    // If the loop below takes a long time to run, a new thread should added to
+    // the current thread pool to ensure forward progress of all tasks.
+    base::ScopedBlockingCall blocking_call(base::BlockingType::MAY_BLOCK);
+
+    for (;;) {
+      int rv = HANDLE_EINTR(recv(netlink_fd_, buffer, sizeof(buffer),
+                                 // Block the first time through loop.
+                                 first_loop ? 0 : MSG_DONTWAIT));
+      first_loop = false;
+      if (rv == 0) {
+        LOG(ERROR) << "Unexpected shutdown of NETLINK socket.";
+        return;
+      }
+      if (rv < 0) {
+        if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
+          break;
+        PLOG(ERROR) << "Failed to recv from netlink socket";
+        return;
+      }
+      HandleMessage(buffer, rv, address_changed, link_changed, tunnel_changed);
     }
-    if (rv < 0) {
-      if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
-        break;
-      PLOG(ERROR) << "Failed to recv from netlink socket";
-      return;
-    }
-    HandleMessage(buffer, rv, address_changed, link_changed, tunnel_changed);
   }
   if (*link_changed || *address_changed)
     UpdateCurrentConnectionType();