1 // Copyright 2018 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_
7 
8 #include <set>
9 
10 #include "components/content_settings/core/browser/content_settings_origin_identifier_value_map.h"
11 #include "components/content_settings/core/browser/user_modifiable_provider.h"
12 
13 namespace base {
14 class Clock;
15 }
16 
17 namespace content_settings {
18 
19 // A user-modifiable content settings provider that doesn't store its settings
20 // on disk.
21 class EphemeralProvider : public UserModifiableProvider {
22  public:
23   EphemeralProvider(bool store_last_modified);
24   ~EphemeralProvider() override;
25 
26   // UserModifiableProvider implementations.
27   std::unique_ptr<RuleIterator> GetRuleIterator(
28       ContentSettingsType content_type,
29       const ResourceIdentifier& resource_identifier,
30       bool incognito) const override;
31   bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
32                          const ContentSettingsPattern& secondary_pattern,
33                          ContentSettingsType content_type,
34                          const ResourceIdentifier& resource_identifier,
35                          std::unique_ptr<base::Value>&& value) override;
36   void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
37   void ShutdownOnUIThread() override;
38   base::Time GetWebsiteSettingLastModified(
39       const ContentSettingsPattern& primary_pattern,
40       const ContentSettingsPattern& secondary_pattern,
41       ContentSettingsType content_type,
42       const ResourceIdentifier& resource_identifier) override;
43   void SetClockForTesting(base::Clock* clock) override;
44 
SetSupportedTypesForTesting(std::set<ContentSettingsType> & supported_types)45   void SetSupportedTypesForTesting(
46       std::set<ContentSettingsType>& supported_types) {
47     supported_types_ = supported_types;
48   }
GetCountForTesting()49   size_t GetCountForTesting() { return content_settings_rules_.size(); }
50 
51  private:
52   bool store_last_modified_;
53 
54   OriginIdentifierValueMap content_settings_rules_;
55 
56   std::set<ContentSettingsType> supported_types_;
57 
58   base::Clock* clock_;
59 
60   DISALLOW_COPY_AND_ASSIGN(EphemeralProvider);
61 };
62 
63 }  // namespace content_settings
64 
65 #endif  // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_EPHEMERAL_PROVIDER_H_
66