[Android] Adding content settings provider for notification channels

- Right now it just attempts to create channels on grant, and delete
them on resetting the permission.

- Java side is not yet implemented so this is actually a no-op.

BUG=700377

Review-Url: https://codereview.chromium.org/2886433002
Cr-Commit-Position: refs/heads/master@{#478267}
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
index 6bee9fc..22dc801e6 100644
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -311,6 +311,7 @@
     "//chrome/browser/android/webapk/chrome_webapk_host.h",
     "//chrome/browser/android/webapk/webapk_install_service.h",
     "//chrome/browser/banners/app_banner_settings_helper.h",
+    "//chrome/browser/notifications/notification_channels_provider_android.h",
     "//chrome/browser/notifications/notification_platform_bridge_android.cc",
     "//chrome/browser/ntp_snippets/ntp_snippets_metrics.h",
     "//chrome/browser/profiles/profile_metrics.h",
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationSettingsBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationSettingsBridge.java
new file mode 100644
index 0000000..5546b6e
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationSettingsBridge.java
@@ -0,0 +1,44 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.notifications;
+
+import org.chromium.base.BuildInfo;
+import org.chromium.base.annotations.CalledByNative;
+
+/**
+ * Interface for native code to interact with Android notification channels.
+ */
+public class NotificationSettingsBridge {
+    // TODO(awdf): Remove this and check BuildInfo.sdk_int() from native instead, once SdkVersion
+    // enum includes Android O.
+    @CalledByNative
+    static boolean shouldUseChannelSettings() {
+        return BuildInfo.isAtLeastO();
+    }
+
+    /**
+     * Creates a notification channel for the given origin.
+     * @param origin The site origin to be used as the channel name.
+     * @param enabled True if the channel should be initially enabled, false if
+     *                it should start off as blocked.
+     * @return true if the channel was successfully created, false otherwise.
+     */
+    @CalledByNative
+    static boolean createChannel(String origin, boolean enabled) {
+        // TODO(crbug.com/700377) Actually construct a channel.
+        return false;
+    }
+
+    @CalledByNative
+    static @NotificationChannelStatus int getChannelStatus(String origin) {
+        // TODO(crbug.com/700377) Actually check channel status.
+        return NotificationChannelStatus.UNAVAILABLE;
+    }
+
+    @CalledByNative
+    static void deleteChannel(String origin) {
+        // TODO(crbug.com/700377) Actually delete channel.
+    }
+}
diff --git a/chrome/android/java_sources.gni b/chrome/android/java_sources.gni
index c5aa7ed3..3c3d5d5c 100644
--- a/chrome/android/java_sources.gni
+++ b/chrome/android/java_sources.gni
@@ -598,6 +598,7 @@
   "java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java",
   "java/src/org/chromium/chrome/browser/notifications/NotificationJobService.java",
   "java/src/org/chromium/chrome/browser/notifications/NotificationService.java",
+  "java/src/org/chromium/chrome/browser/notifications/NotificationSettingsBridge.java",
   "java/src/org/chromium/chrome/browser/notifications/NotificationSystemStatusUtil.java",
   "java/src/org/chromium/chrome/browser/notifications/NotificationUmaTracker.java",
   "java/src/org/chromium/chrome/browser/notifications/StandardNotificationBuilder.java",
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 3243e7cb..aa464ff 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -762,6 +762,8 @@
     "notifications/non_persistent_notification_handler.h",
     "notifications/notification.cc",
     "notifications/notification.h",
+    "notifications/notification_channels_provider_android.cc",
+    "notifications/notification_channels_provider_android.h",
     "notifications/notification_common.cc",
     "notifications/notification_common.h",
     "notifications/notification_delegate.h",
@@ -4254,6 +4256,7 @@
       "../android/java/src/org/chromium/chrome/browser/net/spdyproxy/DataReductionProxySettings.java",
       "../android/java/src/org/chromium/chrome/browser/notifications/ActionInfo.java",
       "../android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java",
+      "../android/java/src/org/chromium/chrome/browser/notifications/NotificationSettingsBridge.java",
       "../android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java",
       "../android/java/src/org/chromium/chrome/browser/ntp/ForeignSessionHelper.java",
       "../android/java/src/org/chromium/chrome/browser/ntp/LogoBridge.java",
diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc
index a346556..b9e9a44 100644
--- a/chrome/browser/content_settings/host_content_settings_map_factory.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc
@@ -30,6 +30,10 @@
 #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
 #endif
 
+#if defined(OS_ANDROID)
+#include "chrome/browser/notifications/notification_channels_provider_android.h"
+#endif  // OS_ANDROID
+
 HostContentSettingsMapFactory::HostContentSettingsMapFactory()
     : RefcountedBrowserContextKeyedServiceFactory(
         "HostContentSettingsMap",
@@ -109,6 +113,15 @@
   }
 #endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
 
+#if defined(OS_ANDROID)
+  if (base::FeatureList::IsEnabled(features::kSiteNotificationChannels)) {
+    auto channels_provider =
+        base::MakeUnique<NotificationChannelsProviderAndroid>();
+    settings_map->RegisterProvider(
+        HostContentSettingsMap::NOTIFICATION_ANDROID_PROVIDER,
+        std::move(channels_provider));
+  }
+#endif  // defined (OS_ANDROID)
   return settings_map;
 }
 
