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 "base/compiler_specific.h"
12 #include "mojo/public/cpp/shell/service.h"
13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
14 #include "mojo/services/view_manager/ids.h"
15 #include "mojo/services/view_manager/node_delegate.h"
16 #include "mojo/services/view_manager/view_manager_export.h"
20 namespace view_manager
{
23 class RootNodeManager
;
27 // Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
30 #pragma warning(disable : 4275)
33 // Manages a connection from the client.
34 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
35 : public ServiceConnection
<IViewManager
, ViewManagerConnection
,
39 ViewManagerConnection();
40 virtual ~ViewManagerConnection();
42 TransportConnectionId
id() const { return id_
; }
44 // Invoked when connection is established.
47 // Returns the Node with the specified id.
48 Node
* GetNode(const NodeId
& id
);
50 // Returns the View with the specified id.
51 View
* GetView(const ViewId
& id
);
53 // Notifies the client of a hierarchy change.
54 void NotifyNodeHierarchyChanged(const NodeId
& node
,
55 const NodeId
& new_parent
,
56 const NodeId
& old_parent
,
57 TransportChangeId change_id
);
58 void NotifyNodeViewReplaced(const NodeId
& node
,
59 const ViewId
& new_view_id
,
60 const ViewId
& old_view_id
,
61 TransportChangeId change_id
);
62 void NotifyNodeDeleted(const NodeId
& node
, TransportChangeId change_id
);
65 typedef std::map
<TransportConnectionSpecificNodeId
, Node
*> NodeMap
;
66 typedef std::map
<TransportConnectionSpecificViewId
, View
*> ViewMap
;
68 // Deletes a node owned by this connection. Returns true on success. |source|
69 // is the connection that originated the change.
70 bool DeleteNodeImpl(ViewManagerConnection
* source
,
71 const NodeId
& node_id
,
72 TransportChangeId change_id
);
74 // Deletes a view owned by this connection. Returns true on success. |source|
75 // is the connection that originated the change.
76 bool DeleteViewImpl(ViewManagerConnection
* source
,
77 const ViewId
& view_id
,
78 TransportChangeId change_id
);
80 // Sets the view associated with a node.
81 bool SetViewImpl(const NodeId
& node_id
,
82 const ViewId
& view_id
,
83 TransportChangeId change_id
);
85 // Overridden from IViewManager:
86 virtual void SetClient(IViewManagerClient
* client
) OVERRIDE
;
87 virtual void CreateNode(TransportConnectionSpecificNodeId node_id
,
88 const Callback
<void(bool)>& callback
) OVERRIDE
;
89 virtual void DeleteNode(TransportNodeId transport_node_id
,
90 TransportChangeId change_id
,
91 const Callback
<void(bool)>& callback
) OVERRIDE
;
92 virtual void AddNode(TransportNodeId parent_id
,
93 TransportNodeId child_id
,
94 TransportChangeId change_id
,
95 const Callback
<void(bool)>& callback
) OVERRIDE
;
96 virtual void RemoveNodeFromParent(
97 TransportNodeId node_id
,
98 TransportChangeId change_id
,
99 const Callback
<void(bool)>& callback
) OVERRIDE
;
100 virtual void GetNodeTree(
101 TransportNodeId node_id
,
102 const Callback
<void(Array
<INode
>)>& callback
) OVERRIDE
;
103 virtual void CreateView(TransportConnectionSpecificViewId view_id
,
104 const Callback
<void(bool)>& callback
) OVERRIDE
;
105 virtual void DeleteView(TransportViewId transport_view_id
,
106 TransportChangeId change_id
,
107 const Callback
<void(bool)>& callback
) OVERRIDE
;
108 virtual void SetView(TransportNodeId transport_node_id
,
109 TransportViewId transport_view_id
,
110 TransportChangeId change_id
,
111 const Callback
<void(bool)>& callback
) OVERRIDE
;
112 virtual void SetViewContents(TransportViewId view_id
,
113 ScopedSharedBufferHandle buffer
,
114 uint32_t buffer_size
) OVERRIDE
;
116 // Overridden from NodeDelegate:
117 virtual void OnNodeHierarchyChanged(const NodeId
& node
,
118 const NodeId
& new_parent
,
119 const NodeId
& old_parent
) OVERRIDE
;
120 virtual void OnNodeViewReplaced(const NodeId
& node
,
121 const ViewId
& new_view_id
,
122 const ViewId
& old_view_id
) OVERRIDE
;
124 IViewManagerClient
* client_
;
126 // Id of this connection as assigned by RootNodeManager. Assigned in
128 TransportConnectionId id_
;
134 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection
);
141 } // namespace view_manager
142 } // namespace services
145 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_