This source file includes following definitions.
- FullPermission
- GrantFullAccessPermission
- GrantAccessPermission
- HasAccessPermission
- RevokePermissions
#include "chrome/browser/chromeos/fileapi/file_access_permissions.h"
#include "base/logging.h"
namespace chromeos {
namespace {
base::FilePath FullPermission() { return base::FilePath(); }
}
FileAccessPermissions::FileAccessPermissions() {}
FileAccessPermissions::~FileAccessPermissions() {}
void FileAccessPermissions::GrantFullAccessPermission(
const std::string& extension_id) {
base::AutoLock locker(lock_);
path_map_[extension_id].insert(FullPermission());
}
void FileAccessPermissions::GrantAccessPermission(
const std::string& extension_id, const base::FilePath& path) {
DCHECK(!path.empty());
base::AutoLock locker(lock_);
path_map_[extension_id].insert(path);
}
bool FileAccessPermissions::HasAccessPermission(
const std::string& extension_id, const base::FilePath& path) const {
base::AutoLock locker(lock_);
PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id);
if (path_map_iter == path_map_.end())
return false;
const PathSet& path_set = path_map_iter->second;
if (path_set.find(FullPermission()) != path_set.end())
return true;
base::FilePath current_path = path.StripTrailingSeparators();
base::FilePath last_path;
while (current_path != last_path) {
if (path_set.find(current_path) != path_set.end())
return true;
last_path = current_path;
current_path = current_path.DirName();
}
return false;
}
void FileAccessPermissions::RevokePermissions(
const std::string& extension_id) {
base::AutoLock locker(lock_);
path_map_.erase(extension_id);
}
}