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