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.
5 #include "webkit/chromeos/fileapi/file_access_permissions.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
12 FileAccessPermissions::FileAccessPermissions() {}
14 FileAccessPermissions::~FileAccessPermissions() {}
17 void FileAccessPermissions::GrantAccessPermission(
18 const std::string
& extension_id
, const 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()) {
23 path_set
.insert(path
);
24 path_map_
.insert(PathAccessMap::value_type(extension_id
, path_set
));
26 if (path_map_iter
->second
.find(path
) != path_map_iter
->second
.end())
28 path_map_iter
->second
.insert(path
);
32 bool FileAccessPermissions::HasAccessPermission(
33 const std::string
& extension_id
, const FilePath
& path
) {
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())
39 // Check this file and walk up its directory tree to find if this extension
41 FilePath current_path
= path
.StripTrailingSeparators();
43 while (current_path
!= last_path
) {
44 if (path_map_iter
->second
.find(current_path
) != path_map_iter
->second
.end())
46 last_path
= current_path
;
47 current_path
= current_path
.DirName();
52 void FileAccessPermissions::RevokePermissions(
53 const std::string
& extension_id
) {
54 base::AutoLock
locker(lock_
);
55 path_map_
.erase(extension_id
);