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