Rework os_crypt on Windows to not always need access to DPAPI.

A data encryption key is stored in profile and encrypted with
DPAPI. DPAPI is needed during initialization but not during
encrypt/decrypt operations. Data encrypted with the new key
has a header to indicate the correct key to use, or whether
it was originally encrypted with raw DPAPI.

This allows code that uses os_crypt to run inside the sandbox
as long as Init() is called before lockdown, or the key is
manually set by calling SetRawEncryptionKey().

The network process, which uses os_crypt to encrypt some
cookies, is now passed the encryption key via the mojo
SetEncryptionKey interface, which is already used on macOS
for the same purpose.

NOTE: Reverting this CL will cause user data loss so
please consult before doing so.

BUG=1000799

Change-Id: I4453c4efbe52eaf4a264e12eb789219578e9caa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1842671
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Christos Froussios <[email protected]>
Commit-Queue: Will Harris <[email protected]>
Cr-Commit-Position: refs/heads/master@{#707696}
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index a960db92..510a4dc 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -331,7 +331,6 @@
 #if defined(OS_MACOSX)
 #include "chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h"
 #include "chrome/browser/ui/cocoa/confirm_quit.h"
-#include "components/os_crypt/os_crypt.h"
 #endif
 
 #if defined(OS_WIN)
@@ -345,6 +344,10 @@
 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_prefs_manager.h"
 #endif
 
+#if defined(OS_WIN) || defined(OS_MACOSX)
+#include "components/os_crypt/os_crypt.h"
+#endif
+
 #if defined(OS_WIN) || defined(OS_MACOSX) || \
     (defined(OS_LINUX) && !defined(OS_CHROMEOS))
 #include "chrome/browser/browser_switcher/browser_switcher_prefs.h"
@@ -729,11 +732,14 @@
 
 #if defined(OS_MACOSX)
   confirm_quit::RegisterLocalState(registry);
-  OSCrypt::RegisterLocalPrefs(registry);
   QuitWithAppsController::RegisterPrefs(registry);
   system_media_permissions::RegisterSystemMediaPermissionStatesPrefs(registry);
 #endif
 
+#if defined(OS_WIN) || defined(OS_MACOSX)
+  OSCrypt::RegisterLocalPrefs(registry);
+#endif
+
 #if defined(OS_WIN)
   registry->RegisterBooleanPref(prefs::kRendererCodeIntegrityEnabled, true);
   component_updater::RegisterPrefsForSwReporter(registry);