Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 5 | #include "chrome/browser/ash/fileapi/file_access_permissions.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 6 | |
Hans Wennborg | 1790e6b | 2020-04-24 19:10:33 | [diff] [blame] | 7 | #include "base/check.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 8 | |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 9 | namespace ash { |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 10 | |
Sorin Jianu | 091a41a | 2024-12-03 00:51:44 | [diff] [blame] | 11 | FileAccessPermissions::FileAccessPermissions() = default; |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 12 | |
Sorin Jianu | 091a41a | 2024-12-03 00:51:44 | [diff] [blame] | 13 | FileAccessPermissions::~FileAccessPermissions() = default; |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 14 | |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 15 | void FileAccessPermissions::GrantAccessPermission(const url::Origin& origin, |
Bo Majewski | c0e8a98 | 2021-02-24 03:57:21 | [diff] [blame] | 16 | const base::FilePath& path) { |
[email protected] | c392aa5 | 2014-01-30 06:25:12 | [diff] [blame] | 17 | DCHECK(!path.empty()); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 18 | base::AutoLock locker(lock_); |
Bo Majewski | c0e8a98 | 2021-02-24 03:57:21 | [diff] [blame] | 19 | path_map_[origin].insert(path); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 20 | } |
21 | |||||
22 | bool FileAccessPermissions::HasAccessPermission( | ||||
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 23 | const url::Origin& origin, |
Bo Majewski | c0e8a98 | 2021-02-24 03:57:21 | [diff] [blame] | 24 | const base::FilePath& path) const { |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 25 | base::AutoLock locker(lock_); |
Bo Majewski | c0e8a98 | 2021-02-24 03:57:21 | [diff] [blame] | 26 | PathAccessMap::const_iterator path_map_iter = path_map_.find(origin); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 27 | if (path_map_iter == path_map_.end()) |
28 | return false; | ||||
[email protected] | c392aa5 | 2014-01-30 06:25:12 | [diff] [blame] | 29 | const PathSet& path_set = path_map_iter->second; |
30 | |||||
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 31 | // Check this file and walk up its directory tree to find if this extension |
32 | // has access to it. | ||||
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 33 | base::FilePath current_path = path.StripTrailingSeparators(); |
34 | base::FilePath last_path; | ||||
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 35 | while (current_path != last_path) { |
[email protected] | c392aa5 | 2014-01-30 06:25:12 | [diff] [blame] | 36 | if (path_set.find(current_path) != path_set.end()) |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 37 | return true; |
38 | last_path = current_path; | ||||
39 | current_path = current_path.DirName(); | ||||
40 | } | ||||
41 | return false; | ||||
42 | } | ||||
43 | |||||
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 44 | void FileAccessPermissions::RevokePermissions(const url::Origin& origin) { |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 45 | base::AutoLock locker(lock_); |
Bo Majewski | 762d913a | 2021-06-30 03:54:25 | [diff] [blame] | 46 | path_map_.erase(origin); |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 47 | } |
48 | |||||
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 49 | } // namespace ash |