diff --git a/chrome/browser/engagement/site_engagement_service_unittest.cc b/chrome/browser/engagement/site_engagement_service_unittest.cc
index 740e9c14..e029822 100644
--- a/chrome/browser/engagement/site_engagement_service_unittest.cc
+++ b/chrome/browser/engagement/site_engagement_service_unittest.cc
@@ -557,7 +557,7 @@
 
   settings_map->SetContentSettingDefaultScope(
       url3, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
-      content_settings::ResourceIdentifier(), CONTENT_SETTING_ASK);
+      content_settings::ResourceIdentifier(), CONTENT_SETTING_DEFAULT);
 
   EXPECT_EQ(5, service_->GetScore(url1));
   EXPECT_EQ(0, service_->GetScore(url2));
diff --git a/chrome/browser/notifications/notification_channels_provider_android.cc b/chrome/browser/notifications/notification_channels_provider_android.cc
new file mode 100644
index 0000000..272a520
--- /dev/null
+++ b/chrome/browser/notifications/notification_channels_provider_android.cc
@@ -0,0 +1,147 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/notification_channels_provider_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/content_settings/core/browser/content_settings_details.h"
+#include "components/content_settings/core/browser/content_settings_utils.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "components/content_settings/core/common/content_settings.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "jni/NotificationSettingsBridge_jni.h"
+#include "url/gurl.h"
+#include "url/origin.h"
+#include "url/url_constants.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ConvertUTF8ToJavaString;
+using base::android::ScopedJavaLocalRef;
+
+namespace {
+
+class NotificationChannelsBridgeImpl
+    : public NotificationChannelsProviderAndroid::NotificationChannelsBridge {
+ public:
+  NotificationChannelsBridgeImpl() = default;
+  ~NotificationChannelsBridgeImpl() override = default;
+
+  bool ShouldUseChannelSettings() override {
+    return Java_NotificationSettingsBridge_shouldUseChannelSettings(
+        AttachCurrentThread());
+  }
+
+  void CreateChannel(const std::string& origin, bool enabled) override {
+    JNIEnv* env = AttachCurrentThread();
+    Java_NotificationSettingsBridge_createChannel(
+        env, ConvertUTF8ToJavaString(env, origin), enabled);
+  }
+
+  NotificationChannelStatus GetChannelStatus(
+      const std::string& origin) override {
+    JNIEnv* env = AttachCurrentThread();
+    return static_cast<NotificationChannelStatus>(
+        Java_NotificationSettingsBridge_getChannelStatus(
+            env, ConvertUTF8ToJavaString(env, origin)));
+  }
+
+  void DeleteChannel(const std::string& origin) override {
+    JNIEnv* env = AttachCurrentThread();
+    Java_NotificationSettingsBridge_deleteChannel(
+        env, ConvertUTF8ToJavaString(env, origin));
+  }
+};
+
+}  // anonymous namespace
+
+NotificationChannelsProviderAndroid::NotificationChannelsProviderAndroid()
+    : NotificationChannelsProviderAndroid(
+          base::MakeUnique<NotificationChannelsBridgeImpl>()) {}
+
+NotificationChannelsProviderAndroid::NotificationChannelsProviderAndroid(
+    std::unique_ptr<NotificationChannelsBridge> bridge)
+    : bridge_(std::move(bridge)),
+      should_use_channels_(bridge_->ShouldUseChannelSettings()) {}
+
+NotificationChannelsProviderAndroid::~NotificationChannelsProviderAndroid() =
+    default;
+
+std::unique_ptr<content_settings::RuleIterator>
+NotificationChannelsProviderAndroid::GetRuleIterator(
+    ContentSettingsType content_type,
+    const content_settings::ResourceIdentifier& resource_identifier,
+    bool incognito) const {
+  // TODO(crbug.com/700377) return rule iterator over all channels
+  return nullptr;
+}
+
+bool NotificationChannelsProviderAndroid::SetWebsiteSetting(
+    const ContentSettingsPattern& primary_pattern,
+    const ContentSettingsPattern& secondary_pattern,
+    ContentSettingsType content_type,
+    const content_settings::ResourceIdentifier& resource_identifier,
+    base::Value* value) {
+  if (content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS ||
+      !should_use_channels_) {
+    return false;
+  }
+  // This provider only handles settings for specific origins.
+  if (primary_pattern == ContentSettingsPattern::Wildcard() &&
+      secondary_pattern == ContentSettingsPattern::Wildcard() &&
+      resource_identifier.empty()) {
+    return false;
+  }
+  url::Origin origin = url::Origin(GURL(primary_pattern.ToString()));
+  DCHECK(!origin.unique());
+  const std::string origin_string = origin.Serialize();
+  ContentSetting setting = content_settings::ValueToContentSetting(value);
+  switch (setting) {
+    case CONTENT_SETTING_ALLOW:
+      CreateChannelIfRequired(origin_string,
+                              NotificationChannelStatus::ENABLED);
+      break;
+    case CONTENT_SETTING_BLOCK:
+      CreateChannelIfRequired(origin_string,
+                              NotificationChannelStatus::BLOCKED);
+      break;
+    case CONTENT_SETTING_DEFAULT:
+      bridge_->DeleteChannel(origin_string);
+      break;
+    default:
+      // We rely on notification settings being one of ALLOW/BLOCK/DEFAULT.
+      NOTREACHED();
+      break;
+  }
+  return true;
+}
+
+void NotificationChannelsProviderAndroid::ClearAllContentSettingsRules(
+    ContentSettingsType content_type) {
+  // TODO(crbug.com/700377): If |content_type| == NOTIFICATIONS, delete
+  // all channels.
+}
+
+void NotificationChannelsProviderAndroid::ShutdownOnUIThread() {
+  RemoveAllObservers();
+}
+
+void NotificationChannelsProviderAndroid::CreateChannelIfRequired(
+    const std::string& origin_string,
+    NotificationChannelStatus new_channel_status) {
+  auto old_channel_status = bridge_->GetChannelStatus(origin_string);
+  if (old_channel_status == NotificationChannelStatus::UNAVAILABLE) {
+    bridge_->CreateChannel(
+        origin_string,
+        new_channel_status == NotificationChannelStatus::ENABLED);
+  } else {
+    // TODO(awdf): Maybe remove this DCHECK - channel status could change any
+    // time so this may be vulnerable to a race condition.
+    DCHECK(old_channel_status == new_channel_status);
+  }
+}
diff --git a/chrome/browser/notifications/notification_channels_provider_android.h b/chrome/browser/notifications/notification_channels_provider_android.h
new file mode 100644
index 0000000..95b62952
--- /dev/null
+++ b/chrome/browser/notifications/notification_channels_provider_android.h
@@ -0,0 +1,75 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_
+#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "components/content_settings/core/browser/content_settings_observable_provider.h"
+#include "components/content_settings/core/browser/content_settings_observer.h"
+#include "components/content_settings/core/browser/content_settings_rule.h"
+#include "components/content_settings/core/common/content_settings.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+#include "components/keyed_service/core/keyed_service.h"
+
+namespace {
+
+// A Java counterpart will be generated for this enum.
+// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications
+enum NotificationChannelStatus { ENABLED, BLOCKED, UNAVAILABLE };
+
+}  // anonymous namespace
+
+// This class provides notification content settings from system notification
+// channels on Android O+. This provider takes precedence over pref-provided
+// content settings, but defers to supervised user and policy settings - see
+// ordering of the ProviderType enum values in HostContentSettingsMap.
+class NotificationChannelsProviderAndroid
+    : public content_settings::ObservableProvider {
+ public:
+  // Helper class to make the JNI calls.
+  class NotificationChannelsBridge {
+   public:
+    virtual ~NotificationChannelsBridge() = default;
+    virtual bool ShouldUseChannelSettings() = 0;
+    virtual void CreateChannel(const std::string& origin, bool enabled) = 0;
+    virtual NotificationChannelStatus GetChannelStatus(
+        const std::string& origin) = 0;
+    virtual void DeleteChannel(const std::string& origin) = 0;
+  };
+
+  NotificationChannelsProviderAndroid();
+  ~NotificationChannelsProviderAndroid() override;
+
+  // ProviderInterface methods:
+  std::unique_ptr<content_settings::RuleIterator> GetRuleIterator(
+      ContentSettingsType content_type,
+      const content_settings::ResourceIdentifier& resource_identifier,
+      bool incognito) const override;
+  bool SetWebsiteSetting(
+      const ContentSettingsPattern& primary_pattern,
+      const ContentSettingsPattern& secondary_pattern,
+      ContentSettingsType content_type,
+      const content_settings::ResourceIdentifier& resource_identifier,
+      base::Value* value) override;
+  void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
+  void ShutdownOnUIThread() override;
+
+ private:
+  explicit NotificationChannelsProviderAndroid(
+      std::unique_ptr<NotificationChannelsBridge> bridge);
+  friend class NotificationChannelsProviderAndroidTest;
+
+  void CreateChannelIfRequired(const std::string& origin_string,
+                               NotificationChannelStatus new_channel_status);
+
+  std::unique_ptr<NotificationChannelsBridge> bridge_;
+  bool should_use_channels_;
+
+  DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid);
+};
+
+#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_
diff --git a/chrome/browser/notifications/notification_channels_provider_android_unittest.cc b/chrome/browser/notifications/notification_channels_provider_android_unittest.cc
new file mode 100644
index 0000000..2024fca
--- /dev/null
+++ b/chrome/browser/notifications/notification_channels_provider_android_unittest.cc
@@ -0,0 +1,131 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/notification_channels_provider_android.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
+#include "components/content_settings/core/browser/content_settings_pref.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+using ::testing::Return;
+
+namespace {
+const char kTestOrigin[] = "https://example.com";
+}  // namespace
+
+class MockNotificationChannelsBridge
+    : public NotificationChannelsProviderAndroid::NotificationChannelsBridge {
+ public:
+  ~MockNotificationChannelsBridge() = default;
+  MOCK_METHOD0(ShouldUseChannelSettings, bool());
+  MOCK_METHOD2(CreateChannel, void(const std::string&, bool));
+  MOCK_METHOD1(GetChannelStatus, NotificationChannelStatus(const std::string&));
+  MOCK_METHOD1(DeleteChannel, void(const std::string&));
+};
+
+class NotificationChannelsProviderAndroidTest : public testing::Test {
+ public:
+  NotificationChannelsProviderAndroidTest()
+      : mock_bridge_(new MockNotificationChannelsBridge()) {}
+  ~NotificationChannelsProviderAndroidTest() override {
+    channels_provider_->ShutdownOnUIThread();
+  }
+
+ protected:
+  // No leak because ownership is passed to channels_provider_ in constructor.
+  MockNotificationChannelsBridge* mock_bridge_;
+  std::unique_ptr<NotificationChannelsProviderAndroid> channels_provider_;
+  void InitChannelsProvider(bool should_use_channels) {
+    EXPECT_CALL(*mock_bridge_, ShouldUseChannelSettings())
+        .WillOnce(Return(should_use_channels));
+    // Can't use base::MakeUnique because the provider's constructor is private.
+    channels_provider_ =
+        base::WrapUnique(new NotificationChannelsProviderAndroid(
+            base::WrapUnique(mock_bridge_)));
+  }
+};
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingWhenChannelsShouldNotBeUsed_NoopAndReturnsFalse) {
+  this->InitChannelsProvider(false /* should_use_channels */);
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
+      new base::Value(CONTENT_SETTING_BLOCK));
+
+  EXPECT_FALSE(result);
+}
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingAllowedWhenChannelUnavailable_CreatesEnabledChannel) {
+  InitChannelsProvider(true /* should_use_channels */);
+  EXPECT_CALL(*mock_bridge_, GetChannelStatus(kTestOrigin))
+      .WillOnce(Return(NotificationChannelStatus::UNAVAILABLE));
+  EXPECT_CALL(*mock_bridge_, CreateChannel(kTestOrigin, true /* enabled */));
+
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
+      new base::Value(CONTENT_SETTING_ALLOW));
+
+  EXPECT_TRUE(result);
+}
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingBlockedWhenChannelUnavailable_CreatesDisabledChannel) {
+  InitChannelsProvider(true /* should_use_channels */);
+  EXPECT_CALL(*mock_bridge_, GetChannelStatus(kTestOrigin))
+      .WillOnce(Return(NotificationChannelStatus::UNAVAILABLE));
+  EXPECT_CALL(*mock_bridge_, CreateChannel(kTestOrigin, false /* enabled */));
+
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
+      new base::Value(CONTENT_SETTING_BLOCK));
+
+  EXPECT_TRUE(result);
+}
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingAllowedWhenChannelAllowed_NoopAndReturnsTrue) {
+  InitChannelsProvider(true /* should_use_channels */);
+  EXPECT_CALL(*mock_bridge_, GetChannelStatus(kTestOrigin))
+      .WillOnce(Return(NotificationChannelStatus::ENABLED));
+
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
+      new base::Value(CONTENT_SETTING_ALLOW));
+
+  EXPECT_TRUE(result);
+}
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingBlockedWhenChannelBlocked_NoopAndReturnsTrue) {
+  InitChannelsProvider(true /* should_use_channels */);
+  EXPECT_CALL(*mock_bridge_, GetChannelStatus(kTestOrigin))
+      .WillOnce(Return(NotificationChannelStatus::BLOCKED));
+
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
+      new base::Value(CONTENT_SETTING_BLOCK));
+
+  EXPECT_TRUE(result);
+}
+
+TEST_F(NotificationChannelsProviderAndroidTest,
+       SetWebsiteSettingDefault_DeletesChannelAndReturnsTrue) {
+  InitChannelsProvider(true /* should_use_channels */);
+  EXPECT_CALL(*mock_bridge_, DeleteChannel(kTestOrigin));
+  bool result = channels_provider_->SetWebsiteSetting(
+      ContentSettingsPattern::FromString(kTestOrigin), ContentSettingsPattern(),
+      CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), nullptr);
+
+  EXPECT_TRUE(result);
+}
diff --git a/chrome/common/chrome_features.cc b/chrome/common/chrome_features.cc
index e696257..d07f061 100644
--- a/chrome/common/chrome_features.cc
+++ b/chrome/common/chrome_features.cc
@@ -305,6 +305,13 @@
 const base::Feature kSafeSearchUrlReporting{"SafeSearchUrlReporting",
                                             base::FEATURE_DISABLED_BY_DEFAULT};
 
