[Stylize] Create a Random Order Pref

If the current experiment enables templates' random ordering, create a
random order and store the list of templates IDs in a pref. Upon
re-fetch of the templates (whenever the user opens the Stylize page),
read the pref and order the templates based on the list order.

Fixed: 1217736
Change-Id: I8969e3a57d3077a056e482432d0f589b7f0aa4bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2963994
Reviewed-by: Dominic Battré <[email protected]>
Reviewed-by: sebsg <[email protected]>
Reviewed-by: David Trainor <[email protected]>
Commit-Queue: Sebastien Lalancette <[email protected]>
Cr-Commit-Position: refs/heads/master@{#894770}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index c9bdb3c..04a23f0 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -3282,6 +3282,7 @@
       "//components/content_creation/notes/android",
       "//components/content_creation/notes/core",
       "//components/content_creation/notes/core:features",
+      "//components/content_creation/notes/core:prefs",
       "//components/content_creation/notes/core/server",
       "//components/content_creation/notes/core/templates",
       "//components/content_settings/android",
diff --git a/chrome/browser/content_creation/notes/internal/note_service_factory.cc b/chrome/browser/content_creation/notes/internal/note_service_factory.cc
index 8a55c5d..b59895b3 100644
--- a/chrome/browser/content_creation/notes/internal/note_service_factory.cc
+++ b/chrome/browser/content_creation/notes/internal/note_service_factory.cc
@@ -42,7 +42,7 @@
     content::BrowserContext* context) const {
   Profile* profile = Profile::FromBrowserContext(context);
 
-  return new NoteService(std::make_unique<TemplateStore>(),
+  return new NoteService(std::make_unique<TemplateStore>(profile->GetPrefs()),
                          std::make_unique<NotesRepository>(
                              IdentityManagerFactory::GetForProfile(profile),
                              context->GetDefaultStoragePartition()
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index cdfe227..b03023e2 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -220,6 +220,7 @@
 #include "chrome/browser/ssl/known_interception_disclosure_infobar_delegate.h"
 #include "chrome/browser/video_tutorials/prefs.h"
 #include "components/cdm/browser/media_drm_storage_impl.h"  // nogncheck crbug.com/1125897
+#include "components/content_creation/notes/core/note_prefs.h"
 #include "components/feed/buildflags.h"
 #include "components/feed/core/common/pref_names.h"
 #include "components/feed/core/shared_prefs/pref_names.h"
@@ -1099,6 +1100,7 @@
 
 #if defined(OS_ANDROID)
   cdm::MediaDrmStorageImpl::RegisterProfilePrefs(registry);
+  content_creation::prefs::RegisterProfilePrefs(registry);
   explore_sites::HistoryStatisticsReporter::RegisterPrefs(registry);
   permissions::GeolocationPermissionContextAndroid::RegisterProfilePrefs(
       registry);