Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / permissions_info.h
blobe79abb429d4689f4a502e254911a846f113e249e
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.
5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/callback.h"
13 #include "base/memory/singleton.h"
14 #include "chrome/common/extensions/permissions/api_permission.h"
15 #include "chrome/common/extensions/permissions/api_permission_set.h"
16 #include "chrome/common/extensions/permissions/permission_message.h"
18 namespace extensions {
20 // Singleton that holds the extension permission instances and provides static
21 // methods for accessing them.
22 class PermissionsInfo {
23 public:
24 // Returns a pointer to the singleton instance.
25 static PermissionsInfo* GetInstance();
27 // Returns the permission with the given |id|, and NULL if it doesn't exist.
28 const APIPermissionInfo* GetByID(APIPermission::ID id) const;
30 // Returns the permission with the given |name|, and NULL if none
31 // exists.
32 const APIPermissionInfo* GetByName(const std::string& name) const;
34 // Returns a set containing all valid api permission ids.
35 APIPermissionSet GetAll() const;
37 // Converts all the permission names in |permission_names| to permission ids.
38 APIPermissionSet GetAllByName(
39 const std::set<std::string>& permission_names) const;
41 // Checks if any permissions have names that start with |name| followed by a
42 // period.
43 bool HasChildPermissions(const std::string& name) const;
45 // Gets the total number of API permissions.
46 size_t get_permission_count() const { return permission_count_; }
48 private:
49 friend class APIPermissionInfo;
51 ~PermissionsInfo();
52 PermissionsInfo();
54 // Registers an |alias| for a given permission |name|.
55 void RegisterAlias(const char* name, const char* alias);
57 // Registers a permission with the specified attributes and flags.
58 const APIPermissionInfo* RegisterPermission(
59 APIPermission::ID id,
60 const char* name,
61 int l10n_message_id,
62 PermissionMessage::ID message_id,
63 int flags,
64 const APIPermissionInfo::APIPermissionConstructor constructor);
66 // Maps permission ids to permissions.
67 typedef std::map<APIPermission::ID, APIPermissionInfo*> IDMap;
69 // Maps names and aliases to permissions.
70 typedef std::map<std::string, APIPermissionInfo*> NameMap;
72 IDMap id_map_;
73 NameMap name_map_;
75 size_t hosted_app_permission_count_;
76 size_t permission_count_;
78 friend struct DefaultSingletonTraits<PermissionsInfo>;
79 DISALLOW_COPY_AND_ASSIGN(PermissionsInfo);
82 } // namespace extensions
84 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSIONS_INFO_H_