| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/content_settings/core/browser/content_settings_observable_p
rovider.h" | 11 #include "components/content_settings/core/browser/content_settings_observable_p
rovider.h" |
| 12 #include "components/content_settings/core/browser/content_settings_observer.h" | 12 #include "components/content_settings/core/browser/content_settings_observer.h" |
| 13 #include "components/content_settings/core/browser/content_settings_rule.h" | 13 #include "components/content_settings/core/browser/content_settings_rule.h" |
| 14 #include "components/content_settings/core/common/content_settings.h" | 14 #include "components/content_settings/core/common/content_settings.h" |
| 15 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 // A Java counterpart will be generated for this enum. | 18 // A Java counterpart will be generated for this enum. |
| 21 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications | 19 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications |
| 22 enum NotificationChannelStatus { ENABLED, BLOCKED, UNAVAILABLE }; | 20 enum NotificationChannelStatus { ENABLED, BLOCKED, UNAVAILABLE }; |
| 23 | 21 |
| 24 } // anonymous namespace | 22 struct NotificationChannel { |
| 23 NotificationChannel(std::string origin, NotificationChannelStatus status) |
| 24 : origin_(origin), status_(status) {} |
| 25 std::string origin_; |
| 26 NotificationChannelStatus status_ = NotificationChannelStatus::UNAVAILABLE; |
| 27 }; |
| 25 | 28 |
| 26 // This class provides notification content settings from system notification | 29 // This class provides notification content settings from system notification |
| 27 // channels on Android O+. This provider takes precedence over pref-provided | 30 // channels on Android O+. This provider takes precedence over pref-provided |
| 28 // content settings, but defers to supervised user and policy settings - see | 31 // content settings, but defers to supervised user and policy settings - see |
| 29 // ordering of the ProviderType enum values in HostContentSettingsMap. | 32 // ordering of the ProviderType enum values in HostContentSettingsMap. |
| 30 class NotificationChannelsProviderAndroid | 33 class NotificationChannelsProviderAndroid |
| 31 : public content_settings::ObservableProvider { | 34 : public content_settings::ObservableProvider { |
| 32 public: | 35 public: |
| 33 // Helper class to make the JNI calls. | 36 // Helper class to make the JNI calls. |
| 34 class NotificationChannelsBridge { | 37 class NotificationChannelsBridge { |
| 35 public: | 38 public: |
| 36 virtual ~NotificationChannelsBridge() = default; | 39 virtual ~NotificationChannelsBridge() = default; |
| 37 virtual bool ShouldUseChannelSettings() = 0; | 40 virtual bool ShouldUseChannelSettings() = 0; |
| 38 virtual void CreateChannel(const std::string& origin, bool enabled) = 0; | 41 virtual void CreateChannel(const std::string& origin, bool enabled) = 0; |
| 39 virtual NotificationChannelStatus GetChannelStatus( | 42 virtual NotificationChannelStatus GetChannelStatus( |
| 40 const std::string& origin) = 0; | 43 const std::string& origin) = 0; |
| 41 virtual void DeleteChannel(const std::string& origin) = 0; | 44 virtual void DeleteChannel(const std::string& origin) = 0; |
| 45 virtual std::vector<NotificationChannel> GetChannels() = 0; |
| 42 }; | 46 }; |
| 43 | 47 |
| 44 NotificationChannelsProviderAndroid(); | 48 NotificationChannelsProviderAndroid(); |
| 45 ~NotificationChannelsProviderAndroid() override; | 49 ~NotificationChannelsProviderAndroid() override; |
| 46 | 50 |
| 47 // ProviderInterface methods: | 51 // ProviderInterface methods: |
| 48 std::unique_ptr<content_settings::RuleIterator> GetRuleIterator( | 52 std::unique_ptr<content_settings::RuleIterator> GetRuleIterator( |
| 49 ContentSettingsType content_type, | 53 ContentSettingsType content_type, |
| 50 const content_settings::ResourceIdentifier& resource_identifier, | 54 const content_settings::ResourceIdentifier& resource_identifier, |
| 51 bool incognito) const override; | 55 bool incognito) const override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 void CreateChannelIfRequired(const std::string& origin_string, | 70 void CreateChannelIfRequired(const std::string& origin_string, |
| 67 NotificationChannelStatus new_channel_status); | 71 NotificationChannelStatus new_channel_status); |
| 68 | 72 |
| 69 std::unique_ptr<NotificationChannelsBridge> bridge_; | 73 std::unique_ptr<NotificationChannelsBridge> bridge_; |
| 70 bool should_use_channels_; | 74 bool should_use_channels_; |
| 71 | 75 |
| 72 DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid); | 76 DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid); |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H
_ | 79 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H
_ |
| OLD | NEW |