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"
13 // Empty path is prefix of any other paths, hence it represents full permission.
14 base::FilePath
FullPermission() { return base::FilePath(); }
18 FileAccessPermissions::FileAccessPermissions() {}
20 FileAccessPermissions::~FileAccessPermissions() {}
22 void FileAccessPermissions::GrantFullAccessPermission(
23 const std::string
& extension_id
) {
24 base::AutoLock
locker(lock_
);
25 path_map_
[extension_id
].insert(FullPermission());
28 void FileAccessPermissions::GrantAccessPermission(
29 const std::string
& extension_id
, const base::FilePath
& path
) {
30 DCHECK(!path
.empty());
31 base::AutoLock
locker(lock_
);
32 path_map_
[extension_id
].insert(path
);
35 bool FileAccessPermissions::HasAccessPermission(
36 const std::string
& extension_id
, const base::FilePath
& path
) const {
37 base::AutoLock
locker(lock_
);
38 PathAccessMap::const_iterator path_map_iter
= path_map_
.find(extension_id
);
39 if (path_map_iter
== path_map_
.end())
41 const PathSet
& path_set
= path_map_iter
->second
;
43 if (path_set
.find(FullPermission()) != path_set
.end())
46 // Check this file and walk up its directory tree to find if this extension
48 base::FilePath current_path
= path
.StripTrailingSeparators();
49 base::FilePath last_path
;
50 while (current_path
!= last_path
) {
51 if (path_set
.find(current_path
) != path_set
.end())
53 last_path
= current_path
;
54 current_path
= current_path
.DirName();
59 void FileAccessPermissions::RevokePermissions(
60 const std::string
& extension_id
) {
61 base::AutoLock
locker(lock_
);
62 path_map_
.erase(extension_id
);
65 } // namespace chromeos