Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / preference / preference_api.h
index b924126..0f95a9b 100644 (file)
@@ -7,12 +7,13 @@
 
 #include <string>
 
+#include "base/memory/ref_counted.h"
 #include "base/prefs/pref_change_registrar.h"
 #include "chrome/browser/extensions/api/content_settings/content_settings_store.h"
-#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
 #include "chrome/browser/extensions/chrome_extension_function.h"
-#include "chrome/browser/extensions/event_router.h"
 #include "content/public/browser/notification_observer.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
+#include "extensions/browser/event_router.h"
 #include "extensions/browser/extension_prefs_scope.h"
 
 class ExtensionPrefValueMap;
@@ -86,58 +87,47 @@ class PreferenceAPIBase {
   // Virtual for testing.
   virtual ExtensionPrefs* extension_prefs() = 0;
   virtual ExtensionPrefValueMap* extension_pref_value_map() = 0;
+  virtual scoped_refptr<ContentSettingsStore> content_settings_store() = 0;
 };
 
 class PreferenceAPI : public PreferenceAPIBase,
-                      public ProfileKeyedAPI,
+                      public BrowserContextKeyedAPI,
                       public EventRouter::Observer,
                       public ContentSettingsStore::Observer {
  public:
-  explicit PreferenceAPI(Profile* profile);
-  virtual ~PreferenceAPI();
+  explicit PreferenceAPI(content::BrowserContext* context);
+  ~PreferenceAPI() override;
 
-  // BrowserContextKeyedService implementation.
-  virtual void Shutdown() OVERRIDE;
+  // KeyedService implementation.
+  void Shutdown() override;
 
-  // ProfileKeyedAPI implementation.
-  static ProfileKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance();
+  // BrowserContextKeyedAPI implementation.
+  static BrowserContextKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance();
 
   // Convenience method to get the PreferenceAPI for a profile.
-  static PreferenceAPI* Get(Profile* profile);
+  static PreferenceAPI* Get(content::BrowserContext* context);
 
   // EventRouter::Observer implementation.
-  virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
-
-  // Loads the preferences controlled by the specified extension from their
-  // dictionary and sets them in the |value_map|.
-  static void LoadExtensionControlledPrefs(ExtensionPrefs* prefs,
-                                           ExtensionPrefValueMap* value_map,
-                                           const std::string& extension_id,
-                                           ExtensionPrefsScope scope);
-
-  // Store extension controlled preference values in the |value_map|,
-  // which then informs the subscribers (ExtensionPrefStores) about the winning
-  // values.
-  static void InitExtensionControlledPrefs(ExtensionPrefs* prefs,
-                                           ExtensionPrefValueMap* value_map);
+  void OnListenerAdded(const EventListenerInfo& details) override;
 
  private:
-  friend class ProfileKeyedAPIFactory<PreferenceAPI>;
+  friend class BrowserContextKeyedAPIFactory<PreferenceAPI>;
 
   // ContentSettingsStore::Observer implementation.
-  virtual void OnContentSettingChanged(const std::string& extension_id,
-                                       bool incognito) OVERRIDE;
+  void OnContentSettingChanged(const std::string& extension_id,
+                               bool incognito) override;
 
   // Clears incognito session-only content settings for all extensions.
   void ClearIncognitoSessionOnlyContentSettings();
 
   // PreferenceAPIBase implementation.
-  virtual ExtensionPrefs* extension_prefs() OVERRIDE;
-  virtual ExtensionPrefValueMap* extension_pref_value_map() OVERRIDE;
+  ExtensionPrefs* extension_prefs() override;
+  ExtensionPrefValueMap* extension_pref_value_map() override;
+  scoped_refptr<ContentSettingsStore> content_settings_store() override;
 
   Profile* profile_;
 
-  // ProfileKeyedAPI implementation.
+  // BrowserContextKeyedAPI implementation.
   static const char* service_name() {
     return "PreferenceAPI";
   }
@@ -177,7 +167,9 @@ class PrefTransformerInterface {
 // classes.
 class PreferenceFunction : public ChromeSyncExtensionFunction {
  protected:
-  virtual ~PreferenceFunction();
+  enum PermissionType { PERMISSION_TYPE_READ, PERMISSION_TYPE_WRITE };
+
+  ~PreferenceFunction() override;
 
   // Given an |extension_pref_key|, provides its |browser_pref_key| from the
   // static map in preference_api.cc. Returns true if the corresponding
@@ -185,6 +177,7 @@ class PreferenceFunction : public ChromeSyncExtensionFunction {
   // modify that pref. Sets |error_| if the extension doesn't have the needed
   // permission.
   bool ValidateBrowserPref(const std::string& extension_pref_key,
+                           PermissionType permission_type,
                            std::string* browser_pref_key);
 };
 
@@ -193,10 +186,10 @@ class GetPreferenceFunction : public PreferenceFunction {
   DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.get", TYPES_CHROMESETTING_GET)
 
  protected:
-  virtual ~GetPreferenceFunction();
+  ~GetPreferenceFunction() override;
 
   // ExtensionFunction:
-  virtual bool RunImpl() OVERRIDE;
+  bool RunSync() override;
 };
 
 class SetPreferenceFunction : public PreferenceFunction {
@@ -204,10 +197,10 @@ class SetPreferenceFunction : public PreferenceFunction {
   DECLARE_EXTENSION_FUNCTION("types.ChromeSetting.set", TYPES_CHROMESETTING_SET)
 
  protected:
-  virtual ~SetPreferenceFunction();
+  ~SetPreferenceFunction() override;
 
   // ExtensionFunction:
-  virtual bool RunImpl() OVERRIDE;
+  bool RunSync() override;
 };
 
 class ClearPreferenceFunction : public PreferenceFunction {
@@ -216,10 +209,10 @@ class ClearPreferenceFunction : public PreferenceFunction {
                              TYPES_CHROMESETTING_CLEAR)
 
  protected:
-  virtual ~ClearPreferenceFunction();
+  ~ClearPreferenceFunction() override;
 
   // ExtensionFunction:
-  virtual bool RunImpl() OVERRIDE;
+  bool RunSync() override;
 };
 
 }  // namespace extensions