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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_
10 #include "base/basictypes.h"
11 #include "mojo/public/cpp/shell/service.h"
12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
13 #include "mojo/services/view_manager/ids.h"
14 #include "mojo/services/view_manager/node_delegate.h"
15 #include "mojo/services/view_manager/view_manager_export.h"
19 namespace view_manager {
22 class RootNodeManager;
25 // Manages a connection from the client.
26 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
27 : public ServiceConnection<IViewManager, ViewManagerConnection,
31 ViewManagerConnection();
32 virtual ~ViewManagerConnection();
34 TransportConnectionId id() const { return id_; }
36 // Invoked when connection is established.
39 // Returns the Node with the specified id.
40 Node* GetNode(const NodeId& id);
42 // Returns the View with the specified id.
43 View* GetView(const ViewId& id);
45 // Notifies the client of a hierarchy change.
46 void NotifyNodeHierarchyChanged(const NodeId& node,
47 const NodeId& new_parent,
48 const NodeId& old_parent,
49 TransportChangeId change_id);
50 void NotifyNodeViewReplaced(const NodeId& node,
51 const ViewId& new_view_id,
52 const ViewId& old_view_id,
53 TransportChangeId change_id);
54 void NotifyNodeDeleted(const NodeId& node, TransportChangeId change_id);
57 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap;
58 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap;
60 // Deletes a node owned by this connection. Returns true on success. |source|
61 // is the connection that originated the change.
62 bool DeleteNodeImpl(ViewManagerConnection* source,
63 const NodeId& node_id,
64 TransportChangeId change_id);
66 // Deletes a view owned by this connection. Returns true on success. |source|
67 // is the connection that originated the change.
68 bool DeleteViewImpl(ViewManagerConnection* source,
69 const ViewId& view_id,
70 TransportChangeId change_id);
72 // Sets the view associated with a node.
73 bool SetViewImpl(const NodeId& node_id,
74 const ViewId& view_id,
75 TransportChangeId change_id);
77 // Overridden from IViewManager:
78 virtual void SetClient(IViewManagerClient* client) OVERRIDE;
79 virtual void CreateNode(TransportConnectionSpecificNodeId node_id,
80 const Callback<void(bool)>& callback) OVERRIDE;
81 virtual void DeleteNode(TransportNodeId transport_node_id,
82 TransportChangeId change_id,
83 const Callback<void(bool)>& callback) OVERRIDE;
84 virtual void AddNode(TransportNodeId parent_id,
85 TransportNodeId child_id,
86 TransportChangeId change_id,
87 const Callback<void(bool)>& callback) OVERRIDE;
88 virtual void RemoveNodeFromParent(
89 TransportNodeId node_id,
90 TransportChangeId change_id,
91 const Callback<void(bool)>& callback) OVERRIDE;
92 virtual void GetNodeTree(
93 TransportNodeId node_id,
94 const Callback<void(Array<INode>)>& callback) OVERRIDE;
95 virtual void CreateView(TransportConnectionSpecificViewId view_id,
96 const Callback<void(bool)>& callback) OVERRIDE;
97 virtual void DeleteView(TransportViewId transport_view_id,
98 TransportChangeId change_id,
99 const Callback<void(bool)>& callback) OVERRIDE;
100 virtual void SetView(TransportNodeId transport_node_id,
101 TransportViewId transport_view_id,
102 TransportChangeId change_id,
103 const Callback<void(bool)>& callback) OVERRIDE;
104 virtual void SetViewContents(TransportViewId view_id,
105 ScopedSharedBufferHandle buffer,
106 uint32_t buffer_size) OVERRIDE;
108 // Overridden from NodeDelegate:
109 virtual void OnNodeHierarchyChanged(const NodeId& node,
110 const NodeId& new_parent,
111 const NodeId& old_parent) OVERRIDE;
112 virtual void OnNodeViewReplaced(const NodeId& node,
113 const ViewId& new_view_id,
114 const ViewId& old_view_id) OVERRIDE;
116 IViewManagerClient* client_;
118 // Id of this connection as assigned by RootNodeManager. Assigned in
120 TransportConnectionId id_;
126 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection);
129 } // namespace view_manager
130 } // namespace services
133 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_