Add a build flag to use platform GCM.

Android Things, a variant on Android that may not have gmscore, needs
GCM. To enable this, make the GCM client selection a build flag.

The build flag is USE_GCM_FROM_PLATFORM which is false for non-Android builds.

Bug: 62139031
Test: manual test on device
Review-Url: https://codereview.chromium.org/2922893002
Cr-Commit-Position: refs/heads/master@{#479500}
diff --git a/components/gcm_driver/BUILD.gn b/components/gcm_driver/BUILD.gn
index 2a549fa8..4b61384 100644
--- a/components/gcm_driver/BUILD.gn
+++ b/components/gcm_driver/BUILD.gn
@@ -2,12 +2,16 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build/buildflag_header.gni")
+import("//components/gcm_driver/config.gni")
+
+buildflag_header("gcm_build_features") {
+  header = "gcm_build_features.h"
+  flags = [ "USE_GCM_FROM_PLATFORM=$use_gcm_from_platform" ]
+}
+
 static_library("gcm_driver") {
   sources = [
-    "android/component_jni_registrar.cc",
-    "android/component_jni_registrar.h",
-    "gcm_account_mapper.cc",
-    "gcm_account_mapper.h",
     "gcm_account_tracker.cc",
     "gcm_account_tracker.h",
     "gcm_activity.cc",
@@ -16,40 +20,22 @@
     "gcm_app_handler.h",
     "gcm_backoff_policy.cc",
     "gcm_backoff_policy.h",
-    "gcm_channel_status_request.cc",
-    "gcm_channel_status_request.h",
-    "gcm_channel_status_syncer.cc",
-    "gcm_channel_status_syncer.h",
     "gcm_client.cc",
     "gcm_client.h",
-    "gcm_client_factory.cc",
-    "gcm_client_factory.h",
-    "gcm_client_impl.cc",
-    "gcm_client_impl.h",
     "gcm_connection_observer.cc",
     "gcm_connection_observer.h",
     "gcm_delayed_task_controller.cc",
     "gcm_delayed_task_controller.h",
-    "gcm_desktop_utils.cc",
-    "gcm_desktop_utils.h",
     "gcm_driver.cc",
     "gcm_driver.h",
-    "gcm_driver_android.cc",
-    "gcm_driver_android.h",
     "gcm_driver_constants.cc",
     "gcm_driver_constants.h",
-    "gcm_driver_desktop.cc",
-    "gcm_driver_desktop.h",
     "gcm_internals_constants.cc",
     "gcm_internals_constants.h",
     "gcm_internals_helper.cc",
     "gcm_internals_helper.h",
     "gcm_profile_service.cc",
     "gcm_profile_service.h",
-    "gcm_stats_recorder_android.cc",
-    "gcm_stats_recorder_android.h",
-    "gcm_stats_recorder_impl.cc",
-    "gcm_stats_recorder_impl.h",
     "registration_info.cc",
     "registration_info.h",
     "system_encryptor.cc",
@@ -63,6 +49,7 @@
     "//components/gcm_driver/instance_id",
   ]
   deps = [
+    ":gcm_build_features",
     "//base:i18n",
     "//components/crx_file",
     "//components/data_use_measurement/core",
@@ -90,8 +77,17 @@
     deps += [ "//components/timers" ]
   }
 
-  if (is_android) {
-    sources -= [
+  if (use_gcm_from_platform) {
+    sources += [
+      "android/component_jni_registrar.cc",
+      "android/component_jni_registrar.h",
+      "gcm_driver_android.cc",
+      "gcm_driver_android.h",
+      "gcm_stats_recorder_android.cc",
+      "gcm_stats_recorder_android.h",
+    ]
+  } else {
+    sources += [
       "gcm_account_mapper.cc",
       "gcm_account_mapper.h",
       "gcm_channel_status_request.cc",
@@ -109,10 +105,13 @@
       "gcm_stats_recorder_impl.cc",
       "gcm_stats_recorder_impl.h",
     ]
-    deps -= [
+    deps += [
       "//components/crx_file",
       "//google_apis/gcm",
     ]
+  }
+
+  if (is_android) {
     deps += [ "android:jni_headers" ]
   }
 }
@@ -122,10 +121,6 @@
   sources = [
     "fake_gcm_app_handler.cc",
     "fake_gcm_app_handler.h",
-    "fake_gcm_client.cc",
-    "fake_gcm_client.h",
-    "fake_gcm_client_factory.cc",
-    "fake_gcm_client_factory.h",
     "fake_gcm_driver.cc",
     "fake_gcm_driver.h",
   ]
@@ -140,14 +135,14 @@
     "//testing/gtest",
   ]
 
-  if (is_android) {
-    sources -= [
+  if (!use_gcm_from_platform) {
+    sources += [
       "fake_gcm_client.cc",
       "fake_gcm_client.h",
       "fake_gcm_client_factory.cc",
       "fake_gcm_client_factory.h",
     ]
-    deps -= [ "//google_apis/gcm:test_support" ]
+    deps += [ "//google_apis/gcm:test_support" ]
   }
 }
 
@@ -155,14 +150,9 @@
   testonly = true
 
   sources = [
-    "gcm_account_mapper_unittest.cc",
     "gcm_account_tracker_unittest.cc",
-    "gcm_channel_status_request_unittest.cc",
-    "gcm_client_impl_unittest.cc",
     "gcm_delayed_task_controller_unittest.cc",
-    "gcm_driver_desktop_unittest.cc",
     "gcm_stats_recorder_android_unittest.cc",
-    "gcm_stats_recorder_impl_unittest.cc",
   ]
 
   deps = [
@@ -180,8 +170,8 @@
     "//third_party/protobuf:protobuf_lite",
   ]
 
-  if (is_android) {
-    sources -= [
+  if (!use_gcm_from_platform) {
+    sources += [
       "gcm_account_mapper_unittest.cc",
       "gcm_channel_status_request_unittest.cc",
       "gcm_client_impl_unittest.cc",