Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/chromeos/fileapi/file_access_permissions.cc

Issue 148233008: Grant Files.app access for mount points added after its launch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/chromeos/fileapi/file_access_permissions.h" 5 #include "chrome/browser/chromeos/fileapi/file_access_permissions.h"
6 6
7 #include "base/command_line.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 8
10 namespace chromeos { 9 namespace chromeos {
11 10
11 namespace {
12
13 // Empty path is prefix of any other paths, hence it represents full permission.
14 base::FilePath FullPermission() { return base::FilePath(); }
15
16 } // namespace
17
12 FileAccessPermissions::FileAccessPermissions() {} 18 FileAccessPermissions::FileAccessPermissions() {}
13 19
14 FileAccessPermissions::~FileAccessPermissions() {} 20 FileAccessPermissions::~FileAccessPermissions() {}
15 21
22 void FileAccessPermissions::GrantFullAccessPermission(
23 const std::string& extension_id) {
24 base::AutoLock locker(lock_);
25 path_map_[extension_id].insert(FullPermission());
26 }
16 27
17 void FileAccessPermissions::GrantAccessPermission( 28 void FileAccessPermissions::GrantAccessPermission(
18 const std::string& extension_id, const base::FilePath& path) { 29 const std::string& extension_id, const base::FilePath& path) {
hashimoto 2014/01/28 10:55:13 nit: How about having "if" or DCHECK to verify pat
kinaba 2014/01/28 23:59:49 Done.
19 base::AutoLock locker(lock_); 30 base::AutoLock locker(lock_);
20 PathAccessMap::iterator path_map_iter = path_map_.find(extension_id); 31 path_map_[extension_id].insert(path);
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 } 32 }
31 33
32 bool FileAccessPermissions::HasAccessPermission( 34 bool FileAccessPermissions::HasAccessPermission(
33 const std::string& extension_id, const base::FilePath& path) const { 35 const std::string& extension_id, const base::FilePath& path) const {
34 base::AutoLock locker(lock_); 36 base::AutoLock locker(lock_);
35 PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id); 37 PathAccessMap::const_iterator path_map_iter = path_map_.find(extension_id);
36 if (path_map_iter == path_map_.end()) 38 if (path_map_iter == path_map_.end())
37 return false; 39 return false;
40 const PathSet& path_set = path_map_iter->second;
41
42 if (path_set.find(FullPermission()) != path_set.end())
43 return true;
38 44
39 // Check this file and walk up its directory tree to find if this extension 45 // Check this file and walk up its directory tree to find if this extension
40 // has access to it. 46 // has access to it.
41 base::FilePath current_path = path.StripTrailingSeparators(); 47 base::FilePath current_path = path.StripTrailingSeparators();
42 base::FilePath last_path; 48 base::FilePath last_path;
43 while (current_path != last_path) { 49 while (current_path != last_path) {
44 if (path_map_iter->second.find(current_path) != path_map_iter->second.end()) 50 if (path_set.find(current_path) != path_set.end())
45 return true; 51 return true;
46 last_path = current_path; 52 last_path = current_path;
47 current_path = current_path.DirName(); 53 current_path = current_path.DirName();
48 } 54 }
49 return false; 55 return false;
50 } 56 }
51 57
52 void FileAccessPermissions::RevokePermissions( 58 void FileAccessPermissions::RevokePermissions(
53 const std::string& extension_id) { 59 const std::string& extension_id) {
54 base::AutoLock locker(lock_); 60 base::AutoLock locker(lock_);
55 path_map_.erase(extension_id); 61 path_map_.erase(extension_id);
56 } 62 }
57 63
58 } // namespace chromeos 64 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698