update_engine: Breaks the use of libcros into two dbus proxies.

This CL breaks USE_LIBCROS into two defines:
	USE_CHROME_NETWORK_PROXY
	USE_CHROME_KIOSK_APP
and changes all related build artifacts for both chrome and android.

Breaks USE_libcros into USE_chrome_network_proxy and USE_chrome_kiosk_app.
Removes BRILL_USE_LIBCROS.
Replaces __BRILLO__ with USE_OMAHA.

BUG=chromium:717306
TEST=Ran test 'cros_workon_make --board=amd64-generic --test update_engine'
	for all four conditions of the newly introduced two flags.

Change-Id: I9ca5b35c22a17c45a861db6a434239096a896127
Reviewed-on: https://chromium-review.googlesource.com/596802
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Tested-by: Sen Jiang <senj@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/Android.mk b/Android.mk
index 41f92d2..d3018fa 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,18 +22,18 @@
 local_use_binder := $(if $(BRILLO_USE_BINDER),$(BRILLO_USE_BINDER),1)
 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_chrome_network_proxy := 0
+local_use_chrome_kiosk_app := 0
 
 # IoT devices use Omaha for updates.
 local_use_omaha := $(if $(filter true,$(PRODUCT_IOT)),1,0)
 
 ue_common_cflags := \
     -DUSE_BINDER=$(local_use_binder) \
+    -DUSE_CHROME_NETWORK_PROXY=$(local_use_chrome_network_proxy) \
+    -DUSE_CHROME_KIOSK_APP=$(local_use_chrome_kiosk_app) \
     -DUSE_HWID_OVERRIDE=$(local_use_hwid_override) \
-    -DUSE_LIBCROS=$(local_use_libcros) \
     -DUSE_MTD=$(local_use_mtd) \
     -DUSE_OMAHA=$(local_use_omaha) \
     -D_FILE_OFFSET_BITS=64 \
@@ -322,10 +322,10 @@
     binder_service_brillo.cc \
     parcelable_update_engine_status.cc
 endif  # local_use_binder == 1
-ifeq ($(local_use_libcros),1)
+ifeq ($(local_use_chrome_network_proxy),1)
 LOCAL_SRC_FILES += \
     chrome_browser_proxy_resolver.cc
-endif  # local_use_libcros == 1
+endif  # local_use_chrome_network_proxy == 1
 include $(BUILD_STATIC_LIBRARY)
 
 else  # local_use_omaha == 1
@@ -990,10 +990,10 @@
 LOCAL_SHARED_LIBRARIES += \
     $(ue_libupdate_engine_android_exported_shared_libraries:-host=)
 endif  # local_use_omaha == 1
-ifeq ($(local_use_libcros),1)
+ifeq ($(local_use_chrome_network_proxy),1)
 LOCAL_SRC_FILES += \
     chrome_browser_proxy_resolver_unittest.cc
-endif  # local_use_libcros == 1
+endif  # local_use_chrome_network_proxy == 1
 include $(BUILD_NATIVE_TEST)
 
 # Update payload signing public key.
diff --git a/libcurl_http_fetcher.cc b/libcurl_http_fetcher.cc
index eac6ea0..87f30ad 100644
--- a/libcurl_http_fetcher.cc
+++ b/libcurl_http_fetcher.cc
@@ -272,7 +272,7 @@
     } else if (base::StartsWith(
                    url_, "https://", base::CompareCase::INSENSITIVE_ASCII)) {
       SetCurlOptionsForHttps();
-#if !defined(__CHROMEOS__) && !defined(__BRILLO__)
+#if !USE_OMAHA
     } else if (base::StartsWith(
                    url_, "file://", base::CompareCase::INSENSITIVE_ASCII)) {
       SetCurlOptionsForFile();
diff --git a/real_system_state.cc b/real_system_state.cc
index 5cbf723..b3ec06d 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -24,9 +24,9 @@
 #include <base/time/time.h>
 #include <brillo/make_unique_ptr.h>
 #include <brillo/message_loops/message_loop.h>
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP || USE_CHROME_NETWORK_PROXY
 #include <chromeos/dbus/service_constants.h>
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_KIOSK_APP || USE_CHROME_NETWORK_PROXY
 
 #include "update_engine/common/boot_control.h"
 #include "update_engine/common/boot_control_stub.h"
@@ -65,14 +65,16 @@
     return false;
   }
 
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
   libcros_proxy_.reset(new org::chromium::LibCrosServiceInterfaceProxy(
       DBusConnection::Get()->GetDBus(), chromeos::kLibCrosServiceName));
