Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / components / content_settings / core / browser / content_settings_default_provider.h
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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/prefs/pref_change_registrar.h"
15 #include "base/synchronization/lock.h"
16 #include "components/content_settings/core/browser/content_settings_observable_provider.h"
17
18 class PrefService;
19
20 namespace user_prefs {
21 class PrefRegistrySyncable;
22 }
23
24 namespace content_settings {
25
26 // Provider that provides default content settings based on
27 // user prefs. If no default values are set by the user we use the hard coded
28 // default values.
29 class DefaultProvider : public ObservableProvider {
30  public:
31   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
32
33   DefaultProvider(PrefService* prefs,
34                   bool incognito);
35   ~DefaultProvider() override;
36
37   // ProviderInterface implementations.
38   RuleIterator* GetRuleIterator(ContentSettingsType content_type,
39                                 const ResourceIdentifier& resource_identifier,
40                                 bool incognito) const override;
41
42   bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
43                          const ContentSettingsPattern& secondary_pattern,
44                          ContentSettingsType content_type,
45                          const ResourceIdentifier& resource_identifier,
46                          base::Value* value) override;
47
48   void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
49
50   void ShutdownOnUIThread() override;
51
52  private:
53   // Sets the fields of |settings| based on the values in |dictionary|.
54   void GetSettingsFromDictionary(const base::DictionaryValue* dictionary);
55
56   // Forces the default settings to be explicitly set instead of themselves
57   // being CONTENT_SETTING_DEFAULT.
58   void ForceDefaultsToBeExplicit();
59
60   // Reads the default settings from the preferences service. If |overwrite| is
61   // true and the preference is missing, the local copy will be cleared as well.
62   void ReadDefaultSettings(bool overwrite);
63
64   // Called on prefs change.
65   void OnPreferenceChanged(const std::string& pref_name);
66
67   typedef linked_ptr<base::Value> ValuePtr;
68   typedef std::map<ContentSettingsType, ValuePtr> ValueMap;
69   // Copies of the pref data, so that we can read it on the IO thread.
70   ValueMap default_settings_;
71
72   PrefService* prefs_;
73
74   // Whether this settings map is for an Incognito session.
75   bool is_incognito_;
76
77   // Used around accesses to the |default_content_settings_| object to guarantee
78   // thread safety.
79   mutable base::Lock lock_;
80
81   PrefChangeRegistrar pref_change_registrar_;
82
83   // Whether we are currently updating preferences, this is used to ignore
84   // notifications from the preferences service that we triggered ourself.
85   bool updating_preferences_;
86
87   DISALLOW_COPY_AND_ASSIGN(DefaultProvider);
88 };
89
90 }  // namespace content_settings
91
92 #endif  // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_