OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #include "webkit/browser/chromeos/fileapi/file_access_permissions.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/logging.h" | |
9 | |
10 namespace chromeos { | |
11 | |
12 FileAccessPermissions::FileAccessPermissions() {} | |
13 | |
14 FileAccessPermissions::~FileAccessPermissions() {} | |
15 | |
16 | |
17 void FileAccessPermissions::GrantAccessPermission( | |
18 const std::string& extension_id, const base::FilePath& path) { | |
19 base::AutoLock locker(lock_); | |
20 PathAccessMap::iterator path_map_iter = path_map_.find(extension_id); | |
21 if (path_map_iter == path_map_.end()) { | |
22 PathSet path_set; | |
23 path_set.insert(path); | |
24 path_map_.insert(PathAccessMap::value_type(extension_id, path_set)); | |
25 } else { | |
26 if (path_map_iter->second.find(path) != path_map_iter->second.end()) | |
27 return; | |
28 path_map_iter->second.insert(path); | |
29 } | |
30 } | |
31 | |
32 bool FileAccessPermissions::HasAccessPermission( | |
33 const std::string& extension_id, const base::FilePath& path) const { | |
34 base::AutoLock locker(lock_); | |
35 PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id); | |
36 if (path_map_iter == path_map_.end()) | |
37 return false; | |
38 | |
39 // Check this file and walk up its directory tree to find if this extension | |
40 // has access to it. | |
41 base::FilePath current_path = path.StripTrailingSeparators(); | |
42 base::FilePath last_path; | |
43 while (current_path != last_path) { | |
44 if (path_map_iter->second.find(current_path) != path_map_iter->second.end()) | |
45 return true; | |
46 last_path = current_path; | |
47 current_path = current_path.DirName(); | |
48 } | |
49 return false; | |
50 } | |
51 | |
52 void FileAccessPermissions::RevokePermissions( | |
53 const std::string& extension_id) { | |
54 base::AutoLock locker(lock_); | |
55 path_map_.erase(extension_id); | |
56 } | |
57 | |
58 } | |
OLD | NEW |