[headless] Don't CHECK() crash on OSCrypt initialization failure.

Also do not attempt to initialize OSCrypt if cookie encryption is disabled.

BUG=1173214

Change-Id: Ibfc010005d27221d0e58c09df4d58e27ef019aa8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2665975
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#849347}
diff --git a/headless/lib/browser/headless_browser_main_parts.cc b/headless/lib/browser/headless_browser_main_parts.cc
index 70f0415..06c4754c 100644
--- a/headless/lib/browser/headless_browser_main_parts.cc
+++ b/headless/lib/browser/headless_browser_main_parts.cc
@@ -4,6 +4,7 @@
 
 #include "headless/lib/browser/headless_browser_main_parts.h"
 
+#include "headless/app/headless_shell_switches.h"
 #include "headless/lib/browser/headless_browser_context_impl.h"
 #include "headless/lib/browser/headless_browser_impl.h"
 #include "headless/lib/browser/headless_devtools.h"
@@ -100,7 +101,11 @@
   local_state_ = factory.Create(std::move(pref_registry));
 
 #if defined(OS_WIN)
-  CHECK(OSCrypt::Init(local_state_.get()));
+  if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kDisableCookieEncryption)) {
+    if (!OSCrypt::Init(local_state_.get()))
+      LOG(ERROR) << "Failed to initialize OSCrypt";
+  }
 #endif
 }
 #endif  // defined(HEADLESS_USE_PREFS)