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

Unified Diff: chrome/common/extensions/permissions/permissions_info.cc

Issue 10675007: Move each permission classes to its own files in extensions/permissions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/permissions/permissions_info.cc
diff --git a/chrome/common/extensions/permissions/permissions_info.cc b/chrome/common/extensions/permissions/permissions_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5e10c0db591cd8cb4d5466412376180cc2a51a2f
--- /dev/null
+++ b/chrome/common/extensions/permissions/permissions_info.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/permissions/permissions_info.h"
+
+namespace extensions {
+
+//
+// PermissionsInfo
miket_OOO 2012/06/26 23:23:44 This comment is nonstandard. Please remove.
Peng 2012/06/26 23:32:35 Done.
+//
+
+// static
+PermissionsInfo* PermissionsInfo::GetInstance() {
+ return Singleton<PermissionsInfo>::get();
+}
+
+APIPermission* PermissionsInfo::GetByID(
+ APIPermission::ID id) {
+ IDMap::iterator i = id_map_.find(id);
+ return (i == id_map_.end()) ? NULL : i->second;
+}
+
+APIPermission* PermissionsInfo::GetByName(
+ const std::string& name) {
+ NameMap::iterator i = name_map_.find(name);
+ return (i == name_map_.end()) ? NULL : i->second;
+}
+
+APIPermissionSet PermissionsInfo::GetAll() {
+ APIPermissionSet permissions;
+ for (IDMap::const_iterator i = id_map_.begin(); i != id_map_.end(); ++i)
+ permissions.insert(i->second->id());
+ return permissions;
+}
+
+APIPermissionSet PermissionsInfo::GetAllByName(
+ const std::set<std::string>& permission_names) {
+ APIPermissionSet permissions;
+ for (std::set<std::string>::const_iterator i = permission_names.begin();
+ i != permission_names.end(); ++i) {
+ APIPermission* permission = GetByName(*i);
+ if (permission)
+ permissions.insert(permission->id());
+ }
+ return permissions;
+}
+
+PermissionsInfo::~PermissionsInfo() {
+ for (IDMap::iterator i = id_map_.begin(); i != id_map_.end(); ++i)
+ delete i->second;
+}
+
+PermissionsInfo::PermissionsInfo()
+ : hosted_app_permission_count_(0),
+ permission_count_(0) {
+ APIPermission::RegisterAllPermissions(this);
+}
+
+void PermissionsInfo::RegisterAlias(
+ const char* name,
+ const char* alias) {
+ DCHECK(name_map_.find(name) != name_map_.end());
+ DCHECK(name_map_.find(alias) == name_map_.end());
+ name_map_[alias] = name_map_[name];
+}
+
+APIPermission* PermissionsInfo::RegisterPermission(
+ APIPermission::ID id,
+ const char* name,
+ int l10n_message_id,
+ PermissionMessage::ID message_id,
+ int flags) {
+ DCHECK(id_map_.find(id) == id_map_.end());
+ DCHECK(name_map_.find(name) == name_map_.end());
+
+ APIPermission* permission = new APIPermission(
+ id, name, l10n_message_id, message_id, flags);
+
+ id_map_[id] = permission;
+ name_map_[name] = permission;
+
+ permission_count_++;
+
+ return permission;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698