Bug 1472338: part 1) Add Chrome tests for the async Clipboard API. r=NeilDeakin
[gecko.git] / dom / ipc / IdType.h
blobacc2b6d8109f36d13fc02635c4ac3a9aa993fdd8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_IdType_h
8 #define mozilla_dom_IdType_h
10 #include "ipc/IPCMessageUtils.h"
12 namespace IPC {
13 template <typename T>
14 struct ParamTraits;
15 } // namespace IPC
17 namespace mozilla {
18 namespace dom {
19 class BrowsingContext;
20 class ContentParent;
21 class BrowserParent;
23 template <typename T>
24 class IdType {
25 friend struct IPC::ParamTraits<IdType<T>>;
27 public:
28 IdType() : mId(0) {}
29 explicit IdType(uint64_t aId) : mId(aId) {}
31 operator uint64_t() const { return mId; }
33 IdType& operator=(uint64_t aId) {
34 mId = aId;
35 return *this;
38 bool operator<(const IdType& rhs) { return mId < rhs.mId; }
40 private:
41 uint64_t mId;
44 using TabId = IdType<BrowserParent>;
45 using ContentParentId = IdType<ContentParent>;
46 } // namespace dom
47 } // namespace mozilla
49 namespace IPC {
51 template <typename T>
52 struct ParamTraits<mozilla::dom::IdType<T>> {
53 using paramType = mozilla::dom::IdType<T>;
55 static void Write(Message* aMsg, const paramType& aParam) {
56 WriteParam(aMsg, aParam.mId);
59 static bool Read(const Message* aMsg, PickleIterator* aIter,
60 paramType* aResult) {
61 return ReadParam(aMsg, aIter, &aResult->mId);
65 } // namespace IPC
67 #endif // mozilla_dom_IdType_h