| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "webkit/quota/special_storage_policy.h" | 14 #include "webkit/quota/special_storage_policy.h" |
| 15 | 15 |
| 16 class CookieSettings; | 16 class CookieSettings; |
| 17 |
| 18 namespace extensions { |
| 17 class Extension; | 19 class Extension; |
| 20 } |
| 18 | 21 |
| 19 // Special rights are granted to 'extensions' and 'applications'. The | 22 // Special rights are granted to 'extensions' and 'applications'. The |
| 20 // storage subsystems and the browsing data remover query this interface | 23 // storage subsystems and the browsing data remover query this interface |
| 21 // to determine which origins have these rights. | 24 // to determine which origins have these rights. |
| 22 class ExtensionSpecialStoragePolicy : public quota::SpecialStoragePolicy { | 25 class ExtensionSpecialStoragePolicy : public quota::SpecialStoragePolicy { |
| 23 public: | 26 public: |
| 24 explicit ExtensionSpecialStoragePolicy(CookieSettings* cookie_settings); | 27 explicit ExtensionSpecialStoragePolicy(CookieSettings* cookie_settings); |
| 25 | 28 |
| 26 // quota::SpecialStoragePolicy methods used by storage subsystems and the | 29 // quota::SpecialStoragePolicy methods used by storage subsystems and the |
| 27 // browsing data remover. These methods are safe to call on any thread. | 30 // browsing data remover. These methods are safe to call on any thread. |
| 28 virtual bool IsStorageProtected(const GURL& origin) OVERRIDE; | 31 virtual bool IsStorageProtected(const GURL& origin) OVERRIDE; |
| 29 virtual bool IsStorageUnlimited(const GURL& origin) OVERRIDE; | 32 virtual bool IsStorageUnlimited(const GURL& origin) OVERRIDE; |
| 30 virtual bool IsStorageSessionOnly(const GURL& origin) OVERRIDE; | 33 virtual bool IsStorageSessionOnly(const GURL& origin) OVERRIDE; |
| 31 virtual bool IsFileHandler(const std::string& extension_id) OVERRIDE; | 34 virtual bool IsFileHandler(const std::string& extension_id) OVERRIDE; |
| 32 virtual bool HasSessionOnlyOrigins() OVERRIDE; | 35 virtual bool HasSessionOnlyOrigins() OVERRIDE; |
| 33 | 36 |
| 34 // Methods used by the ExtensionService to populate this class. | 37 // Methods used by the ExtensionService to populate this class. |
| 35 void GrantRightsForExtension(const Extension* extension); | 38 void GrantRightsForExtension(const extensions::Extension* extension); |
| 36 void RevokeRightsForExtension(const Extension* extension); | 39 void RevokeRightsForExtension(const extensions::Extension* extension); |
| 37 void RevokeRightsForAllExtensions(); | 40 void RevokeRightsForAllExtensions(); |
| 38 | 41 |
| 39 protected: | 42 protected: |
| 40 virtual ~ExtensionSpecialStoragePolicy(); | 43 virtual ~ExtensionSpecialStoragePolicy(); |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 class SpecialCollection { | 46 class SpecialCollection { |
| 44 public: | 47 public: |
| 45 SpecialCollection(); | 48 SpecialCollection(); |
| 46 ~SpecialCollection(); | 49 ~SpecialCollection(); |
| 47 | 50 |
| 48 bool Contains(const GURL& origin); | 51 bool Contains(const GURL& origin); |
| 49 bool ContainsExtension(const std::string& extension_id); | 52 bool ContainsExtension(const std::string& extension_id); |
| 50 void Add(const Extension* extension); | 53 void Add(const extensions::Extension* extension); |
| 51 void Remove(const Extension* extension); | 54 void Remove(const extensions::Extension* extension); |
| 52 void Clear(); | 55 void Clear(); |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 typedef std::map<GURL, bool> CachedResults; | 58 typedef std::map<GURL, bool> CachedResults; |
| 56 typedef std::map<std::string, scoped_refptr<const Extension> > Extensions; | 59 typedef std::map<std::string, scoped_refptr<const extensions::Extension> > |
| 60 Extensions; |
| 57 Extensions extensions_; | 61 Extensions extensions_; |
| 58 CachedResults cached_results_; | 62 CachedResults cached_results_; |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 void NotifyChanged(); | 65 void NotifyChanged(); |
| 62 | 66 |
| 63 base::Lock lock_; // Synchronize all access to the collections. | 67 base::Lock lock_; // Synchronize all access to the collections. |
| 64 SpecialCollection protected_apps_; | 68 SpecialCollection protected_apps_; |
| 65 SpecialCollection unlimited_extensions_; | 69 SpecialCollection unlimited_extensions_; |
| 66 SpecialCollection file_handler_extensions_; | 70 SpecialCollection file_handler_extensions_; |
| 67 scoped_refptr<CookieSettings> cookie_settings_; | 71 scoped_refptr<CookieSettings> cookie_settings_; |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_ |
| OLD | NEW |