OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ | 4 #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ |
5 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ | 5 #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "services/resource_coordinator/public/cpp/coordination_unit_types.h" | 9 #include "services/resource_coordinator/public/cpp/coordination_unit_types.h" |
10 #include "services/resource_coordinator/public/cpp/resource_coordinator_export.h
" | 10 #include "services/resource_coordinator/public/cpp/resource_coordinator_export.h
" |
11 | 11 |
12 namespace resource_coordinator { | 12 namespace resource_coordinator { |
13 | 13 |
14 // This is a native struct rather than a mojom struct as we eventually want | 14 // This is a native struct rather than a mojom struct as we eventually want |
15 // to annotate base::TaskRunner with CUs for cost attribution purses and | 15 // to annotate base::TaskRunner with CUs for cost attribution purses and |
16 // would like to move it to base/ as easily as possible at that point. | 16 // would like to move it to base/ as easily as possible at that point. |
17 // TODO(oysteine): Rename to CoordinationUnitGUID to better differentiate the | |
18 // class from the internal id | |
19 struct SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_EXPORT CoordinationUnitID { | 17 struct SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_EXPORT CoordinationUnitID { |
20 typedef uint64_t CoordinationUnitTypeId; | |
21 | |
22 CoordinationUnitID(); | 18 CoordinationUnitID(); |
23 CoordinationUnitID(const CoordinationUnitType& type, | 19 CoordinationUnitID(const CoordinationUnitType& type, |
24 const std::string& new_id); | 20 const std::string& new_id); |
25 CoordinationUnitID(const CoordinationUnitType& type, | |
26 CoordinationUnitTypeId new_id); | |
27 | 21 |
28 bool operator==(const CoordinationUnitID& b) const { | 22 bool operator==(const CoordinationUnitID& b) const { |
29 return id == b.id && type == b.type; | 23 return id == b.id && type == b.type; |
30 } | 24 } |
31 | 25 |
32 CoordinationUnitTypeId id; | 26 int64_t id; |
33 CoordinationUnitType type; | 27 CoordinationUnitType type; |
34 }; | 28 }; |
35 | 29 |
36 } // resource_coordinator | 30 } // resource_coordinator |
37 | 31 |
38 namespace std { | 32 namespace std { |
39 | 33 |
40 template <> | 34 template <> |
41 struct hash<resource_coordinator::CoordinationUnitID> { | 35 struct hash<resource_coordinator::CoordinationUnitID> { |
42 uint64_t operator()( | 36 uint64_t operator()( |
43 const resource_coordinator::CoordinationUnitID& id) const { | 37 const resource_coordinator::CoordinationUnitID& id) const { |
44 return ((static_cast<uint64_t>(id.type)) << 32) | | 38 return ((static_cast<uint64_t>(id.type)) << 32) | id.id; |
45 static_cast<uint64_t>(id.id); | |
46 } | 39 } |
47 }; | 40 }; |
48 | 41 |
49 } // namespace std | 42 } // namespace std |
50 | 43 |
51 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ | 44 #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_CPP_ID_H_ |
OLD | NEW |