Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: mojo/services/view_manager/ids.h

Issue 320193002: Consolidates view_manager typedefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: formatting Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 4
5 #ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_IDS_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_IDS_H_
7 7
8 #include "mojo/services/public/cpp/view_manager/util.h" 8 #include "mojo/services/public/cpp/view_manager/util.h"
9 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" 9 #include "mojo/services/public/cpp/view_manager/view_manager_types.h"
10 #include "mojo/services/view_manager/view_manager_export.h" 10 #include "mojo/services/view_manager/view_manager_export.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace view_manager { 13 namespace view_manager {
14 namespace service { 14 namespace service {
15 15
16 // Connection id reserved for the root. 16 // Connection id reserved for the root.
17 const TransportConnectionId kRootConnection = 0; 17 const ConnectionSpecificId kRootConnection = 0;
18 18
19 // Adds a bit of type safety to node ids. 19 // Adds a bit of type safety to node ids.
20 struct MOJO_VIEW_MANAGER_EXPORT NodeId { 20 struct MOJO_VIEW_MANAGER_EXPORT NodeId {
21 NodeId(TransportConnectionId connection_id, 21 NodeId(ConnectionSpecificId connection_id, ConnectionSpecificId node_id)
22 TransportConnectionSpecificNodeId node_id)
23 : connection_id(connection_id), 22 : connection_id(connection_id),
24 node_id(node_id) {} 23 node_id(node_id) {}
25 NodeId() : connection_id(0), node_id(0) {} 24 NodeId() : connection_id(0), node_id(0) {}
26 25
27 bool operator==(const NodeId& other) const { 26 bool operator==(const NodeId& other) const {
28 return other.connection_id == connection_id && 27 return other.connection_id == connection_id &&
29 other.node_id == node_id; 28 other.node_id == node_id;
30 } 29 }
31 30
32 bool operator!=(const NodeId& other) const { 31 bool operator!=(const NodeId& other) const {
33 return !(*this == other); 32 return !(*this == other);
34 } 33 }
35 34
36 TransportConnectionId connection_id; 35 ConnectionSpecificId connection_id;
37 TransportConnectionSpecificNodeId node_id; 36 ConnectionSpecificId node_id;
38 }; 37 };
39 38
40 // Adds a bit of type safety to view ids. 39 // Adds a bit of type safety to view ids.
41 struct MOJO_VIEW_MANAGER_EXPORT ViewId { 40 struct MOJO_VIEW_MANAGER_EXPORT ViewId {
42 ViewId(TransportConnectionId connection_id, 41 ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id)
43 TransportConnectionSpecificViewId view_id)
44 : connection_id(connection_id), 42 : connection_id(connection_id),
45 view_id(view_id) {} 43 view_id(view_id) {}
46 ViewId() : connection_id(0), view_id(0) {} 44 ViewId() : connection_id(0), view_id(0) {}
47 45
48 bool operator==(const ViewId& other) const { 46 bool operator==(const ViewId& other) const {
49 return other.connection_id == connection_id && 47 return other.connection_id == connection_id &&
50 other.view_id == view_id; 48 other.view_id == view_id;
51 } 49 }
52 50
53 bool operator!=(const ViewId& other) const { 51 bool operator!=(const ViewId& other) const {
54 return !(*this == other); 52 return !(*this == other);
55 } 53 }
56 54
57 TransportConnectionId connection_id; 55 ConnectionSpecificId connection_id;
58 TransportConnectionSpecificViewId view_id; 56 ConnectionSpecificId view_id;
59 }; 57 };
60 58
61 // Functions for converting to/from structs and transport values. 59 // Functions for converting to/from structs and transport values.
62 inline NodeId NodeIdFromTransportId(TransportNodeId id) { 60 inline NodeId NodeIdFromTransportId(Id id) {
63 return NodeId(HiWord(id), LoWord(id)); 61 return NodeId(HiWord(id), LoWord(id));
64 } 62 }
65 63
66 inline TransportNodeId NodeIdToTransportId(const NodeId& id) { 64 inline Id NodeIdToTransportId(const NodeId& id) {
67 return (id.connection_id << 16) | id.node_id; 65 return (id.connection_id << 16) | id.node_id;
68 } 66 }
69 67
70 inline ViewId ViewIdFromTransportId(TransportViewId id) { 68 inline ViewId ViewIdFromTransportId(Id id) {
71 return ViewId(HiWord(id), LoWord(id)); 69 return ViewId(HiWord(id), LoWord(id));
72 } 70 }
73 71
74 inline TransportViewId ViewIdToTransportId(const ViewId& id) { 72 inline Id ViewIdToTransportId(const ViewId& id) {
75 return (id.connection_id << 16) | id.view_id; 73 return (id.connection_id << 16) | id.view_id;
76 } 74 }
77 75
78 inline NodeId RootNodeId() { 76 inline NodeId RootNodeId() {
79 return NodeId(kRootConnection, 1); 77 return NodeId(kRootConnection, 1);
80 } 78 }
81 79
82 // Returns a NodeId that is reserved to indicate no node. That is, no node will 80 // Returns a NodeId that is reserved to indicate no node. That is, no node will
83 // ever be created with this id. 81 // ever be created with this id.
84 inline NodeId InvalidNodeId() { 82 inline NodeId InvalidNodeId() {
85 return NodeId(kRootConnection, 0); 83 return NodeId(kRootConnection, 0);
86 } 84 }
87 85
88 } // namespace service 86 } // namespace service
89 } // namespace view_manager 87 } // namespace view_manager
90 } // namespace mojo 88 } // namespace mojo
91 89
92 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_ 90 #endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_
OLDNEW
« no previous file with comments | « mojo/services/public/cpp/view_manager/view_tree_node.h ('k') | mojo/services/view_manager/root_node_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698