Home | History | Annotate | Download | only in fileapi
      1 // Copyright 2013 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_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_
      6 #define CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_
      7 
      8 #include <map>
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/basictypes.h"
     13 #include "base/files/file_path.h"
     14 #include "base/synchronization/lock.h"
     15 
     16 namespace chromeos {
     17 
     18 // In a thread safe manner maintains the set of paths allowed to access for
     19 // each extension.
     20 class FileAccessPermissions {
     21  public:
     22   FileAccessPermissions();
     23   virtual ~FileAccessPermissions();
     24 
     25   // Grants |extension_id| full access to all paths.
     26   void GrantFullAccessPermission(const std::string& extension_id);
     27   // Grants |extension_id| access to |path|.
     28   void GrantAccessPermission(const std::string& extension_id,
     29                              const base::FilePath& path);
     30   // Checks id |extension_id| has permission to access to |path|.
     31   bool HasAccessPermission(const std::string& extension_id,
     32                            const base::FilePath& path) const;
     33   // Revokes all file permissions for |extension_id|.
     34   void RevokePermissions(const std::string& extension_id);
     35 
     36  private:
     37   typedef std::set<base::FilePath> PathSet;
     38   typedef std::map<std::string, PathSet> PathAccessMap;
     39 
     40   mutable base::Lock lock_;  // Synchronize all access to path_map_.
     41   PathAccessMap path_map_;
     42 
     43   DISALLOW_COPY_AND_ASSIGN(FileAccessPermissions);
     44 };
     45 
     46 }  // namespace chromeos
     47 
     48 #endif  // CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_
     49