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

Side by Side Diff: mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h

Issue 303163005: Embedding demo in View manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ 5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 12 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" 13 #include "mojo/services/public/cpp/view_manager/view_manager_types.h"
14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 14 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
15 15
16 class SkBitmap; 16 class SkBitmap;
17 17
18 namespace base {
19 class RunLoop;
20 }
21
22 namespace mojo { 18 namespace mojo {
23 namespace view_manager { 19 namespace view_manager {
24 20
25 class ViewManager; 21 class ViewManager;
26 class ViewManagerTransaction; 22 class ViewManagerTransaction;
27 23
28 // Manages the connection with the View Manager service. 24 // Manages the connection with the View Manager service.
29 class ViewManagerSynchronizer : public IViewManagerClient { 25 class ViewManagerSynchronizer : public InterfaceImpl<IViewManagerClient> {
30 public: 26 public:
31 explicit ViewManagerSynchronizer(ViewManager* view_manager); 27 explicit ViewManagerSynchronizer(ViewManager* view_manager);
32 virtual ~ViewManagerSynchronizer(); 28 virtual ~ViewManagerSynchronizer();
33 29
34 bool connected() const { return connected_; } 30 bool connected() const { return connected_; }
35 31
36 // API exposed to the node/view implementations that pushes local changes to 32 // API exposed to the node/view implementations that pushes local changes to
37 // the service. 33 // the service.
38 TransportNodeId CreateViewTreeNode(); 34 TransportNodeId CreateViewTreeNode();
39 void DestroyViewTreeNode(TransportNodeId node_id); 35 void DestroyViewTreeNode(TransportNodeId node_id);
40 36
41 TransportViewId CreateView(); 37 TransportViewId CreateView();
42 void DestroyView(TransportViewId view_id); 38 void DestroyView(TransportViewId view_id);
43 39
44 // These methods take TransportIds. For views owned by the current connection, 40 // These methods take TransportIds. For views owned by the current connection,
45 // the connection id high word can be zero. In all cases, the TransportId 0x1 41 // the connection id high word can be zero. In all cases, the TransportId 0x1
46 // refers to the root node. 42 // refers to the root node.
47 void AddChild(TransportNodeId child_id, TransportNodeId parent_id); 43 void AddChild(TransportNodeId child_id, TransportNodeId parent_id);
48 void RemoveChild(TransportNodeId child_id, TransportNodeId parent_id); 44 void RemoveChild(TransportNodeId child_id, TransportNodeId parent_id);
49 45
50 bool OwnsNode(TransportNodeId id) const; 46 bool OwnsNode(TransportNodeId id) const;
51 bool OwnsView(TransportViewId id) const; 47 bool OwnsView(TransportViewId id) const;
52 48
53 void SetActiveView(TransportNodeId node_id, TransportViewId view_id); 49 void SetActiveView(TransportNodeId node_id, TransportViewId view_id);
54 void SetBounds(TransportNodeId node_id, const gfx::Rect& bounds); 50 void SetBounds(TransportNodeId node_id, const gfx::Rect& bounds);
55 void SetViewContents(TransportViewId view_id, const SkBitmap& contents); 51 void SetViewContents(TransportViewId view_id, const SkBitmap& contents);
56 52
53 void Embed(const String& url, TransportNodeId node_id);
54
57 void set_changes_acked_callback(const base::Callback<void(void)>& callback) { 55 void set_changes_acked_callback(const base::Callback<void(void)>& callback) {
58 changes_acked_callback_ = callback; 56 changes_acked_callback_ = callback;
59 } 57 }
60 void ClearChangesAckedCallback() { 58 void ClearChangesAckedCallback() {
61 changes_acked_callback_ = base::Callback<void(void)>(); 59 changes_acked_callback_ = base::Callback<void(void)>();
62 } 60 }
63 61
64 private: 62 private:
65 friend class ViewManagerTransaction; 63 friend class ViewManagerTransaction;
66 typedef ScopedVector<ViewManagerTransaction> Transactions; 64 typedef ScopedVector<ViewManagerTransaction> Transactions;
67 65
66 // Overridden from InterfaceImpl:
67 virtual void OnConnectionEstablished() OVERRIDE;
68
68 // Overridden from IViewManagerClient: 69 // Overridden from IViewManagerClient:
69 virtual void OnViewManagerConnectionEstablished( 70 virtual void OnViewManagerConnectionEstablished(
70 TransportConnectionId connection_id, 71 TransportConnectionId connection_id,
71 TransportChangeId next_server_change_id, 72 TransportChangeId next_server_change_id,
72 mojo::Array<INodePtr> nodes) OVERRIDE; 73 mojo::Array<INodePtr> nodes) OVERRIDE;
73 virtual void OnServerChangeIdAdvanced( 74 virtual void OnServerChangeIdAdvanced(
74 uint32_t next_server_change_id) OVERRIDE; 75 uint32_t next_server_change_id) OVERRIDE;
75 virtual void OnNodeBoundsChanged(uint32 node_id, 76 virtual void OnNodeBoundsChanged(uint32 node_id,
76 RectPtr old_bounds, 77 RectPtr old_bounds,
77 RectPtr new_bounds) OVERRIDE; 78 RectPtr new_bounds) OVERRIDE;
(...skipping 11 matching lines...) Expand all
89 virtual void OnViewDeleted(uint32_t view_id) OVERRIDE; 90 virtual void OnViewDeleted(uint32_t view_id) OVERRIDE;
90 91
91 // Sync the client model with the service by enumerating the pending 92 // Sync the client model with the service by enumerating the pending
92 // transaction queue and applying them in order. 93 // transaction queue and applying them in order.
93 void Sync(); 94 void Sync();
94 95
95 // Removes |transaction| from the pending queue. |transaction| must be at the 96 // Removes |transaction| from the pending queue. |transaction| must be at the
96 // front of the queue. 97 // front of the queue.
97 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); 98 void RemoveFromPendingQueue(ViewManagerTransaction* transaction);
98 99
99 ViewManager* view_manager_; 100 ViewManager* view_manager() { return view_manager_.get(); }
101
102 scoped_ptr<ViewManager> view_manager_;
100 bool connected_; 103 bool connected_;
101 TransportConnectionId connection_id_; 104 TransportConnectionId connection_id_;
102 uint16_t next_id_; 105 uint16_t next_id_;
103 TransportChangeId next_server_change_id_; 106 TransportChangeId next_server_change_id_;
104 107
105 Transactions pending_transactions_; 108 Transactions pending_transactions_;
106 109
107 base::WeakPtrFactory<ViewManagerSynchronizer> sync_factory_; 110 base::WeakPtrFactory<ViewManagerSynchronizer> sync_factory_;
108 111
109 // Non-NULL while blocking on the connection to |service_| during
110 // construction.
111 base::RunLoop* init_loop_;
112
113 base::Callback<void(void)> changes_acked_callback_; 112 base::Callback<void(void)> changes_acked_callback_;
114 113
115 IViewManagerPtr service_; 114 IViewManager* service_;
116 115
117 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); 116 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer);
118 }; 117 };
119 118
120 } // namespace view_manager 119 } // namespace view_manager
121 } // namespace mojo 120 } // namespace mojo
122 121
123 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H _ 122 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698