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

Unified Diff: components/mus/ws/ids.h

Issue 1639223003: Makes it so each windowtreeclient can use whatever ids it wants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/mus/ws/connection_manager.cc ('k') | components/mus/ws/server_window_surface.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/ws/ids.h
diff --git a/components/mus/ws/ids.h b/components/mus/ws/ids.h
index fdb3b5643d06ddeb7728972a4eddac5cd66f07b1..233f24dc9fb9dbcb30111dc7046ca9243d276b7b 100644
--- a/components/mus/ws/ids.h
+++ b/components/mus/ws/ids.h
@@ -9,18 +9,31 @@
#include <tuple>
+#include "base/hash.h"
#include "components/mus/common/types.h"
#include "components/mus/common/util.h"
namespace mus {
-
namespace ws {
// Connection id is used to indicate no connection. That is, no WindowTreeImpl
// ever gets this id.
const ConnectionSpecificId kInvalidConnectionId = 0;
-// Adds a bit of type safety to window ids.
+// Every window has a unique id associated with it (WindowId). The id is a
+// combination of the id assigned to the connection (the high order bits) and
+// a unique id for the window. Each client (WindowTreeImpl) refers to the
+// window by an id assigned by the client (ClientWindowId). To facilitate this
+// WindowTreeImpl maintains a mapping between WindowId and ClientWindowId.
+//
+// This model works when the client initiates creation of windows, which is
+// the typical use case. Embed roots and the WindowManager are special, they
+// get access to windows created by other connections. These clients see the
+// id assigned on the server. Such clients have to take care that they only
+// create windows using their connection id. To do otherwise could result in
+// multiple windows having the same ClientWindowId. WindowTreeImpl enforces
+// that embed roots use the connection id in creating the window id to avoid
+// possible conflicts.
struct WindowId {
WindowId(ConnectionSpecificId connection_id, ConnectionSpecificId window_id)
: connection_id(connection_id), window_id(window_id) {}
@@ -41,10 +54,25 @@ struct WindowId {
ConnectionSpecificId window_id;
};
+// Used for ids assigned by the client.
+struct ClientWindowId {
+ explicit ClientWindowId(Id id) : id(id) {}
+ ClientWindowId() : id(0u) {}
+
+ bool operator==(const ClientWindowId& other) const { return other.id == id; }
+
+ bool operator!=(const ClientWindowId& other) const {
+ return !(*this == other);
+ }
+
+ bool operator<(const ClientWindowId& other) const { return id < other.id; }
+
+ Id id;
+};
+
inline WindowId WindowIdFromTransportId(Id id) {
return WindowId(HiWord(id), LoWord(id));
}
-
inline Id WindowIdToTransportId(const WindowId& id) {
return (id.connection_id << 16) | id.window_id;
}
@@ -61,7 +89,24 @@ inline WindowId RootWindowId(uint16_t index) {
}
} // namespace ws
-
} // namespace mus
+namespace BASE_HASH_NAMESPACE {
+
+template <>
+struct hash<mus::ws::ClientWindowId> {
+ size_t operator()(const mus::ws::ClientWindowId& id) const {
+ return hash<mus::Id>()(id.id);
+ }
+};
+
+template <>
+struct hash<mus::ws::WindowId> {
+ size_t operator()(const mus::ws::WindowId& id) const {
+ return hash<mus::Id>()(WindowIdToTransportId(id));
+ }
+};
+
+} // namespace BASE_HASH_NAMESPACE
+
#endif // COMPONENTS_MUS_WS_IDS_H_
« no previous file with comments | « components/mus/ws/connection_manager.cc ('k') | components/mus/ws/server_window_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698