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