+#endif  // USE_CHROME_KIOSK_APP
+#if USE_CHROME_NETWORK_PROXY
   network_proxy_service_proxy_.reset(
       new org::chromium::NetworkProxyServiceInterfaceProxy(
           DBusConnection::Get()->GetDBus(),
           chromeos::kNetworkProxyServiceName));
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 
   LOG_IF(INFO, !hardware_->IsNormalBootMode()) << "Booted in dev mode.";
   LOG_IF(INFO, !hardware_->IsOfficialBuild()) << "Booted non-official build.";
@@ -143,27 +145,28 @@
       new CertificateChecker(prefs_.get(), &openssl_wrapper_));
   certificate_checker_->Init();
 
-#if USE_LIBCROS
-  org::chromium::NetworkProxyServiceInterfaceProxyInterface* net_proxy =
-      network_proxy_service_proxy_.get();
-  org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy =
-      libcros_proxy_.get();
+  update_attempter_.reset(
+      new UpdateAttempter(this,
+                          certificate_checker_.get(),
+#if USE_CHROME_NETWORK_PROXY
+                          network_proxy_service_proxy_.get()));
 #else
-  org::chromium::NetworkProxyServiceInterfaceProxyInterface* net_proxy =
-      nullptr;
-  org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy =
-      nullptr;
-#endif  // USE_LIBCROS
+                          nullptr)));
+#endif  // USE_CHROME_NETWORK_PROXY
 
   // Initialize the UpdateAttempter before the UpdateManager.
-  update_attempter_.reset(new UpdateAttempter(this, certificate_checker_.get(),
-                                              net_proxy));
   update_attempter_->Init();
 
   // Initialize the Update Manager using the default state factory.
   chromeos_update_manager::State* um_state =
