OLD | NEW |
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_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ | 5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ |
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ | 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
14 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 14 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 class Application; | 17 class Application; |
18 namespace view_manager { | 18 namespace view_manager { |
19 | 19 |
20 class View; | 20 class View; |
| 21 class ViewManagerDelegate; |
21 class ViewManagerSynchronizer; | 22 class ViewManagerSynchronizer; |
22 class ViewTreeNode; | 23 class ViewTreeNode; |
23 | 24 |
24 // Approximately encapsulates the View Manager service. | 25 // Approximately encapsulates the View Manager service. |
25 // Has a synchronizer that keeps a client model in sync with the service. | 26 // Has a synchronizer that keeps a client model in sync with the service. |
26 // Owned by the connection. | 27 // Owned by the connection. |
27 // | |
28 // TODO: displays | |
29 class ViewManager { | 28 class ViewManager { |
30 public: | 29 public: |
31 typedef base::Callback<void(ViewManager*, ViewTreeNode*)> RootCallback; | |
32 | |
33 ~ViewManager(); | 30 ~ViewManager(); |
34 | 31 |
35 // |ready_callback| is run when the ViewManager connection is established | 32 // Delegate is owned by the caller. |
36 // and ready to use. | 33 static void Create(Application* application, ViewManagerDelegate* delegate); |
37 static void Create( | |
38 Application* application, | |
39 const RootCallback& root_added_callback, | |
40 const RootCallback& root_removed_callback); | |
41 // Blocks until ViewManager is ready to use. | |
42 static ViewManager* CreateBlocking(Application* application); | |
43 | 34 |
44 const std::vector<ViewTreeNode*>& roots() { return roots_; } | 35 const std::vector<ViewTreeNode*>& roots() { return roots_; } |
45 | 36 |
46 ViewTreeNode* GetNodeById(TransportNodeId id); | 37 ViewTreeNode* GetNodeById(TransportNodeId id); |
47 View* GetViewById(TransportViewId id); | 38 View* GetViewById(TransportViewId id); |
48 | 39 |
49 private: | 40 private: |
50 friend class ViewManagerPrivate; | 41 friend class ViewManagerPrivate; |
| 42 friend class ViewManagerSynchronizer; |
| 43 |
51 typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap; | 44 typedef std::map<TransportNodeId, ViewTreeNode*> IdToNodeMap; |
52 typedef std::map<TransportViewId, View*> IdToViewMap; | 45 typedef std::map<TransportViewId, View*> IdToViewMap; |
| 46 typedef std::map<TransportConnectionId, |
| 47 ViewManagerSynchronizer*> SynchronizerMap; |
53 | 48 |
54 ViewManager(Application* application, | 49 ViewManager(ViewManagerSynchronizer* synchronizer, |
55 const RootCallback& root_added_callback, | 50 ViewManagerDelegate* delegate); |
56 const RootCallback& root_removed_callback); | |
57 | 51 |
58 RootCallback root_added_callback_; | 52 ViewManagerDelegate* delegate_; |
59 RootCallback root_removed_callback_; | |
60 | |
61 ViewManagerSynchronizer* synchronizer_; | 53 ViewManagerSynchronizer* synchronizer_; |
62 | 54 |
63 std::vector<ViewTreeNode*> roots_; | 55 std::vector<ViewTreeNode*> roots_; |
64 | 56 |
65 IdToNodeMap nodes_; | 57 IdToNodeMap nodes_; |
66 IdToViewMap views_; | 58 IdToViewMap views_; |
67 | 59 |
68 DISALLOW_COPY_AND_ASSIGN(ViewManager); | 60 DISALLOW_COPY_AND_ASSIGN(ViewManager); |
69 }; | 61 }; |
70 | 62 |
71 } // namespace view_manager | 63 } // namespace view_manager |
72 } // namespace mojo | 64 } // namespace mojo |
73 | 65 |
74 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ | 66 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_MANAGER_H_ |
OLD | NEW |