update_engine: Use org.chromium.NetworkProxyService.

Make update_engine call Chrome's new
org.chromium.NetworkProxyService D-Bus service to resolve
network proxies instead of using
org.chromium.LibCrosService. The new service supports
asynchronous replies instead of responding via D-Bus
signals.

BUG=chromium:446115,chromium:703217
TEST=unit tests pass; also added debug logging and verified
     that chrome's proxy settings are used

(cherry picked from commit 941cf235c5e56eddc6e4f2de2f38bee032a4dead)
Cherry-pick updated to resolve conflicts with existing code in AOSP.

Change-Id: I8c0704482e9988fe9ed14d32797b3a5b8da3d46a
Reviewed-on: https://chromium-review.googlesource.com/497491
Commit-Ready: Dan Erat <derat@chromium.org>
Tested-by: Dan Erat <derat@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
diff --git a/real_system_state.cc b/real_system_state.cc
index aab074f..5cbf723 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -24,12 +24,18 @@
 #include <base/time/time.h>
 #include <brillo/make_unique_ptr.h>
 #include <brillo/message_loops/message_loop.h>
+#if USE_LIBCROS
+#include <chromeos/dbus/service_constants.h>
+#endif  // USE_LIBCROS
 
 #include "update_engine/common/boot_control.h"
 #include "update_engine/common/boot_control_stub.h"
 #include "update_engine/common/constants.h"
 #include "update_engine/common/hardware.h"
 #include "update_engine/common/utils.h"
+#if USE_DBUS
+#include "update_engine/dbus_connection.h"
+#endif  // USE_DBUS
 #include "update_engine/update_manager/state_factory.h"
 
 using brillo::MessageLoop;
@@ -59,6 +65,15 @@
     return false;
   }
 
+#if USE_LIBCROS
+  libcros_proxy_.reset(new org::chromium::LibCrosServiceInterfaceProxy(
+      DBusConnection::Get()->GetDBus(), chromeos::kLibCrosServiceName));
+  network_proxy_service_proxy_.reset(
+      new org::chromium::NetworkProxyServiceInterfaceProxy(
+          DBusConnection::Get()->GetDBus(),
+          chromeos::kNetworkProxyServiceName));
+#endif  // USE_LIBCROS
+
   LOG_IF(INFO, !hardware_->IsNormalBootMode()) << "Booted in dev mode.";
   LOG_IF(INFO, !hardware_->IsOfficialBuild()) << "Booted non-official build.";
 
@@ -129,14 +144,20 @@
   certificate_checker_->Init();
 
 #if USE_LIBCROS
-  LibCrosProxy* libcros_proxy = &libcros_proxy_;
+  org::chromium::NetworkProxyServiceInterfaceProxyInterface* net_proxy =
+      network_proxy_service_proxy_.get();
+  org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy =
+      libcros_proxy_.get();
 #else
-  LibCrosProxy* libcros_proxy = nullptr;
+  org::chromium::NetworkProxyServiceInterfaceProxyInterface* net_proxy =
+      nullptr;
+  org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy =
+      nullptr;
 #endif  // USE_LIBCROS
 
   // Initialize the UpdateAttempter before the UpdateManager.
-  update_attempter_.reset(
-      new UpdateAttempter(this, certificate_checker_.get(), libcros_proxy));
+  update_attempter_.reset(new UpdateAttempter(this, certificate_checker_.get(),
+                                              net_proxy));
   update_attempter_->Init();
 
   // Initialize the Update Manager using the default state factory.