OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 6 |
| 7 namespace extensions { |
| 8 |
| 9 // static |
| 10 PermissionsInfo* PermissionsInfo::GetInstance() { |
| 11 return Singleton<PermissionsInfo>::get(); |
| 12 } |
| 13 |
| 14 APIPermission* PermissionsInfo::GetByID( |
| 15 APIPermission::ID id) { |
| 16 IDMap::iterator i = id_map_.find(id); |
| 17 return (i == id_map_.end()) ? NULL : i->second; |
| 18 } |
| 19 |
| 20 APIPermission* PermissionsInfo::GetByName( |
| 21 const std::string& name) { |
| 22 NameMap::iterator i = name_map_.find(name); |
| 23 return (i == name_map_.end()) ? NULL : i->second; |
| 24 } |
| 25 |
| 26 APIPermissionSet PermissionsInfo::GetAll() { |
| 27 APIPermissionSet permissions; |
| 28 for (IDMap::const_iterator i = id_map_.begin(); i != id_map_.end(); ++i) |
| 29 permissions.insert(i->second->id()); |
| 30 return permissions; |
| 31 } |
| 32 |
| 33 APIPermissionSet PermissionsInfo::GetAllByName( |
| 34 const std::set<std::string>& permission_names) { |
| 35 APIPermissionSet permissions; |
| 36 for (std::set<std::string>::const_iterator i = permission_names.begin(); |
| 37 i != permission_names.end(); ++i) { |
| 38 APIPermission* permission = GetByName(*i); |
| 39 if (permission) |
| 40 permissions.insert(permission->id()); |
| 41 } |
| 42 return permissions; |
| 43 } |
| 44 |
| 45 PermissionsInfo::~PermissionsInfo() { |
| 46 for (IDMap::iterator i = id_map_.begin(); i != id_map_.end(); ++i) |
| 47 delete i->second; |
| 48 } |
| 49 |
| 50 PermissionsInfo::PermissionsInfo() |
| 51 : hosted_app_permission_count_(0), |
| 52 permission_count_(0) { |
| 53 APIPermission::RegisterAllPermissions(this); |
| 54 } |
| 55 |
| 56 void PermissionsInfo::RegisterAlias( |
| 57 const char* name, |
| 58 const char* alias) { |
| 59 DCHECK(name_map_.find(name) != name_map_.end()); |
| 60 DCHECK(name_map_.find(alias) == name_map_.end()); |
| 61 name_map_[alias] = name_map_[name]; |
| 62 } |
| 63 |
| 64 APIPermission* PermissionsInfo::RegisterPermission( |
| 65 APIPermission::ID id, |
| 66 const char* name, |
| 67 int l10n_message_id, |
| 68 PermissionMessage::ID message_id, |
| 69 int flags) { |
| 70 DCHECK(id_map_.find(id) == id_map_.end()); |
| 71 DCHECK(name_map_.find(name) == name_map_.end()); |
| 72 |
| 73 APIPermission* permission = new APIPermission( |
| 74 id, name, l10n_message_id, message_id, flags); |
| 75 |
| 76 id_map_[id] = permission; |
| 77 name_map_[name] = permission; |
| 78 |
| 79 permission_count_++; |
| 80 |
| 81 return permission; |
| 82 } |
| 83 |
| 84 } // namespace extensions |
OLD | NEW |