Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / extension_special_storage_policy.h
blobedaa543804412849d063217d59af6596844de006
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 "storage/browser/quota/special_storage_policy.h"
14 #include "url/gurl.h"
16 class CookieSettings;
18 namespace content {
19 class BrowserContext;
22 namespace extensions {
23 class Extension;
26 // Special rights are granted to 'extensions' and 'applications'. The
27 // storage subsystems and the browsing data remover query this interface
28 // to determine which origins have these rights.
29 class ExtensionSpecialStoragePolicy : public storage::SpecialStoragePolicy {
30 public:
31 explicit ExtensionSpecialStoragePolicy(CookieSettings* cookie_settings);
33 // storage::SpecialStoragePolicy methods used by storage subsystems and the
34 // browsing data remover. These methods are safe to call on any thread.
35 bool IsStorageProtected(const GURL& origin) override;
36 bool IsStorageUnlimited(const GURL& origin) override;
37 bool IsStorageSessionOnly(const GURL& origin) override;
38 bool CanQueryDiskSize(const GURL& origin) override;
39 bool HasIsolatedStorage(const GURL& origin) override;
40 bool HasSessionOnlyOrigins() override;
42 // Methods used by the ExtensionService to populate this class.
43 void GrantRightsForExtension(const extensions::Extension* extension,
44 content::BrowserContext* browser_context);
45 void RevokeRightsForExtension(const extensions::Extension* extension);
46 void RevokeRightsForAllExtensions();
48 // Decides whether the storage for |extension|'s web extent needs protection.
49 bool NeedsProtection(const extensions::Extension* extension);
51 // Returns the set of extensions protecting this origin. The caller does not
52 // take ownership of the return value.
53 const extensions::ExtensionSet* ExtensionsProtectingOrigin(
54 const GURL& origin);
56 protected:
57 ~ExtensionSpecialStoragePolicy() override;
59 private:
60 class SpecialCollection {
61 public:
62 SpecialCollection();
63 ~SpecialCollection();
65 bool Contains(const GURL& origin);
66 bool GrantsCapabilitiesTo(const GURL& origin);
67 const extensions::ExtensionSet* ExtensionsContaining(const GURL& origin);
68 bool ContainsExtension(const std::string& extension_id);
69 bool Add(const extensions::Extension* extension);
70 bool Remove(const extensions::Extension* extension);
71 void Clear();
73 private:
74 typedef std::map<GURL, extensions::ExtensionSet*> CachedResults;
76 void ClearCache();
78 extensions::ExtensionSet extensions_;
79 CachedResults cached_results_;
82 void NotifyGranted(const GURL& origin, int change_flags);
83 void NotifyRevoked(const GURL& origin, int change_flags);
84 void NotifyCleared();
86 base::Lock lock_; // Synchronize all access to the collections.
87 SpecialCollection protected_apps_;
88 SpecialCollection installed_apps_;
89 SpecialCollection unlimited_extensions_;
90 SpecialCollection file_handler_extensions_;
91 SpecialCollection isolated_extensions_;
92 SpecialCollection content_capabilities_unlimited_extensions_;
93 scoped_refptr<CookieSettings> cookie_settings_;
96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SPECIAL_STORAGE_POLICY_H_