Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / mojo / services / view_manager / view_manager_connection.h
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.
4
5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_
7
8 #include <set>
9
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"
16
17 namespace mojo {
18 namespace services {
19 namespace view_manager {
20
21 class Node;
22 class RootNodeManager;
23 class View;
24
25 // Manages a connection from the client.
26 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
27     : public ServiceConnection<IViewManager, ViewManagerConnection,
28                                RootNodeManager>,
29       public NodeDelegate {
30  public:
31   ViewManagerConnection();
32   virtual ~ViewManagerConnection();
33
34   TransportConnectionId id() const { return id_; }
35
36   // Invoked when connection is established.
37   void Initialize();
38
39   // Returns the Node with the specified id.
40   Node* GetNode(const NodeId& id);
41
42   // Returns the View with the specified id.
43   View* GetView(const ViewId& id);
44
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);
55
56  private:
57   typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap;
58   typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap;
59
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);
65
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);
71
72   // Sets the view associated with a node.
73   bool SetViewImpl(const NodeId& node_id,
74                    const ViewId& view_id,
75                    TransportChangeId change_id);
76
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;
107
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;
115
116   IViewManagerClient* client_;
117
118   // Id of this connection as assigned by RootNodeManager. Assigned in
119   // Initialize().
120   TransportConnectionId id_;
121
122   NodeMap node_map_;
123
124   ViewMap view_map_;
125
126   DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection);
127 };
128
129 }  // namespace view_manager
130 }  // namespace services
131 }  // namespace mojo
132
133 #endif  // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_