LaCrOS: Replace defined(OS_CHROMEOS) with BUILDFLAG(IS_CHROMEOS_ASH)

The change is mostly mechanical replacing defined(OS_CHROMEOS) with
BUILDFLAG(IS_CHROMEOS_ASH) and GN variable is_chromeos with is_ash
with some special cases (For those cases please refer to
http://go/lacros-macros).

The patch is made in preparation to switching lacros build from
target_os=linux to target_os=chromeos. This will prevent lacros from
changing behaviour after the switch.

Bug: 1052397
Change-Id: I5ec5132b286ab2f67e971abca49c72f9117870bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2494401
Commit-Queue: Yuta Hijikata <[email protected]>
Reviewed-by: Michael Ershov <[email protected]>
Reviewed-by: Ryan Sleevi <[email protected]>
Cr-Commit-Position: refs/heads/master@{#826695}
diff --git a/crypto/BUILD.gn b/crypto/BUILD.gn
index c0efa3a8..c5d6af8 100644
--- a/crypto/BUILD.gn
+++ b/crypto/BUILD.gn
@@ -2,6 +2,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//build/config/chromeos/ui_mode.gni")
 import("//build/config/crypto.gni")
 import("//testing/test.gni")
 
@@ -115,9 +116,10 @@
       "nss_util.h",
       "nss_util_internal.h",
     ]
+    deps += [ "//build:chromeos_buildflags" ]
   }
 
-  if (is_chromeos) {
+  if (is_chromeos_ash) {
     sources += [ "nss_util_chromeos.cc" ]
   }
 
@@ -178,7 +180,7 @@
     ]
   }
 
-  if (is_chromeos) {
+  if (is_chromeos_ash) {
     sources += [
       "scoped_test_nss_chromeos_user.cc",
       "scoped_test_nss_chromeos_user.h",
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index d369529..0f124c2 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -27,6 +27,7 @@
 #include "base/threading/scoped_blocking_call.h"
 #include "base/threading/thread_restrictions.h"
 #include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
 #include "crypto/nss_crypto_module_delegate.h"
 #include "crypto/nss_util_internal.h"
 
@@ -34,13 +35,13 @@
 
 namespace {
 
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
 // Fake certificate authority database used for testing.
 static const base::FilePath::CharType kReadOnlyCertDB[] =
     FILE_PATH_LITERAL("/etc/fake_root_ca/nssdb");
-#endif  // defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 
-#if !defined(OS_CHROMEOS)
+#if !BUILDFLAG(IS_CHROMEOS_ASH)
 base::FilePath GetDefaultConfigDirectory() {
   base::FilePath dir;
   base::PathService::Get(base::DIR_HOME, &dir);
@@ -56,7 +57,7 @@
   DVLOG(2) << "DefaultConfigDirectory: " << dir.value();
   return dir;
 }
-#endif  // !defined(OS_CHROMEOS)
+#endif  // !BUILDFLAG(IS_CHROMEOS_ASH)
 
 // On non-Chrome OS platforms, return the default config directory. On Chrome OS
 // test images, return a read-only directory with fake root CA certs (which are
@@ -64,14 +65,14 @@
 // code). On Chrome OS non-test images (where the read-only directory doesn't
 // exist), return an empty path.
 base::FilePath GetInitialConfigDirectory() {
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
   base::FilePath database_dir = base::FilePath(kReadOnlyCertDB);
   if (!base::PathExists(database_dir))
     database_dir.clear();
   return database_dir;
 #else
   return GetDefaultConfigDirectory();
-#endif  // defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 }
 
 // This callback for NSS forwards all requests to a caller-specified
@@ -157,7 +158,7 @@
       // Use "sql:" which can be shared by multiple processes safely.
       std::string nss_config_dir =
           base::StringPrintf("sql:%s", database_dir.value().c_str());
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
       status = NSS_Init(nss_config_dir.c_str());
 #else
       status = NSS_InitReadWrite(nss_config_dir.c_str());
diff --git a/crypto/nss_util.h b/crypto/nss_util.h
index d069164..fd27095e 100644
--- a/crypto/nss_util.h
+++ b/crypto/nss_util.h
@@ -11,6 +11,7 @@
 #include "base/callback.h"
 #include "base/compiler_specific.h"
 #include "base/macros.h"
+#include "build/chromeos_buildflags.h"
 #include "crypto/crypto_export.h"
 
 namespace base {
@@ -35,7 +36,7 @@
 // A sample version string is "3.12.3".
 bool CheckNSSVersion(const char* version);
 
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
 // Indicates that NSS should use the Chaps library so that we
 // can access the TPM through NSS.  InitializeTPMTokenAndSystemSlot and
 // InitializeTPMForChromeOSUser must still be called to load the slots.
diff --git a/crypto/nss_util_internal.h b/crypto/nss_util_internal.h
index 5d9c673..7221375 100644
--- a/crypto/nss_util_internal.h
+++ b/crypto/nss_util_internal.h
@@ -12,6 +12,7 @@
 #include "base/callback.h"
 #include "base/compiler_specific.h"
 #include "base/macros.h"
+#include "build/chromeos_buildflags.h"
 #include "crypto/crypto_export.h"
 #include "crypto/scoped_nss_types.h"
 
@@ -42,7 +43,7 @@
   DISALLOW_COPY_AND_ASSIGN(AutoSECMODListReadLock);
 };
 
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
 // Returns a reference to the system-wide TPM slot if it is loaded. If it is not
 // loaded and |callback| is non-null, the |callback| will be run once the slot
 // is loaded.
@@ -124,7 +125,7 @@
 // Returns true if chaps is the module to which |slot| is attached.
 CRYPTO_EXPORT bool IsSlotProvidedByChaps(PK11SlotInfo* slot);
 
-#endif  // defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
 
 // Loads the given module for this NSS session.
 SECMODModule* LoadNSSModule(const char* name,