+#if defined(OS_ANDROID)
+// Enables separate notification channels in Android O for notifications from
+// different origins, instead of sending them all to a single 'Sites' channel.
+const base::Feature kSiteNotificationChannels{
+    "SiteNotificationChannels", base::FEATURE_DISABLED_BY_DEFAULT};
+#endif  // defined (OS_ANDROID)
+
 // A new user experience for transitioning into fullscreen and mouse pointer
 // lock states.
 const base::Feature kSimplifiedFullscreenUI{"ViewsSimplifiedFullscreenUI",
diff --git a/chrome/common/chrome_features.h b/chrome/common/chrome_features.h
index 96861ed..1ba9a8b 100644
--- a/chrome/common/chrome_features.h
+++ b/chrome/common/chrome_features.h
@@ -166,6 +166,10 @@
 
 extern const base::Feature kSiteDetails;
 
+#if defined(OS_ANDROID)
+extern const base::Feature kSiteNotificationChannels;
+#endif
+
 #if defined(SYZYASAN)
 extern const base::Feature kSyzyasanDeferredFree;
 #endif
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index f5cd21b..6d128ec 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -3118,6 +3118,7 @@
     "../browser/net/spdyproxy/data_reduction_proxy_settings_unittest_android.cc",
     "../browser/net/url_info_unittest.cc",
     "../browser/notifications/desktop_notification_profile_util_unittest.cc",
+    "../browser/notifications/notification_channels_provider_android_unittest.cc",
     "../browser/notifications/notification_permission_context_unittest.cc",
     "../browser/notifications/notification_platform_bridge_mac_unittest.mm",
     "../browser/notifications/platform_notification_service_unittest.cc",
diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc
index 52a6708..92c7e2a3 100644
--- a/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/components/content_settings/core/browser/host_content_settings_map.cc
@@ -55,6 +55,7 @@
     {"policy", content_settings::SETTING_SOURCE_POLICY},
     {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED},
     {"extension", content_settings::SETTING_SOURCE_EXTENSION},
+    {"notification_android", content_settings::SETTING_SOURCE_USER},
     {"preference", content_settings::SETTING_SOURCE_USER},
     {"default", content_settings::SETTING_SOURCE_USER},
 };
@@ -384,6 +385,8 @@
     std::unique_ptr<base::Value> value) {
   DCHECK(SupportsResourceIdentifier(content_type) ||
          resource_identifier.empty());
+  // TODO(crbug.com/731126): Verify that assumptions for notification content
+  // settings are met.
   UsedContentSettingsProviders();
 
   for (const auto& provider_pair : content_settings_providers_) {
@@ -910,4 +913,4 @@
 void HostContentSettingsMap::SetClockForTesting(
     std::unique_ptr<base::Clock> clock) {
   pref_provider_->SetClockForTesting(std::move(clock));
-}
\ No newline at end of file
+}
diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h
index b5c7798b..b9f4bfb 100644
--- a/components/content_settings/core/browser/host_content_settings_map.h
+++ b/components/content_settings/core/browser/host_content_settings_map.h
@@ -57,6 +57,7 @@
     POLICY_PROVIDER,
     SUPERVISED_PROVIDER,
     CUSTOM_EXTENSION_PROVIDER,
+    NOTIFICATION_ANDROID_PROVIDER,
     PREF_PROVIDER,
     DEFAULT_PROVIDER,
     NUM_PROVIDER_TYPES