blob: aacf7524d1b6de9442a918df2dea64049ca54fab [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_
#define CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_
#include <set>
#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "url/origin.h"
namespace chromeos {
// In a thread safe manner maintains the set of paths allowed to access for
// each extension.
class FileAccessPermissions {
public:
FileAccessPermissions();
virtual ~FileAccessPermissions();
// Grants |origin| access to |path|.
void GrantAccessPermission(const url::Origin& origin,
const base::FilePath& path);
// Checks whether |origin| has permission to access to |path|.
bool HasAccessPermission(const url::Origin& origin,
const base::FilePath& path) const;
// Revokes all file permissions for |origin|.
void RevokePermissions(const url::Origin& origin);
private:
typedef std::set<base::FilePath> PathSet;
typedef base::flat_map<url::Origin, PathSet> PathAccessMap;
mutable base::Lock lock_; // Synchronize all access to path_map_.
PathAccessMap path_map_;
DISALLOW_COPY_AND_ASSIGN(FileAccessPermissions);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILEAPI_FILE_ACCESS_PERMISSIONS_H_