-      chromeos_update_manager::DefaultStateFactory(
-          &policy_provider_, libcros_proxy, this);
+      chromeos_update_manager::DefaultStateFactory(&policy_provider_,
+#if USE_CHROME_KIOSK_APP
+                                                   libcros_proxy_.get(),
+#else
+                                                   nullptr,
+#endif  // USE_CHROME_KIOSK_APP
+                                                   this);
+
   if (!um_state) {
     LOG(ERROR) << "Failed to initialize the Update Manager.";
     return false;
diff --git a/real_system_state.h b/real_system_state.h
index 64964cd..6aee0af 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -25,10 +25,12 @@
 #include <metrics/metrics_library.h>
 #include <policy/device_policy.h>
 
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
 #include <libcros/dbus-proxies.h>
+#endif  // USE_CHROME_KIOSK_APP
+#if USE_CHROME_NETWORK_PROXY
 #include <network_proxy/dbus-proxies.h>
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 
 #include "update_engine/certificate_checker.h"
 #include "update_engine/common/boot_control_interface.h"
@@ -127,12 +129,14 @@
   inline bool system_rebooted() override { return system_rebooted_; }
 
  private:
-#if USE_LIBCROS
   // Real DBus proxies using the DBus connection.
+#if USE_CHROME_KIOSK_APP
   std::unique_ptr<org::chromium::LibCrosServiceInterfaceProxy> libcros_proxy_;
+#endif  // USE_CHROME_KIOSK_APP
+#if USE_CHROME_NETWORK_PROXY
   std::unique_ptr<org::chromium::NetworkProxyServiceInterfaceProxy>
       network_proxy_service_proxy_;
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 
   // Interface for the power manager.
   std::unique_ptr<PowerManagerInterface> power_manager_;
diff --git a/update_attempter.cc b/update_attempter.cc
index ff3b046..9cf9368 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -126,12 +126,12 @@
         network_proxy_service_proxy)
     : processor_(new ActionProcessor()),
       system_state_(system_state),
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
       cert_checker_(cert_checker),
       chrome_proxy_resolver_(network_proxy_service_proxy) {
 #else
       cert_checker_(cert_checker) {
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 }
 
 UpdateAttempter::~UpdateAttempter() {
diff --git a/update_attempter.h b/update_attempter.h
index 7780357..b4e2f60 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -29,9 +29,9 @@
 #include <base/time/time.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
 #include "update_engine/chrome_browser_proxy_resolver.h"
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 #include "update_engine/certificate_checker.h"
 #include "update_engine/client_library/include/update_engine/update_status.h"
 #include "update_engine/common/action_processor.h"
@@ -304,13 +304,13 @@
   void MarkDeltaUpdateFailure();
 
   ProxyResolver* GetProxyResolver() {
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
     return obeying_proxies_ ?
         reinterpret_cast<ProxyResolver*>(&chrome_proxy_resolver_) :
         reinterpret_cast<ProxyResolver*>(&direct_proxy_resolver_);
 #else
     return &direct_proxy_resolver_;
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
   }
 
   // Sends a ping to Omaha.
@@ -452,9 +452,9 @@
 
   // Our two proxy resolvers
   DirectProxyResolver direct_proxy_resolver_;
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
   ChromeBrowserProxyResolver chrome_proxy_resolver_;
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 
   // 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_attempter_unittest.cc b/update_attempter_unittest.cc
index 4928477..4ebc85c 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -31,10 +31,10 @@
 #include <policy/libpolicy.h>
 #include <policy/mock_device_policy.h>
 
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
 #include "network_proxy/dbus-proxies.h"
 #include "network_proxy/dbus-proxy-mocks.h"
-#endif // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
 #include "update_engine/common/fake_clock.h"
 #include "update_engine/common/fake_prefs.h"
 #include "update_engine/common/mock_action.h"
@@ -187,13 +187,13 @@
   brillo::BaseMessageLoop loop_{&base_loop_};
 
   FakeSystemState fake_system_state_;
-#if USE_LIBCROS
+#if USE_CHROME_NETWORK_PROXY
   NetworkProxyServiceInterfaceProxyMock network_proxy_service_proxy_mock_;
   UpdateAttempterUnderTest attempter_{&fake_system_state_,
                                       &network_proxy_service_proxy_mock_};
 #else
   UpdateAttempterUnderTest attempter_{&fake_system_state_, nullptr};
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_NETWORK_PROXY
   OpenSSLWrapper openssl_wrapper_;
   CertificateChecker certificate_checker_;
 
diff --git a/update_engine.gyp b/update_engine.gyp
index 6b7e5f4..152bcaa 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -14,6 +14,10 @@
 # limitations under the License.
 #
 {
+  'variables': {
+    'USE_chrome_network_proxy': '1',
+    'USE_chrome_kiosk_app': '1',
+  },
   'target_defaults': {
     'variables': {
       'deps': [
@@ -47,7 +51,8 @@
       'USE_BINDER=<(USE_binder)',
       'USE_DBUS=<(USE_dbus)',
       'USE_HWID_OVERRIDE=<(USE_hwid_override)',
-      'USE_LIBCROS=<(USE_libcros)',
+      'USE_CHROME_KIOSK_APP=<(USE_chrome_kiosk_app)',
+      'USE_CHROME_NETWORK_PROXY=<(USE_chrome_network_proxy)',
       'USE_MTD=<(USE_mtd)',
       'USE_OMAHA=1',
       'USE_SHILL=1',
@@ -98,32 +103,34 @@
       'includes': ['../../../platform2/common-mk/generate-dbus-adaptors.gypi'],
     },
     {
-      'target_name': 'update_engine-other-dbus-proxies',
+      'target_name': 'update_engine-dbus-libcros-client',
       'type': 'none',
-      'actions': [
-        {
-          'action_name': 'update_engine-dbus-libcros-client',
-          'variables': {
-            'mock_output_file': 'include/libcros/dbus-proxy-mocks.h',
-            'proxy_output_file': 'include/libcros/dbus-proxies.h'
-          },
-          'sources': [
-            'dbus_bindings/org.chromium.LibCrosService.dbus-xml',
-          ],
-          'includes': ['../../../platform2/common-mk/generate-dbus-proxies.gypi'],
+      'actions': [{
+        'action_name': 'update_engine-dbus-libcros-client-action',
+        'variables': {
+          'mock_output_file': 'include/libcros/dbus-proxy-mocks.h',
+          'proxy_output_file': 'include/libcros/dbus-proxies.h'
         },
-        {
-          'action_name': 'update_engine-dbus-network_proxy-client',
-          'variables': {
-            'mock_output_file': 'include/network_proxy/dbus-proxy-mocks.h',
-            'proxy_output_file': 'include/network_proxy/dbus-proxies.h'
-          },
-          'sources': [
-            'dbus_bindings/org.chromium.NetworkProxyService.dbus-xml',
-          ],
-          'includes': ['../../../platform2/common-mk/generate-dbus-proxies.gypi'],
+        'sources': [
+          'dbus_bindings/org.chromium.LibCrosService.dbus-xml',
+        ],
+        'includes': ['../../../platform2/common-mk/generate-dbus-proxies.gypi'],
+      }],
+    },
+    {
+      'target_name': 'update_engine-dbus-chrome_network_proxy-client',
+      'type': 'none',
+      'actions': [{
+        'action_name': 'update_engine-dbus-chrome_network_proxy-client-action',
+        'variables': {
+          'mock_output_file': 'include/network_proxy/dbus-proxy-mocks.h',
+          'proxy_output_file': 'include/network_proxy/dbus-proxies.h'
         },
-      ],
+        'sources': [
+          'dbus_bindings/org.chromium.NetworkProxyService.dbus-xml',
+        ],
+        'includes': ['../../../platform2/common-mk/generate-dbus-proxies.gypi'],
+      }],
     },
     # The payload application component and common dependencies.
     {
@@ -212,7 +219,6 @@
         'libpayload_consumer',
         'update_metadata-protos',
         'update_engine-dbus-adaptor',
-        'update_engine-other-dbus-proxies',
       ],
       'variables': {
         'exported_deps': [
@@ -292,14 +298,19 @@
         'update_status_utils.cc',
       ],
       'conditions': [
-        ['USE_libcros == 1', {
+        ['USE_chrome_network_proxy == 1', {
           'dependencies': [
-            'update_engine-other-dbus-proxies',
+            'update_engine-dbus-chrome_network_proxy-client',
           ],
           'sources': [
             'chrome_browser_proxy_resolver.cc',
           ],
         }],
+        ['USE_chrome_kiosk_app == 1', {
+          'dependencies': [
+            'update_engine-dbus-libcros-client',
+          ],
+        }],
       ],
     },
     # update_engine daemon.
@@ -563,11 +574,19 @@
             'testrunner.cc',
           ],
           'conditions': [
-            ['USE_libcros == 1', {
+            ['USE_chrome_network_proxy == 1', {
+              'dependencies': [
+                'update_engine-dbus-chrome_network_proxy-client',
+              ],
               'sources': [
                 'chrome_browser_proxy_resolver_unittest.cc',
               ],
             }],
+            ['USE_chrome_kiosk_app == 1', {
+              'dependencies': [
+                'update_engine-dbus-libcros-client',
+              ],
+            }],
           ],
         },
       ],
diff --git a/update_manager/real_system_provider.cc b/update_manager/real_system_provider.cc
index 9b968ca..fdf7e86 100644
--- a/update_manager/real_system_provider.cc
+++ b/update_manager/real_system_provider.cc
@@ -20,9 +20,9 @@
 #include <base/callback.h>
 #include <base/logging.h>
 #include <base/time/time.h>
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
 #include <libcros/dbus-proxies.h>
-#endif
+#endif  // USE_CHROME_KIOSK_APP
 
 #include "update_engine/common/utils.h"
 #include "update_engine/update_manager/generic_variables.h"
@@ -124,7 +124,7 @@
 
 bool RealSystemProvider::GetKioskAppRequiredPlatformVersion(
     string* required_platform_version) {
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
   brillo::ErrorPtr error;
   if (!libcros_proxy_->GetKioskAppRequiredPlatformVersion(
           required_platform_version, &error)) {
@@ -132,7 +132,7 @@
     required_platform_version->clear();
     return false;
   }
-#endif
+#endif  // USE_CHROME_KIOSK_APP
 
   return true;
 }
diff --git a/update_manager/real_system_provider.h b/update_manager/real_system_provider.h
index a62e1ae..80a8615 100644
--- a/update_manager/real_system_provider.h
+++ b/update_manager/real_system_provider.h
@@ -40,8 +40,12 @@
       chromeos_update_engine::BootControlInterface* boot_control,
       org::chromium::LibCrosServiceInterfaceProxyInterface* libcros_proxy)
       : hardware_(hardware),
+#if USE_CHROME_KIOSK_APP
         boot_control_(boot_control),
         libcros_proxy_(libcros_proxy) {}
+#else
+        boot_control_(boot_control) {}
+#endif  // USE_CHROME_KIOSK_APP
 
   // Initializes the provider and returns whether it succeeded.
   bool Init();
@@ -78,8 +82,9 @@
 
   chromeos_update_engine::HardwareInterface* const hardware_;
   chromeos_update_engine::BootControlInterface* const boot_control_;
-  org::chromium::LibCrosServiceInterfaceProxyInterface* const libcros_proxy_
-      ALLOW_UNUSED_TYPE;
+#if USE_CHROME_KIOSK_APP
+  org::chromium::LibCrosServiceInterfaceProxyInterface* const libcros_proxy_;
+#endif  // USE_CHROME_KIOSK_APP
 
   DISALLOW_COPY_AND_ASSIGN(RealSystemProvider);
 };
diff --git a/update_manager/real_system_provider_unittest.cc b/update_manager/real_system_provider_unittest.cc
index 821a6cc..33838e5 100644
--- a/update_manager/real_system_provider_unittest.cc
+++ b/update_manager/real_system_provider_unittest.cc
@@ -26,30 +26,30 @@
 #include "update_engine/common/fake_boot_control.h"
 #include "update_engine/common/fake_hardware.h"
 #include "update_engine/update_manager/umtest_utils.h"
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
 #include "libcros/dbus-proxies.h"
 #include "libcros/dbus-proxy-mocks.h"
 
 using org::chromium::LibCrosServiceInterfaceProxyMock;
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_KIOSK_APP
 using std::unique_ptr;
 using testing::_;
 using testing::DoAll;
 using testing::Return;
 using testing::SetArgPointee;
 
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
 namespace {
 const char kRequiredPlatformVersion[] ="1234.0.0";
 }  // namespace
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_KIOSK_APP
 
 namespace chromeos_update_manager {
 
 class UmRealSystemProviderTest : public ::testing::Test {
  protected:
   void SetUp() override {
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
     libcros_proxy_mock_.reset(new LibCrosServiceInterfaceProxyMock());
     ON_CALL(*libcros_proxy_mock_,
             GetKioskAppRequiredPlatformVersion(_, _, _))
@@ -61,7 +61,7 @@
 #else
     provider_.reset(
         new RealSystemProvider(&fake_hardware_, &fake_boot_control_, nullptr));
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_KIOSK_APP
     EXPECT_TRUE(provider_->Init());
   }
 
@@ -69,9 +69,9 @@
   chromeos_update_engine::FakeBootControl fake_boot_control_;
   unique_ptr<RealSystemProvider> provider_;
 
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
   unique_ptr<LibCrosServiceInterfaceProxyMock> libcros_proxy_mock_;
-#endif  // USE_LIBCROS
+#endif  // USE_CHROME_KIOSK_APP
 };
 
 TEST_F(UmRealSystemProviderTest, InitTest) {
@@ -91,7 +91,7 @@
   UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_complete());
 }
 
-#if USE_LIBCROS
+#if USE_CHROME_KIOSK_APP
 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersion) {
   UmTestUtils::ExpectVariableHasValue(
       std::string(kRequiredPlatformVersion),
@@ -129,6 +129,6 @@
   UmTestUtils::ExpectVariableHasValue(
       std::string(), provider_->var_kiosk_required_platform_version());
 }
-#endif
+#endif  // USE_CHROME_KIOSK_APP
 
 }  // namespace chromeos_update_manager
diff --git a/update_manager/state_factory.cc b/update_manager/state_factory.cc
index 70fc80b..a79b676 100644
--- a/update_manager/state_factory.cc
+++ b/update_manager/state_factory.cc
@@ -73,6 +73,7 @@
   unique_ptr<RealRandomProvider> random_provider(new RealRandomProvider());
   unique_ptr<RealSystemProvider> system_provider(new RealSystemProvider(
       system_state->hardware(), system_state->boot_control(), libcros_proxy));
+
   unique_ptr<RealTimeProvider> time_provider(new RealTimeProvider(clock));
   unique_ptr<RealUpdaterProvider> updater_provider(
       new RealUpdaterProvider(system_state));