When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / webkit / chromeos / fileapi / file_access_permissions.cc
blob99b058160625e6e59054982bdce1b1ad30b56c76
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"
10 namespace chromeos {
12 FileAccessPermissions::FileAccessPermissions() {}
14 FileAccessPermissions::~FileAccessPermissions() {}
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);
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;
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();
49 return false;
52 void FileAccessPermissions::RevokePermissions(
53 const std::string& extension_id) {
54 base::AutoLock locker(lock_);
55 path_map_.erase(extension_id);