Disable ChromeBrowserProxyResolver behind a flag.

In Brillo and Android targets, there isn't a Chrome instance running
to resolve the proxies for a given URL. While this is not a fatal error
it logs abundant error messages on each request, confusing developers.

This patch compiles the ChromeBrowserProxyResolver only when the
USE_LIBCROS flag is set. This is now disabled by default in Brillo and
Android, but enabled in Chrome OS.

Bug: 24277309
TEST=`mma` on edison-eng. Applied an update, no more proxy error logs.

Change-Id: I27779572bf2fc810cb7846d63e123643d0386b0a
diff --git a/Android.mk b/Android.mk
index c3cf8c8..9dbab17 100644
--- a/Android.mk
+++ b/Android.mk
@@ -23,6 +23,9 @@
 local_use_dbus := $(if $(BRILLO_USE_DBUS),$(BRILLO_USE_DBUS),0)
 local_use_hwid_override := \
     $(if $(BRILLO_USE_HWID_OVERRIDE),$(BRILLO_USE_HWID_OVERRIDE),0)
+# "libcros" gates the LibCrosService exposed by the Chrome OS' chrome browser to
+# the system layer.
+local_use_libcros := $(if $(BRILLO_USE_LIBCROS),$(BRILLO_USE_LIBCROS),0)
 local_use_mtd := $(if $(BRILLO_USE_MTD),$(BRILLO_USE_MTD),0)
 local_use_power_management := \
     $(if $(BRILLO_USE_POWER_MANAGEMENT),$(BRILLO_USE_POWER_MANAGEMENT),0)
@@ -32,6 +35,7 @@
     -DUSE_BINDER=$(local_use_binder) \
     -DUSE_DBUS=$(local_use_dbus) \
     -DUSE_HWID_OVERRIDE=$(local_use_hwid_override) \
+    -DUSE_LIBCROS=$(local_use_libcros) \
     -DUSE_MTD=$(local_use_mtd) \
     -DUSE_POWER_MANAGEMENT=$(local_use_power_management) \
     -DUSE_WEAVE=$(local_use_weave) \
@@ -299,7 +303,6 @@
     $(ue_update_metadata_protos_exported_shared_libraries)
 LOCAL_SRC_FILES := \
     boot_control_android.cc \
-    chrome_browser_proxy_resolver.cc \
     common_service.cc \
     connection_manager.cc \
     daemon.cc \
@@ -346,6 +349,10 @@
 LOCAL_SRC_FILES += \
     weave_service.cc
 endif  # local_use_weave == 1
+ifeq ($(local_use_libcros),1)
+LOCAL_SRC_FILES += \
+    chrome_browser_proxy_resolver.cc
+endif  # local_use_libcros == 1
 include $(BUILD_STATIC_LIBRARY)
 
 else  # !defined(BRILLO)
diff --git a/update_attempter.cc b/update_attempter.cc
index aeb433b..b67fcb3 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -125,7 +125,9 @@
     : processor_(new ActionProcessor()),
       system_state_(system_state),
       cert_checker_(cert_checker),
+#if USE_LIBCROS
       chrome_proxy_resolver_(libcros_proxy),
+#endif  // USE_LIBCROS
       debugd_proxy_(debugd_proxy) {
 }
 
@@ -155,7 +157,9 @@
   else
     status_ = UpdateStatus::IDLE;
 
+#if USE_LIBCROS
   chrome_proxy_resolver_.Init();
+#endif  // USE_LIBCROS
 }
 
 void UpdateAttempter::ScheduleUpdates() {
diff --git a/update_attempter.h b/update_attempter.h
index 8f6fd18..bbc4b4e 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -306,9 +306,13 @@
   void MarkDeltaUpdateFailure();
 
   ProxyResolver* GetProxyResolver() {
+#if USE_LIBCROS
     return obeying_proxies_ ?
         reinterpret_cast<ProxyResolver*>(&chrome_proxy_resolver_) :
         reinterpret_cast<ProxyResolver*>(&direct_proxy_resolver_);
+#else
+    return &direct_proxy_resolver_;
+#endif  // USE_LIBCROS
   }
 
   // Sends a ping to Omaha.
@@ -454,7 +458,9 @@
 
   // Our two proxy resolvers
   DirectProxyResolver direct_proxy_resolver_;
+#if USE_LIBCROS
   ChromeBrowserProxyResolver chrome_proxy_resolver_;
+#endif  // USE_LIBCROS
 
   // Originally, both of these flags are false. Once UpdateBootFlags is called,
   // |update_boot_flags_running_| is set to true. As soon as UpdateBootFlags
diff --git a/update_engine.gyp b/update_engine.gyp
index b7aaa9d..c6250af 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -26,6 +26,7 @@
       'USE_binder%': '0',
       'USE_dbus%': '1',
       'USE_hwid_override%': '0',
+      'USE_libcros%': '1',
       'USE_mtd%': '0',
       'USE_power_management%': '0',
       'USE_buffet%': '0',
@@ -52,6 +53,7 @@
       'USE_BINDER=<(USE_binder)',
       'USE_DBUS=<(USE_dbus)',
       'USE_HWID_OVERRIDE=<(USE_hwid_override)',
+      'USE_LIBCROS=<(USE_libcros)',
       'USE_MTD=<(USE_mtd)',
       'USE_POWER_MANAGEMENT=<(USE_power_management)',
       'USE_WEAVE=<(USE_buffet)',
@@ -246,7 +248,6 @@
       },
       'sources': [
         'boot_control_chromeos.cc',
-        'chrome_browser_proxy_resolver.cc',
         'common_service.cc',
         'connection_manager.cc',
         'daemon.cc',
@@ -293,6 +294,14 @@
             ],
           },
         }],
+        ['USE_libcros == 1', {
+          'dependencies': [
+            'update_engine-other-dbus-proxies',
+          ],
+          'sources': [
+            'chrome_browser_proxy_resolver.cc',
+          ],
+        }],
       ],
     },
     # update_engine daemon.
@@ -468,7 +477,6 @@
           'includes': ['../../../platform2/common-mk/common_test.gypi'],
           'sources': [
             'boot_control_chromeos_unittest.cc',
-            'chrome_browser_proxy_resolver_unittest.cc',
             'common/action_pipe_unittest.cc',
             'common/action_processor_unittest.cc',
             'common/action_unittest.cc',
@@ -540,6 +548,13 @@
             # Main entry point for runnning tests.
             'testrunner.cc',
           ],
+          'conditions': [
+            ['USE_libcros == 1', {
+              'sources': [
+                'chrome_browser_proxy_resolver_unittest.cc',
+              ],
+            }],
+          ],
         },
       ],
     }],