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_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA NAGER_H_ | 5 #ifndef CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA NAGER_H_ |
6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA NAGER_H_ | 6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS_MA NAGER_H_ |
7 | 7 |
8 #include <memory> | |
engedy
2017/04/12 14:02:51
#include <utility> for std::move
Charlie Harrison
2017/04/12 17:53:45
Done.
| |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/time/clock.h" | |
11 #include "components/content_settings/core/browser/content_settings_observer.h" | 13 #include "components/content_settings/core/browser/content_settings_observer.h" |
14 #include "components/content_settings/core/common/content_settings.h" | |
12 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
14 | 17 |
15 class ContentSettingsPattern; | 18 class ContentSettingsPattern; |
19 class GURL; | |
16 class HostContentSettingsMap; | 20 class HostContentSettingsMap; |
17 class Profile; | 21 class Profile; |
18 | 22 |
23 namespace base { | |
24 class DictionaryValue; | |
25 } // namespace base | |
26 | |
19 // This class observes subresource filter content settings changes for metrics | 27 // This class observes subresource filter content settings changes for metrics |
20 // collection. | 28 // collection. It is also contains helpers to get/set content settings. |
engedy
2017/04/12 14:02:51
nit: Swap the order. I'd argue that it is now the
Charlie Harrison
2017/04/12 17:53:45
Done.
| |
21 class SubresourceFilterContentSettingsManager | 29 class SubresourceFilterContentSettingsManager |
22 : public KeyedService, | 30 : public KeyedService, |
23 public content_settings::Observer { | 31 public content_settings::Observer { |
24 public: | 32 public: |
25 explicit SubresourceFilterContentSettingsManager(Profile* profile); | 33 explicit SubresourceFilterContentSettingsManager(Profile* profile); |
26 ~SubresourceFilterContentSettingsManager() override; | 34 ~SubresourceFilterContentSettingsManager() override; |
27 | 35 |
36 ContentSetting GetContentSetting(const GURL& url) const; | |
37 void SetContentSetting(const GURL& url, | |
38 ContentSetting setting, | |
39 bool log_metrics); | |
40 void ClearContentSetting(const GURL& url); | |
41 | |
42 // Specific logic for more intelligent UI. | |
43 void OnDidShowUI(const GURL& url); | |
44 bool ShouldShowUIForSite(const GURL& url) const; | |
45 bool should_use_smart_ui() const { return should_use_smart_ui_; } | |
46 | |
47 void set_clock_for_testing(std::unique_ptr<base::Clock> tick_clock) { | |
48 clock_ = std::move(tick_clock); | |
49 } | |
50 | |
51 // Time before showing the UI again on a domain. | |
52 // TODO(csharrison): Consider setting this via a finch param. | |
53 static const base::TimeDelta kUIShowThresholdTime; | |
engedy
2017/04/12 14:02:51
#include "base/time.h"
Charlie Harrison
2017/04/12 17:53:45
Done.
| |
54 | |
28 private: | 55 private: |
29 // KeyedService: | 56 // KeyedService: |
30 void Shutdown() override; | 57 void Shutdown() override; |
31 | 58 |
32 // content_settings::Observer: | 59 // content_settings::Observer: |
33 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 60 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
34 const ContentSettingsPattern& secondary_pattern, | 61 const ContentSettingsPattern& secondary_pattern, |
35 ContentSettingsType content_type, | 62 ContentSettingsType content_type, |
36 std::string resource_identifier) override; | 63 std::string resource_identifier) override; |
37 | 64 |
65 std::unique_ptr<base::DictionaryValue> GetWebsiteSetting( | |
66 const GURL& url) const; | |
67 void SetWebsiteSetting(const GURL& url, | |
68 std::unique_ptr<base::DictionaryValue> dict); | |
69 | |
38 HostContentSettingsMap* settings_map_; | 70 HostContentSettingsMap* settings_map_; |
39 | 71 |
72 // A clock is injected into this class so tests can set arbitrary timestamps | |
73 // in website settings. | |
74 std::unique_ptr<base::Clock> clock_; | |
75 | |
76 // Used internally so the class ignores changes to the settings that are not | |
77 // user initiated. | |
78 bool ignore_settings_changes_ = false; | |
79 | |
80 const bool should_use_smart_ui_ = false; | |
81 | |
40 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsManager); | 82 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsManager); |
41 }; | 83 }; |
42 | 84 |
43 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS _MANAGER_H_ | 85 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_SUBRESOURCE_FILTER_CONTENT_SETTINGS _MANAGER_H_ |
OLD | NEW |