Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_special_storage_policy.h
blobaa04bd6752c902217357ed04c72a4b87e7749691
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_
8 #include <map>
9 #include <string>
11 #include "base/synchronization/lock.h"
12 #include "extensions/common/extension_set.h"
13 #include "url/gurl.h"
14 #include "webkit/browser/quota/special_storage_policy.h"
16 class CookieSettings;
18 namespace extensions {
19 class Extension;
22 // Special rights are granted to 'extensions' and 'applications'. The
23 // storage subsystems and the browsing data remover query this interface
24 // to determine which origins have these rights.
25 class ExtensionSpecialStoragePolicy : public quota::SpecialStoragePolicy {
26 public:
27 explicit ExtensionSpecialStoragePolicy(CookieSettings* cookie_settings);
29 // quota::SpecialStoragePolicy methods used by storage subsystems and the
30 // browsing data remover. These methods are safe to call on any thread.
31 virtual bool IsStorageProtected(const GURL& origin) OVERRIDE;
32 virtual bool IsStorageUnlimited(const GURL& origin) OVERRIDE;
33 virtual bool IsStorageSessionOnly(const GURL& origin) OVERRIDE;
34 virtual bool CanQueryDiskSize(const GURL& origin) OVERRIDE;
35 virtual bool IsFileHandler(const std::string& extension_id) OVERRIDE;
36 virtual bool HasIsolatedStorage(const GURL& origin) OVERRIDE;
37 virtual bool HasSessionOnlyOrigins() OVERRIDE;
39 // Methods used by the ExtensionService to populate this class.
40 void GrantRightsForExtension(const extensions::Extension* extension);
41 void RevokeRightsForExtension(const extensions::Extension* extension);
42 void RevokeRightsForAllExtensions();
44 // Decides whether the storage for |extension|'s web extent needs protection.
45 bool NeedsProtection(const extensions::Extension* extension);
47 // Returns the set of extensions protecting this origin. The caller does not
48 // take ownership of the return value.
49 const extensions::ExtensionSet* ExtensionsProtectingOrigin(
50 const GURL& origin);
52 protected:
53 virtual ~ExtensionSpecialStoragePolicy();
55 private:
56 class SpecialCollection {
57 public:
58 SpecialCollection();
59 ~SpecialCollection();
61 bool Contains(const GURL& origin);
62 const extensions::ExtensionSet* ExtensionsContaining(const GURL& origin);
63 bool ContainsExtension(const std::string& extension_id);
64 bool Add(const extensions::Extension* extension);
65 bool Remove(const extensions::Extension* extension);
66 void Clear();
68 private:
69 typedef std::map<GURL, extensions::ExtensionSet*> CachedResults;
71 void ClearCache();
73 extensions::ExtensionSet extensions_;
74 CachedResults cached_results_;
77 void NotifyGranted(const GURL& origin, int change_flags);
78 void NotifyRevoked(const GURL& origin, int change_flags);
79 void NotifyCleared();
81 base::Lock lock_; // Synchronize all access to the collections.
82 SpecialCollection protected_apps_;
83 SpecialCollection installed_apps_;
84 SpecialCollection unlimited_extensions_;
85 SpecialCollection file_handler_extensions_;
86 SpecialCollection isolated_extensions_;
87 scoped_refptr<CookieSettings> cookie_settings_;
90 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_