Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / common / permissions / permissions_info.h
blob43d61b287eaa7765962ea81daac4e56aa08dc5e4
1 // Copyright 2013 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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/callback.h"
13 #include "base/lazy_instance.h"
14 #include "extensions/common/permissions/api_permission.h"
15 #include "extensions/common/permissions/api_permission_set.h"
16 #include "extensions/common/permissions/permissions_provider.h"
18 namespace extensions {
20 // A global object that holds the extension permission instances and provides
21 // methods for accessing them.
22 class PermissionsInfo {
23 public:
24 static PermissionsInfo* GetInstance();
26 // Initializes the permissions from the provider.
27 void AddProvider(const PermissionsProvider& provider);
29 // Returns the permission with the given |id|, and NULL if it doesn't exist.
30 const APIPermissionInfo* GetByID(APIPermission::ID id) const;
32 // Returns the permission with the given |name|, and NULL if none
33 // exists.
34 const APIPermissionInfo* GetByName(const std::string& name) const;
36 // Returns a set containing all valid api permission ids.
37 APIPermissionSet GetAll() const;
39 // Converts all the permission names in |permission_names| to permission ids.
40 APIPermissionSet GetAllByName(
41 const std::set<std::string>& permission_names) const;
43 // Checks if any permissions have names that start with |name| followed by a
44 // period.
45 bool HasChildPermissions(const std::string& name) const;
47 // Gets the total number of API permissions.
48 size_t get_permission_count() const { return permission_count_; }
50 private:
51 friend struct base::DefaultLazyInstanceTraits<PermissionsInfo>;
53 PermissionsInfo();
55 virtual ~PermissionsInfo();
57 // Registers an |alias| for a given permission |name|.
58 void RegisterAlias(const char* name, const char* alias);
60 // Registers a permission with the specified attributes and flags.
61 void RegisterPermission(APIPermissionInfo* permission);
63 // Maps permission ids to permissions.
64 typedef std::map<APIPermission::ID, APIPermissionInfo*> IDMap;
66 // Maps names and aliases to permissions.
67 typedef std::map<std::string, APIPermissionInfo*> NameMap;
69 IDMap id_map_;
70 NameMap name_map_;
72 size_t permission_count_;
74 DISALLOW_COPY_AND_ASSIGN(PermissionsInfo);
77 } // namespace extensions
79 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_INFO_H_