[Offline Prefetch] Check notification pref

Before scheduling new notifications for prefetched offline pages, check
the state of the Content Suggestions Notification preference setting.

Start displaying the notification preference page on pre-O devices when
the prefetched pages feature is enabled.

On O+ devices, notifications are handled at the system level by
Notification channels, so this pref can be ignored.

Bug: 944912
Change-Id: I9e53fa2037952af4e98400416ed307ef8bbc3968
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586595
Commit-Queue: Natalie Chouinard <[email protected]>
Reviewed-by: Theresa <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Carlos Knippschild <[email protected]>
Cr-Commit-Position: refs/heads/master@{#667278}
diff --git a/chrome/browser/android/preferences/prefs.h b/chrome/browser/android/preferences/prefs.h
index 5c58b0f4..a71d5f3 100644
--- a/chrome/browser/android/preferences/prefs.h
+++ b/chrome/browser/android/preferences/prefs.h
@@ -36,7 +36,6 @@
   AUTOFILL_CREDIT_CARD_ENABLED,
   USAGE_STATS_ENABLED,
   OFFLINE_PREFETCH_USER_SETTING_ENABLED,
-  CONTENT_SUGGESTIONS_NOTIFICATIONS_ENABLED,
   // PREF_NUM_PREFS must be the last entry.
   PREF_NUM_PREFS
 };
@@ -64,7 +63,6 @@
     autofill::prefs::kAutofillCreditCardEnabled,
     prefs::kUsageStatsEnabled,
     offline_pages::prefetch_prefs::kUserSettingEnabled,
-    offline_pages::prefetch_prefs::kContentSuggestionsNotificationsEnabled,
 };
 
 #endif  // CHROME_BROWSER_ANDROID_PREFERENCES_PREFS_H_
diff --git a/chrome/browser/android/preferences/prefs_unittest.cc b/chrome/browser/android/preferences/prefs_unittest.cc
index c590bf2..ab2e406 100644
--- a/chrome/browser/android/preferences/prefs_unittest.cc
+++ b/chrome/browser/android/preferences/prefs_unittest.cc
@@ -62,9 +62,6 @@
   EXPECT_EQ(prefs::kUsageStatsEnabled, GetPrefName(USAGE_STATS_ENABLED));
   EXPECT_EQ(offline_pages::prefetch_prefs::kUserSettingEnabled,
             GetPrefName(OFFLINE_PREFETCH_USER_SETTING_ENABLED));
-  EXPECT_EQ(
-      offline_pages::prefetch_prefs::kContentSuggestionsNotificationsEnabled,
-      GetPrefName(CONTENT_SUGGESTIONS_NOTIFICATIONS_ENABLED));
 
   // If this check fails, a pref is missing a test case above.
   EXPECT_EQ(Pref::PREF_NUM_PREFS, pref_count_);
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index 2d69e32..a2980c5a 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -436,6 +436,11 @@
     "ntp.content_suggestions.notifications.sent_count";
 const char kNotificationIDWithinCategory[] =
     "ContentSuggestionsNotificationIDWithinCategory";
+
+// Deprecated 5/2019.
+const char kContentSuggestionsNotificationsEnabled[] =
+    "ntp.content_suggestions.notifications.enabled";
+
 #endif  // defined(OS_ANDROID)
 
 #if !defined(OS_ANDROID)
@@ -499,6 +504,7 @@
   registry->RegisterIntegerPref(kContentSuggestionsNotificationsSentDay, 0);
   registry->RegisterIntegerPref(kContentSuggestionsNotificationsSentCount, 0);
   registry->RegisterStringPref(kNotificationIDWithinCategory, std::string());
+  registry->RegisterBooleanPref(kContentSuggestionsNotificationsEnabled, true);
 #endif  // defined(OS_ANDROID)
 
 #if !defined(OS_ANDROID)
@@ -1080,6 +1086,9 @@
   profile_prefs->ClearPref(kContentSuggestionsNotificationsSentDay);
   profile_prefs->ClearPref(kContentSuggestionsNotificationsSentCount);
   profile_prefs->ClearPref(kNotificationIDWithinCategory);
+
+  // Added 5/2019.
+  profile_prefs->ClearPref(kContentSuggestionsNotificationsEnabled);
 #endif  // defined(OS_ANDROID)
 
 #if !defined(OS_ANDROID)