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 std::string origin_; | |
24 NotificationChannelStatus status_ = NotificationChannelStatus::UNAVAILABLE; | |
25 NotificationChannel(std::string origin, NotificationChannelStatus status) | |
26 : origin_(origin), status_(status) {} | |
raymes
2017/06/04 23:51:21
nit: methods always come before member variables
awdf
2017/06/05 16:29:26
Done.
| |
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 11 matching lines...) Expand all Loading... | |
63 std::unique_ptr<NotificationChannelsBridge> bridge); | 67 std::unique_ptr<NotificationChannelsBridge> bridge); |
64 friend class NotificationChannelsProviderAndroidTest; | 68 friend class NotificationChannelsProviderAndroidTest; |
65 | 69 |
66 std::unique_ptr<NotificationChannelsBridge> bridge_; | 70 std::unique_ptr<NotificationChannelsBridge> bridge_; |
67 bool should_use_channels_; | 71 bool should_use_channels_; |
68 | 72 |
69 DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid); | 73 DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid); |
70 }; | 74 }; |
71 | 75 |
72 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H _ | 76 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H _ |
OLD | NEW |