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

Side by Side Diff: chrome/browser/content_settings/content_settings_base_provider.h

Issue 6484035: Add a content_settings::BaseProvider for code that is shared by all content settings providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_CONTENT_SETTINGS_CONTENT_SETTINGS_BASE_PROVIDER_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_BASE_PROVIDER_H_
7 #pragma once
8
9 #include <map>
10 #include <string>
11 #include <utility>
12
13 #include "base/synchronization/lock.h"
14 #include "chrome/browser/content_settings/content_settings_provider.h"
15
16 namespace content_settings {
17
18 typedef std::pair<ContentSettingsType, std::string>
19 ContentSettingsTypeResourceIdentifierPair;
20 typedef std::map<ContentSettingsTypeResourceIdentifierPair, ContentSetting>
21 ResourceContentSettings;
22
23 struct ExtendedContentSettings {
24 ContentSettings content_settings;
25 ResourceContentSettings content_settings_for_resources;
26 };
27
28 // Map for ContentSettings.
29 typedef std::map<std::string, ExtendedContentSettings> HostContentSettings;
30
31 // BaseProvider is the abstract base class for all content-settings-provider
32 // classes.
33 class BaseProvider : public ProviderInterface {
34 public:
35 // Maps CONTENT_SETTING_ASK for the CONTENT_SETTINGS_TYPE_PLUGINS to
36 // CONTENT_SETTING_BLOCK if click-to-play is not enabled.
37 static ContentSetting ClickToPlayFixup(ContentSettingsType content_type,
38 ContentSetting setting);
39
40 explicit BaseProvider(bool is_otr)
41 : is_off_the_record_(is_otr) {
42 }
43 virtual ~BaseProvider() {}
44
45 // Initializes the Provider.
46 virtual void Init() = 0;
47
48 // ProviderInterface Implementation
49 virtual bool ContentSettingsTypeIsManaged(
50 ContentSettingsType content_type) = 0;
51
52 virtual ContentSetting GetContentSetting(
53 const GURL& requesting_url,
54 const GURL& embedding_url,
55 ContentSettingsType content_type,
56 const ResourceIdentifier& resource_identifier) const;
57
58 virtual void SetContentSetting(
59 const ContentSettingsPattern& requesting_pattern,
60 const ContentSettingsPattern& embedding_pattern,
61 ContentSettingsType content_type,
62 const ResourceIdentifier& resource_identifier,
63 ContentSetting content_setting) = 0;
64
65 virtual void GetAllContentSettingsRules(
66 ContentSettingsType content_type,
67 const ResourceIdentifier& resource_identifier,
68 Rules* content_setting_rules) const;
69
70 virtual void ClearAllContentSettingsRules(
71 ContentSettingsType content_type) = 0;
72
73 virtual void ResetToDefaults() = 0;
74
75 protected:
76 // Returns true if the |content_type| requires a resource identifier.
77 bool RequiresResourceIdentifier(
78 ContentSettingsType content_type) const;
79
80 // Returns true if the passed |settings| object contains only
81 // CONTENT_SETTING_DEFAULT values.
82 bool AllDefault(const ExtendedContentSettings& settings) const;
83
84 // TODO(markusheintz): LEGACY method. Will be removed in a future re-factoring
85 // step.
86 ContentSettings GetNonDefaultContentSettings(const GURL& url) const;
87
88 // Accessors
89 HostContentSettings* host_content_settings() {
90 return &host_content_settings_;
91 }
92
93 HostContentSettings* off_the_record_settings() {
94 return &off_the_record_settings_;
95 }
96
97 base::Lock& lock() const {
98 return lock_;
99 }
100
101 bool is_off_the_record() const {
102 return is_off_the_record_;
103 }
104
105 private:
106 // Copies of the pref data, so that we can read it on threads other than the
107 // UI thread.
108 HostContentSettings host_content_settings_;
109
110 // Whether this settings map is for an OTR session.
111 bool is_off_the_record_;
112
113 // Differences to the preference-stored host content settings for
114 // off-the-record settings.
115 HostContentSettings off_the_record_settings_;
116
117 // Used around accesses to the content_settings_ object to guarantee
118 // thread safety.
119 mutable base::Lock lock_;
120 };
121
122 } // namespace content_settings
123
124 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_BASE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698