Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(764)

Unified Diff: chrome/browser/notifications/notification_channels_provider_android.h

Issue 2886433002: [Android] Adding content settings provider for notification channels (Closed)
Patch Set: Added unit tests (refactored out a class for jni calls) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_channels_provider_android.h
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 0000000000000000000000000000000000000000..40f9c674ec9e10fc5c0dc5aee611cd2ed5a6021a
--- /dev/null
+++ b/chrome/browser/notifications/notification_channels_provider_android.h
@@ -0,0 +1,72 @@
+// 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 {
raymes 2017/05/24 00:59:51 nit: newline after this
awdf 2017/06/01 15:11:22 Done.
+// 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();
+ explicit NotificationChannelsProviderAndroid(
+ std::unique_ptr<NotificationChannelsBridge> bridge);
Peter Beverloo 2017/05/24 10:57:42 Consider making this private with a friends declar
awdf 2017/06/01 15:11:21 Done.
+ ~NotificationChannelsProviderAndroid() override;
+
+ // ProviderInterface methods:
+ std::unique_ptr<content_settings::RuleIterator> GetRuleIterator(
+ ContentSettingsType content_type,
+ const content_settings::ResourceIdentifier& resource_identifier,
+ bool incognito) const override;
+
Peter Beverloo 2017/05/24 10:57:42 nit: no blank lines
awdf 2017/06/01 15:11:22 Done.
+ 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:
+ std::unique_ptr<NotificationChannelsBridge> bridge_;
+ bool should_use_channels_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid);
+};
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_

Powered by Google App Engine
This is Rietveld 408576698