Move prefs::kLastPolicyStatisticsUpdate to the policy component.
[chromium-blink-merge.git] / ppapi / shared_impl / id_assignment.h
blob3bacac3829fe4b3c5d49a4231548569e09f2b369
1 // Copyright (c) 2011 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 PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_
6 #define PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_
8 #include <limits>
10 #include "base/basictypes.h"
11 #include "ppapi/shared_impl/ppapi_shared_export.h"
13 namespace ppapi {
15 enum PPIdType {
16 PP_ID_TYPE_MODULE,
17 PP_ID_TYPE_INSTANCE,
18 PP_ID_TYPE_RESOURCE,
19 PP_ID_TYPE_VAR,
21 // Not a real type, must be last.
22 PP_ID_TYPE_COUNT
25 PPAPI_SHARED_EXPORT extern const unsigned int kPPIdTypeBits;
27 extern const int32 kMaxPPId;
29 // The least significant bits are the type, the rest are the value.
30 template <typename T> inline T MakeTypedId(T value, PPIdType type) {
31 return (value << kPPIdTypeBits) | static_cast<T>(type);
34 template <typename T> inline bool CheckIdType(T id, PPIdType type) {
35 // Say a resource of 0 is always valid, since that means "no resource."
36 // You shouldn't be passing 0 var, instance, or module IDs around so those
37 // are still invalid.
38 if (type == PP_ID_TYPE_RESOURCE && !id)
39 return true;
40 const T mask = (static_cast<T>(1) << kPPIdTypeBits) - 1;
41 return (id & mask) == type;
44 } // namespace ppapi
46 #endif // PPAPI_SHARED_IMPL_ID_ASSIGNMENT_H_