Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / fileapi / file_access_permissions.cc
blobfee041a16d9661b11d52901445b831b772802cfb
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.
5 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h"
7 #include "base/logging.h"
9 namespace chromeos {
11 FileAccessPermissions::FileAccessPermissions() {}
13 FileAccessPermissions::~FileAccessPermissions() {}
15 void FileAccessPermissions::GrantAccessPermission(
16 const std::string& extension_id, const base::FilePath& path) {
17 DCHECK(!path.empty());
18 base::AutoLock locker(lock_);
19 path_map_[extension_id].insert(path);
22 bool FileAccessPermissions::HasAccessPermission(
23 const std::string& extension_id, const base::FilePath& path) const {
24 base::AutoLock locker(lock_);
25 PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id);
26 if (path_map_iter == path_map_.end())
27 return false;
28 const PathSet& path_set = path_map_iter->second;
30 // Check this file and walk up its directory tree to find if this extension
31 // has access to it.
32 base::FilePath current_path = path.StripTrailingSeparators();
33 base::FilePath last_path;
34 while (current_path != last_path) {
35 if (path_set.find(current_path) != path_set.end())
36 return true;
37 last_path = current_path;
38 current_path = current_path.DirName();
40 return false;
43 void FileAccessPermissions::RevokePermissions(
44 const std::string& extension_id) {
45 base::AutoLock locker(lock_);
46 path_map_.erase(extension_id);
49 } // namespace chromeos