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

Side by Side Diff: chrome/browser/notifications/notification_channels_provider_android.h

Issue 2886433002: [Android] Adding content settings provider for notification channels (Closed)
Patch Set: Conditionally include new header file Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H_
7
8 #include <string>
9
10 #include "base/macros.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"
13 #include "components/content_settings/core/browser/content_settings_rule.h"
14 #include "components/content_settings/core/common/content_settings.h"
15 #include "components/content_settings/core/common/content_settings_types.h"
16 #include "components/keyed_service/core/keyed_service.h"
17
18 namespace {
19
20 // A Java counterpart will be generated for this enum.
21 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications
22 enum NotificationChannelStatus { ENABLED, BLOCKED, UNAVAILABLE };
23
24 } // anonymous namespace
25
26 // This class provides notification content settings from system notification
27 // channels on Android O+. This provider takes precedence over pref-provided
28 // content settings, but defers to supervised user and policy settings - see
29 // ordering of the ProviderType enum values in HostContentSettingsMap.
30 class NotificationChannelsProviderAndroid
31 : public content_settings::ObservableProvider {
32 public:
33 // Helper class to make the JNI calls.
34 class NotificationChannelsBridge {
35 public:
36 virtual ~NotificationChannelsBridge() = default;
37 virtual bool ShouldUseChannelSettings() = 0;
38 virtual void CreateChannel(const std::string& origin, bool enabled) = 0;
39 virtual NotificationChannelStatus GetChannelStatus(
40 const std::string& origin) = 0;
41 virtual void DeleteChannel(const std::string& origin) = 0;
42 };
43
44 NotificationChannelsProviderAndroid();
45 ~NotificationChannelsProviderAndroid() override;
46
47 // ProviderInterface methods:
48 std::unique_ptr<content_settings::RuleIterator> GetRuleIterator(
49 ContentSettingsType content_type,
50 const content_settings::ResourceIdentifier& resource_identifier,
51 bool incognito) const override;
52 bool SetWebsiteSetting(
53 const ContentSettingsPattern& primary_pattern,
54 const ContentSettingsPattern& secondary_pattern,
55 ContentSettingsType content_type,
56 const content_settings::ResourceIdentifier& resource_identifier,
57 base::Value* value) override;
58 void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
59 void ShutdownOnUIThread() override;
60
61 private:
62 explicit NotificationChannelsProviderAndroid(
63 std::unique_ptr<NotificationChannelsBridge> bridge);
64 friend class NotificationChannelsProviderAndroidTest;
65
66 void CreateChannelIfRequired(const std::string& origin_string,
67 NotificationChannelStatus new_channel_status);
68
69 std::unique_ptr<NotificationChannelsBridge> bridge_;
70 bool should_use_channels_;
71
72 DISALLOW_COPY_AND_ASSIGN(NotificationChannelsProviderAndroid);
73 };
74
75 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_CHANNELS_PROVIDER_ANDROID_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698