| 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 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | 11 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| 12 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 12 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 13 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" | 13 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
| 14 #include "mojo/services/public/cpp/view_manager/util.h" | 14 #include "mojo/services/public/cpp/view_manager/util.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 15 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace view_manager { | 20 namespace view_manager { |
| 21 | 21 |
| 22 uint32_t MakeTransportId(uint16_t connection_id, uint16_t local_id) { | 22 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 23 ConnectionSpecificId local_id) { |
| 23 return (connection_id << 16) | local_id; | 24 return (connection_id << 16) | local_id; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // Helper called to construct a local node/view object from transport data. | 27 // Helper called to construct a local node/view object from transport data. |
| 27 ViewTreeNode* AddNodeToViewManager(ViewManager* manager, | 28 ViewTreeNode* AddNodeToViewManager(ViewManager* manager, |
| 28 ViewTreeNode* parent, | 29 ViewTreeNode* parent, |
| 29 TransportNodeId node_id, | 30 Id node_id, |
| 30 TransportViewId view_id, | 31 Id view_id, |
| 31 const gfx::Rect& bounds) { | 32 const gfx::Rect& bounds) { |
| 32 // We don't use the ctor that takes a ViewManager here, since it will call | 33 // We don't use the ctor that takes a ViewManager here, since it will call |
| 33 // back to the service and attempt to create a new node. | 34 // back to the service and attempt to create a new node. |
| 34 ViewTreeNode* node = ViewTreeNodePrivate::LocalCreate(); | 35 ViewTreeNode* node = ViewTreeNodePrivate::LocalCreate(); |
| 35 ViewTreeNodePrivate private_node(node); | 36 ViewTreeNodePrivate private_node(node); |
| 36 private_node.set_view_manager(manager); | 37 private_node.set_view_manager(manager); |
| 37 private_node.set_id(node_id); | 38 private_node.set_id(node_id); |
| 38 private_node.LocalSetBounds(gfx::Rect(), bounds); | 39 private_node.LocalSetBounds(gfx::Rect(), bounds); |
| 39 if (parent) | 40 if (parent) |
| 40 ViewTreeNodePrivate(parent).LocalAddChild(node); | 41 ViewTreeNodePrivate(parent).LocalAddChild(node); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 // Overridden to perform transaction-specific commit actions. | 125 // Overridden to perform transaction-specific commit actions. |
| 125 virtual void DoCommit() = 0; | 126 virtual void DoCommit() = 0; |
| 126 | 127 |
| 127 // Overridden to perform transaction-specific cleanup on commit ack from the | 128 // Overridden to perform transaction-specific cleanup on commit ack from the |
| 128 // service. | 129 // service. |
| 129 virtual void DoActionCompleted(bool success) = 0; | 130 virtual void DoActionCompleted(bool success) = 0; |
| 130 | 131 |
| 131 IViewManager* service() { return synchronizer_->service_; } | 132 IViewManager* service() { return synchronizer_->service_; } |
| 132 | 133 |
| 133 TransportChangeId GetAndAdvanceNextServerChangeId() { | 134 Id GetAndAdvanceNextServerChangeId() { |
| 134 return synchronizer_->next_server_change_id_++; | 135 return synchronizer_->next_server_change_id_++; |
| 135 } | 136 } |
| 136 | 137 |
| 137 base::Callback<void(bool)> ActionCompletedCallback() { | 138 base::Callback<void(bool)> ActionCompletedCallback() { |
| 138 return base::Bind(&ViewManagerTransaction::OnActionCompleted, | 139 return base::Bind(&ViewManagerTransaction::OnActionCompleted, |
| 139 base::Unretained(this)); | 140 base::Unretained(this)); |
| 140 } | 141 } |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 // General callback to be used for commits to the service. | 144 // General callback to be used for commits to the service. |
| 144 void OnActionCompleted(bool success) { | 145 void OnActionCompleted(bool success) { |
| 145 DCHECK(success); | 146 DCHECK(success); |
| 146 DoActionCompleted(success); | 147 DoActionCompleted(success); |
| 147 synchronizer_->RemoveFromPendingQueue(this); | 148 synchronizer_->RemoveFromPendingQueue(this); |
| 148 } | 149 } |
| 149 | 150 |
| 150 const TransactionType transaction_type_; | 151 const TransactionType transaction_type_; |
| 151 bool committed_; | 152 bool committed_; |
| 152 ViewManagerSynchronizer* synchronizer_; | 153 ViewManagerSynchronizer* synchronizer_; |
| 153 | 154 |
| 154 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); | 155 DISALLOW_COPY_AND_ASSIGN(ViewManagerTransaction); |
| 155 }; | 156 }; |
| 156 | 157 |
| 157 class CreateViewTransaction : public ViewManagerTransaction { | 158 class CreateViewTransaction : public ViewManagerTransaction { |
| 158 public: | 159 public: |
| 159 CreateViewTransaction(TransportViewId view_id, | 160 CreateViewTransaction(Id view_id, ViewManagerSynchronizer* synchronizer) |
| 160 ViewManagerSynchronizer* synchronizer) | |
| 161 : ViewManagerTransaction(TYPE_CREATE_VIEW, synchronizer), | 161 : ViewManagerTransaction(TYPE_CREATE_VIEW, synchronizer), |
| 162 view_id_(view_id) {} | 162 view_id_(view_id) {} |
| 163 virtual ~CreateViewTransaction() {} | 163 virtual ~CreateViewTransaction() {} |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 // Overridden from ViewManagerTransaction: | 166 // Overridden from ViewManagerTransaction: |
| 167 virtual void DoCommit() OVERRIDE { | 167 virtual void DoCommit() OVERRIDE { |
| 168 service()->CreateView(view_id_, ActionCompletedCallback()); | 168 service()->CreateView(view_id_, ActionCompletedCallback()); |
| 169 } | 169 } |
| 170 virtual void DoActionCompleted(bool success) OVERRIDE { | 170 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 171 // TODO(beng): failure. | 171 // TODO(beng): failure. |
| 172 } | 172 } |
| 173 | 173 |
| 174 const TransportViewId view_id_; | 174 const Id view_id_; |
| 175 | 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(CreateViewTransaction); | 176 DISALLOW_COPY_AND_ASSIGN(CreateViewTransaction); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 class DestroyViewTransaction : public ViewManagerTransaction { | 179 class DestroyViewTransaction : public ViewManagerTransaction { |
| 180 public: | 180 public: |
| 181 DestroyViewTransaction(TransportViewId view_id, | 181 DestroyViewTransaction(Id view_id, ViewManagerSynchronizer* synchronizer) |
| 182 ViewManagerSynchronizer* synchronizer) | |
| 183 : ViewManagerTransaction(TYPE_DESTROY_VIEW, synchronizer), | 182 : ViewManagerTransaction(TYPE_DESTROY_VIEW, synchronizer), |
| 184 view_id_(view_id) {} | 183 view_id_(view_id) {} |
| 185 virtual ~DestroyViewTransaction() {} | 184 virtual ~DestroyViewTransaction() {} |
| 186 | 185 |
| 187 private: | 186 private: |
| 188 // Overridden from ViewManagerTransaction: | 187 // Overridden from ViewManagerTransaction: |
| 189 virtual void DoCommit() OVERRIDE { | 188 virtual void DoCommit() OVERRIDE { |
| 190 service()->DeleteView(view_id_, ActionCompletedCallback()); | 189 service()->DeleteView(view_id_, ActionCompletedCallback()); |
| 191 } | 190 } |
| 192 virtual void DoActionCompleted(bool success) OVERRIDE { | 191 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 193 // TODO(beng): recovery? | 192 // TODO(beng): recovery? |
| 194 } | 193 } |
| 195 | 194 |
| 196 const TransportViewId view_id_; | 195 const Id view_id_; |
| 197 | 196 |
| 198 DISALLOW_COPY_AND_ASSIGN(DestroyViewTransaction); | 197 DISALLOW_COPY_AND_ASSIGN(DestroyViewTransaction); |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 class CreateViewTreeNodeTransaction : public ViewManagerTransaction { | 200 class CreateViewTreeNodeTransaction : public ViewManagerTransaction { |
| 202 public: | 201 public: |
| 203 CreateViewTreeNodeTransaction(TransportNodeId node_id, | 202 CreateViewTreeNodeTransaction(Id node_id, |
| 204 ViewManagerSynchronizer* synchronizer) | 203 ViewManagerSynchronizer* synchronizer) |
| 205 : ViewManagerTransaction(TYPE_CREATE_VIEW_TREE_NODE, synchronizer), | 204 : ViewManagerTransaction(TYPE_CREATE_VIEW_TREE_NODE, synchronizer), |
| 206 node_id_(node_id) {} | 205 node_id_(node_id) {} |
| 207 virtual ~CreateViewTreeNodeTransaction() {} | 206 virtual ~CreateViewTreeNodeTransaction() {} |
| 208 | 207 |
| 209 private: | 208 private: |
| 210 // Overridden from ViewManagerTransaction: | 209 // Overridden from ViewManagerTransaction: |
| 211 virtual void DoCommit() OVERRIDE { | 210 virtual void DoCommit() OVERRIDE { |
| 212 service()->CreateNode(node_id_, ActionCompletedCallback()); | 211 service()->CreateNode(node_id_, ActionCompletedCallback()); |
| 213 } | 212 } |
| 214 virtual void DoActionCompleted(bool success) OVERRIDE { | 213 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 215 // TODO(beng): Failure means we tried to create with an extant id for this | 214 // TODO(beng): Failure means we tried to create with an extant id for this |
| 216 // connection. It also could mean we tried to do something | 215 // connection. It also could mean we tried to do something |
| 217 // invalid, or we tried applying a change out of order. Figure | 216 // invalid, or we tried applying a change out of order. Figure |
| 218 // out what to do. | 217 // out what to do. |
| 219 } | 218 } |
| 220 | 219 |
| 221 const TransportNodeId node_id_; | 220 const Id node_id_; |
| 222 | 221 |
| 223 DISALLOW_COPY_AND_ASSIGN(CreateViewTreeNodeTransaction); | 222 DISALLOW_COPY_AND_ASSIGN(CreateViewTreeNodeTransaction); |
| 224 }; | 223 }; |
| 225 | 224 |
| 226 class DestroyViewTreeNodeTransaction : public ViewManagerTransaction { | 225 class DestroyViewTreeNodeTransaction : public ViewManagerTransaction { |
| 227 public: | 226 public: |
| 228 DestroyViewTreeNodeTransaction(TransportNodeId node_id, | 227 DestroyViewTreeNodeTransaction(Id node_id, |
| 229 ViewManagerSynchronizer* synchronizer) | 228 ViewManagerSynchronizer* synchronizer) |
| 230 : ViewManagerTransaction(TYPE_DESTROY_VIEW_TREE_NODE, synchronizer), | 229 : ViewManagerTransaction(TYPE_DESTROY_VIEW_TREE_NODE, synchronizer), |
| 231 node_id_(node_id) {} | 230 node_id_(node_id) {} |
| 232 virtual ~DestroyViewTreeNodeTransaction() {} | 231 virtual ~DestroyViewTreeNodeTransaction() {} |
| 233 | 232 |
| 234 private: | 233 private: |
| 235 // Overridden from ViewManagerTransaction: | 234 // Overridden from ViewManagerTransaction: |
| 236 virtual void DoCommit() OVERRIDE { | 235 virtual void DoCommit() OVERRIDE { |
| 237 GetAndAdvanceNextServerChangeId(); | 236 GetAndAdvanceNextServerChangeId(); |
| 238 service()->DeleteNode(node_id_, ActionCompletedCallback()); | 237 service()->DeleteNode(node_id_, ActionCompletedCallback()); |
| 239 } | 238 } |
| 240 virtual void DoActionCompleted(bool success) OVERRIDE { | 239 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 241 // TODO(beng): recovery? | 240 // TODO(beng): recovery? |
| 242 } | 241 } |
| 243 | 242 |
| 244 const TransportNodeId node_id_; | 243 const Id node_id_; |
| 245 DISALLOW_COPY_AND_ASSIGN(DestroyViewTreeNodeTransaction); | 244 DISALLOW_COPY_AND_ASSIGN(DestroyViewTreeNodeTransaction); |
| 246 }; | 245 }; |
| 247 | 246 |
| 248 class HierarchyTransaction : public ViewManagerTransaction { | 247 class HierarchyTransaction : public ViewManagerTransaction { |
| 249 public: | 248 public: |
| 250 enum HierarchyChangeType { | 249 enum HierarchyChangeType { |
| 251 TYPE_ADD, | 250 TYPE_ADD, |
| 252 TYPE_REMOVE | 251 TYPE_REMOVE |
| 253 }; | 252 }; |
| 254 HierarchyTransaction(HierarchyChangeType hierarchy_change_type, | 253 HierarchyTransaction(HierarchyChangeType hierarchy_change_type, |
| 255 TransportNodeId child_id, | 254 Id child_id, |
| 256 TransportNodeId parent_id, | 255 Id parent_id, |
| 257 ViewManagerSynchronizer* synchronizer) | 256 ViewManagerSynchronizer* synchronizer) |
| 258 : ViewManagerTransaction(TYPE_HIERARCHY, synchronizer), | 257 : ViewManagerTransaction(TYPE_HIERARCHY, synchronizer), |
| 259 hierarchy_change_type_(hierarchy_change_type), | 258 hierarchy_change_type_(hierarchy_change_type), |
| 260 child_id_(child_id), | 259 child_id_(child_id), |
| 261 parent_id_(parent_id) {} | 260 parent_id_(parent_id) {} |
| 262 virtual ~HierarchyTransaction() {} | 261 virtual ~HierarchyTransaction() {} |
| 263 | 262 |
| 264 private: | 263 private: |
| 265 // Overridden from ViewManagerTransaction: | 264 // Overridden from ViewManagerTransaction: |
| 266 virtual void DoCommit() OVERRIDE { | 265 virtual void DoCommit() OVERRIDE { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 280 break; | 279 break; |
| 281 } | 280 } |
| 282 } | 281 } |
| 283 | 282 |
| 284 virtual void DoActionCompleted(bool success) OVERRIDE { | 283 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 285 // TODO(beng): Failure means either one of the nodes specified didn't exist, | 284 // TODO(beng): Failure means either one of the nodes specified didn't exist, |
| 286 // or we passed the same node id for both params. Roll back? | 285 // or we passed the same node id for both params. Roll back? |
| 287 } | 286 } |
| 288 | 287 |
| 289 const HierarchyChangeType hierarchy_change_type_; | 288 const HierarchyChangeType hierarchy_change_type_; |
| 290 const TransportNodeId child_id_; | 289 const Id child_id_; |
| 291 const TransportNodeId parent_id_; | 290 const Id parent_id_; |
| 292 | 291 |
| 293 DISALLOW_COPY_AND_ASSIGN(HierarchyTransaction); | 292 DISALLOW_COPY_AND_ASSIGN(HierarchyTransaction); |
| 294 }; | 293 }; |
| 295 | 294 |
| 296 class SetActiveViewTransaction : public ViewManagerTransaction { | 295 class SetActiveViewTransaction : public ViewManagerTransaction { |
| 297 public: | 296 public: |
| 298 SetActiveViewTransaction(TransportNodeId node_id, | 297 SetActiveViewTransaction(Id node_id, |
| 299 TransportViewId view_id, | 298 Id view_id, |
| 300 ViewManagerSynchronizer* synchronizer) | 299 ViewManagerSynchronizer* synchronizer) |
| 301 : ViewManagerTransaction(TYPE_SET_ACTIVE_VIEW, synchronizer), | 300 : ViewManagerTransaction(TYPE_SET_ACTIVE_VIEW, synchronizer), |
| 302 node_id_(node_id), | 301 node_id_(node_id), |
| 303 view_id_(view_id) {} | 302 view_id_(view_id) {} |
| 304 virtual ~SetActiveViewTransaction() {} | 303 virtual ~SetActiveViewTransaction() {} |
| 305 | 304 |
| 306 private: | 305 private: |
| 307 // Overridden from ViewManagerTransaction: | 306 // Overridden from ViewManagerTransaction: |
| 308 virtual void DoCommit() OVERRIDE { | 307 virtual void DoCommit() OVERRIDE { |
| 309 service()->SetView(node_id_, view_id_, ActionCompletedCallback()); | 308 service()->SetView(node_id_, view_id_, ActionCompletedCallback()); |
| 310 } | 309 } |
| 311 virtual void DoActionCompleted(bool success) OVERRIDE { | 310 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 312 // TODO(beng): recovery? | 311 // TODO(beng): recovery? |
| 313 } | 312 } |
| 314 | 313 |
| 315 const TransportNodeId node_id_; | 314 const Id node_id_; |
| 316 const TransportViewId view_id_; | 315 const Id view_id_; |
| 317 | 316 |
| 318 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); | 317 DISALLOW_COPY_AND_ASSIGN(SetActiveViewTransaction); |
| 319 }; | 318 }; |
| 320 | 319 |
| 321 class SetBoundsTransaction : public ViewManagerTransaction { | 320 class SetBoundsTransaction : public ViewManagerTransaction { |
| 322 public: | 321 public: |
| 323 SetBoundsTransaction(TransportNodeId node_id, | 322 SetBoundsTransaction(Id node_id, |
| 324 const gfx::Rect& bounds, | 323 const gfx::Rect& bounds, |
| 325 ViewManagerSynchronizer* synchronizer) | 324 ViewManagerSynchronizer* synchronizer) |
| 326 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), | 325 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), |
| 327 node_id_(node_id), | 326 node_id_(node_id), |
| 328 bounds_(bounds) {} | 327 bounds_(bounds) {} |
| 329 virtual ~SetBoundsTransaction() {} | 328 virtual ~SetBoundsTransaction() {} |
| 330 | 329 |
| 331 private: | 330 private: |
| 332 // Overridden from ViewManagerTransaction: | 331 // Overridden from ViewManagerTransaction: |
| 333 virtual void DoCommit() OVERRIDE { | 332 virtual void DoCommit() OVERRIDE { |
| 334 service()->SetNodeBounds( | 333 service()->SetNodeBounds( |
| 335 node_id_, Rect::From(bounds_), ActionCompletedCallback()); | 334 node_id_, Rect::From(bounds_), ActionCompletedCallback()); |
| 336 } | 335 } |
| 337 virtual void DoActionCompleted(bool success) OVERRIDE { | 336 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 338 // TODO(beng): recovery? | 337 // TODO(beng): recovery? |
| 339 } | 338 } |
| 340 | 339 |
| 341 const TransportNodeId node_id_; | 340 const Id node_id_; |
| 342 const gfx::Rect bounds_; | 341 const gfx::Rect bounds_; |
| 343 | 342 |
| 344 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); | 343 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); |
| 345 }; | 344 }; |
| 346 | 345 |
| 347 class SetViewContentsTransaction : public ViewManagerTransaction { | 346 class SetViewContentsTransaction : public ViewManagerTransaction { |
| 348 public: | 347 public: |
| 349 SetViewContentsTransaction(TransportViewId view_id, | 348 SetViewContentsTransaction(Id view_id, |
| 350 const SkBitmap& contents, | 349 const SkBitmap& contents, |
| 351 ViewManagerSynchronizer* synchronizer) | 350 ViewManagerSynchronizer* synchronizer) |
| 352 : ViewManagerTransaction(TYPE_SET_VIEW_CONTENTS, synchronizer), | 351 : ViewManagerTransaction(TYPE_SET_VIEW_CONTENTS, synchronizer), |
| 353 view_id_(view_id), | 352 view_id_(view_id), |
| 354 contents_(contents) {} | 353 contents_(contents) {} |
| 355 virtual ~SetViewContentsTransaction() {} | 354 virtual ~SetViewContentsTransaction() {} |
| 356 | 355 |
| 357 private: | 356 private: |
| 358 // Overridden from ViewManagerTransaction: | 357 // Overridden from ViewManagerTransaction: |
| 359 virtual void DoCommit() OVERRIDE { | 358 virtual void DoCommit() OVERRIDE { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 394 |
| 396 result = MapBuffer( | 395 result = MapBuffer( |
| 397 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); | 396 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); |
| 398 if (result != MOJO_RESULT_OK) | 397 if (result != MOJO_RESULT_OK) |
| 399 return false; | 398 return false; |
| 400 DCHECK(*memory); | 399 DCHECK(*memory); |
| 401 | 400 |
| 402 return true; | 401 return true; |
| 403 } | 402 } |
| 404 | 403 |
| 405 const TransportViewId view_id_; | 404 const Id view_id_; |
| 406 const SkBitmap contents_; | 405 const SkBitmap contents_; |
| 407 ScopedSharedBufferHandle shared_state_handle_; | 406 ScopedSharedBufferHandle shared_state_handle_; |
| 408 | 407 |
| 409 DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction); | 408 DISALLOW_COPY_AND_ASSIGN(SetViewContentsTransaction); |
| 410 }; | 409 }; |
| 411 | 410 |
| 412 class EmbedTransaction : public ViewManagerTransaction { | 411 class EmbedTransaction : public ViewManagerTransaction { |
| 413 public: | 412 public: |
| 414 EmbedTransaction(const String& url, | 413 EmbedTransaction(const String& url, |
| 415 TransportNodeId node_id, | 414 Id node_id, |
| 416 ViewManagerSynchronizer* synchronizer) | 415 ViewManagerSynchronizer* synchronizer) |
| 417 : ViewManagerTransaction(TYPE_EMBED, synchronizer), | 416 : ViewManagerTransaction(TYPE_EMBED, synchronizer), |
| 418 url_(url), | 417 url_(url), |
| 419 node_id_(node_id) {} | 418 node_id_(node_id) {} |
| 420 virtual ~EmbedTransaction() {} | 419 virtual ~EmbedTransaction() {} |
| 421 | 420 |
| 422 private: | 421 private: |
| 423 // Overridden from ViewManagerTransaction: | 422 // Overridden from ViewManagerTransaction: |
| 424 virtual void DoCommit() OVERRIDE { | 423 virtual void DoCommit() OVERRIDE { |
| 425 std::vector<TransportNodeId> ids; | 424 std::vector<Id> ids; |
| 426 ids.push_back(node_id_); | 425 ids.push_back(node_id_); |
| 427 service()->Connect(url_, Array<TransportNodeId>::From(ids), | 426 service()->Connect(url_, Array<Id>::From(ids), |
| 428 ActionCompletedCallback()); | 427 ActionCompletedCallback()); |
| 429 } | 428 } |
| 430 virtual void DoActionCompleted(bool success) OVERRIDE { | 429 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 431 // TODO(beng): recovery? | 430 // TODO(beng): recovery? |
| 432 } | 431 } |
| 433 | 432 |
| 434 const String url_; | 433 const String url_; |
| 435 const TransportNodeId node_id_; | 434 const Id node_id_; |
| 436 | 435 |
| 437 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); | 436 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); |
| 438 }; | 437 }; |
| 439 | 438 |
| 440 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManagerDelegate* delegate) | 439 ViewManagerSynchronizer::ViewManagerSynchronizer(ViewManagerDelegate* delegate) |
| 441 : view_manager_(new ViewManager(this, delegate)), | 440 : view_manager_(new ViewManager(this, delegate)), |
| 442 connected_(false), | 441 connected_(false), |
| 443 connection_id_(0), | 442 connection_id_(0), |
| 444 next_id_(1), | 443 next_id_(1), |
| 445 next_server_change_id_(0), | 444 next_server_change_id_(0), |
| 446 sync_factory_(this) { | 445 sync_factory_(this) { |
| 447 } | 446 } |
| 448 | 447 |
| 449 ViewManagerSynchronizer::~ViewManagerSynchronizer() { | 448 ViewManagerSynchronizer::~ViewManagerSynchronizer() { |
| 450 } | 449 } |
| 451 | 450 |
| 452 TransportNodeId ViewManagerSynchronizer::CreateViewTreeNode() { | 451 Id ViewManagerSynchronizer::CreateViewTreeNode() { |
| 453 DCHECK(connected_); | 452 DCHECK(connected_); |
| 454 const TransportNodeId node_id( | 453 const Id node_id(MakeTransportId(connection_id_, ++next_id_)); |
| 455 MakeTransportId(connection_id_, ++next_id_)); | |
| 456 pending_transactions_.push_back( | 454 pending_transactions_.push_back( |
| 457 new CreateViewTreeNodeTransaction(node_id, this)); | 455 new CreateViewTreeNodeTransaction(node_id, this)); |
| 458 Sync(); | 456 Sync(); |
| 459 return node_id; | 457 return node_id; |
| 460 } | 458 } |
| 461 | 459 |
| 462 void ViewManagerSynchronizer::DestroyViewTreeNode(TransportNodeId node_id) { | 460 void ViewManagerSynchronizer::DestroyViewTreeNode(Id node_id) { |
| 463 DCHECK(connected_); | 461 DCHECK(connected_); |
| 464 pending_transactions_.push_back( | 462 pending_transactions_.push_back( |
| 465 new DestroyViewTreeNodeTransaction(node_id, this)); | 463 new DestroyViewTreeNodeTransaction(node_id, this)); |
| 466 Sync(); | 464 Sync(); |
| 467 } | 465 } |
| 468 | 466 |
| 469 TransportViewId ViewManagerSynchronizer::CreateView() { | 467 Id ViewManagerSynchronizer::CreateView() { |
| 470 DCHECK(connected_); | 468 DCHECK(connected_); |
| 471 const TransportNodeId view_id( | 469 const Id view_id(MakeTransportId(connection_id_, ++next_id_)); |
| 472 MakeTransportId(connection_id_, ++next_id_)); | |
| 473 pending_transactions_.push_back(new CreateViewTransaction(view_id, this)); | 470 pending_transactions_.push_back(new CreateViewTransaction(view_id, this)); |
| 474 Sync(); | 471 Sync(); |
| 475 return view_id; | 472 return view_id; |
| 476 } | 473 } |
| 477 | 474 |
| 478 void ViewManagerSynchronizer::DestroyView(TransportViewId view_id) { | 475 void ViewManagerSynchronizer::DestroyView(Id view_id) { |
| 479 DCHECK(connected_); | 476 DCHECK(connected_); |
| 480 pending_transactions_.push_back(new DestroyViewTransaction(view_id, this)); | 477 pending_transactions_.push_back(new DestroyViewTransaction(view_id, this)); |
| 481 Sync(); | 478 Sync(); |
| 482 } | 479 } |
| 483 | 480 |
| 484 void ViewManagerSynchronizer::AddChild(TransportNodeId child_id, | 481 void ViewManagerSynchronizer::AddChild(Id child_id, |
| 485 TransportNodeId parent_id) { | 482 Id parent_id) { |
| 486 DCHECK(connected_); | 483 DCHECK(connected_); |
| 487 pending_transactions_.push_back( | 484 pending_transactions_.push_back( |
| 488 new HierarchyTransaction(HierarchyTransaction::TYPE_ADD, | 485 new HierarchyTransaction(HierarchyTransaction::TYPE_ADD, |
| 489 child_id, | 486 child_id, |
| 490 parent_id, | 487 parent_id, |
| 491 this)); | 488 this)); |
| 492 Sync(); | 489 Sync(); |
| 493 } | 490 } |
| 494 | 491 |
| 495 void ViewManagerSynchronizer::RemoveChild(TransportNodeId child_id, | 492 void ViewManagerSynchronizer::RemoveChild(Id child_id, Id parent_id) { |
| 496 TransportNodeId parent_id) { | |
| 497 DCHECK(connected_); | 493 DCHECK(connected_); |
| 498 pending_transactions_.push_back( | 494 pending_transactions_.push_back( |
| 499 new HierarchyTransaction(HierarchyTransaction::TYPE_REMOVE, | 495 new HierarchyTransaction(HierarchyTransaction::TYPE_REMOVE, |
| 500 child_id, | 496 child_id, |
| 501 parent_id, | 497 parent_id, |
| 502 this)); | 498 this)); |
| 503 Sync(); | 499 Sync(); |
| 504 } | 500 } |
| 505 | 501 |
| 506 bool ViewManagerSynchronizer::OwnsNode(TransportNodeId id) const { | 502 bool ViewManagerSynchronizer::OwnsNode(Id id) const { |
| 507 return HiWord(id) == connection_id_; | 503 return HiWord(id) == connection_id_; |
| 508 } | 504 } |
| 509 | 505 |
| 510 bool ViewManagerSynchronizer::OwnsView(TransportViewId id) const { | 506 bool ViewManagerSynchronizer::OwnsView(Id id) const { |
| 511 return HiWord(id) == connection_id_; | 507 return HiWord(id) == connection_id_; |
| 512 } | 508 } |
| 513 | 509 |
| 514 void ViewManagerSynchronizer::SetActiveView(TransportNodeId node_id, | 510 void ViewManagerSynchronizer::SetActiveView(Id node_id, Id view_id) { |
| 515 TransportViewId view_id) { | |
| 516 DCHECK(connected_); | 511 DCHECK(connected_); |
| 517 pending_transactions_.push_back( | 512 pending_transactions_.push_back( |
| 518 new SetActiveViewTransaction(node_id, view_id, this)); | 513 new SetActiveViewTransaction(node_id, view_id, this)); |
| 519 Sync(); | 514 Sync(); |
| 520 } | 515 } |
| 521 | 516 |
| 522 void ViewManagerSynchronizer::SetBounds(TransportNodeId node_id, | 517 void ViewManagerSynchronizer::SetBounds(Id node_id, const gfx::Rect& bounds) { |
| 523 const gfx::Rect& bounds) { | |
| 524 DCHECK(connected_); | 518 DCHECK(connected_); |
| 525 pending_transactions_.push_back( | 519 pending_transactions_.push_back( |
| 526 new SetBoundsTransaction(node_id, bounds, this)); | 520 new SetBoundsTransaction(node_id, bounds, this)); |
| 527 Sync(); | 521 Sync(); |
| 528 } | 522 } |
| 529 | 523 |
| 530 void ViewManagerSynchronizer::SetViewContents(TransportViewId view_id, | 524 void ViewManagerSynchronizer::SetViewContents(Id view_id, |
| 531 const SkBitmap& contents) { | 525 const SkBitmap& contents) { |
| 532 DCHECK(connected_); | 526 DCHECK(connected_); |
| 533 pending_transactions_.push_back( | 527 pending_transactions_.push_back( |
| 534 new SetViewContentsTransaction(view_id, contents, this)); | 528 new SetViewContentsTransaction(view_id, contents, this)); |
| 535 Sync(); | 529 Sync(); |
| 536 } | 530 } |
| 537 | 531 |
| 538 void ViewManagerSynchronizer::Embed(const String& url, | 532 void ViewManagerSynchronizer::Embed(const String& url, Id node_id) { |
| 539 TransportNodeId node_id) { | |
| 540 DCHECK(connected_); | 533 DCHECK(connected_); |
| 541 pending_transactions_.push_back(new EmbedTransaction(url, node_id, this)); | 534 pending_transactions_.push_back(new EmbedTransaction(url, node_id, this)); |
| 542 Sync(); | 535 Sync(); |
| 543 } | 536 } |
| 544 | 537 |
| 545 //////////////////////////////////////////////////////////////////////////////// | 538 //////////////////////////////////////////////////////////////////////////////// |
| 546 // ViewManagerSynchronizer, InterfaceImpl overrides: | 539 // ViewManagerSynchronizer, InterfaceImpl overrides: |
| 547 | 540 |
| 548 void ViewManagerSynchronizer::OnConnectionEstablished() { | 541 void ViewManagerSynchronizer::OnConnectionEstablished() { |
| 549 service_ = client(); | 542 service_ = client(); |
| 550 } | 543 } |
| 551 | 544 |
| 552 //////////////////////////////////////////////////////////////////////////////// | 545 //////////////////////////////////////////////////////////////////////////////// |
| 553 // ViewManagerSynchronizer, IViewManagerClient implementation: | 546 // ViewManagerSynchronizer, IViewManagerClient implementation: |
| 554 | 547 |
| 555 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( | 548 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( |
| 556 TransportConnectionId connection_id, | 549 ConnectionSpecificId connection_id, |
| 557 TransportChangeId next_server_change_id, | 550 Id next_server_change_id, |
| 558 mojo::Array<INodePtr> nodes) { | 551 mojo::Array<INodePtr> nodes) { |
| 559 connected_ = true; | 552 connected_ = true; |
| 560 connection_id_ = connection_id; | 553 connection_id_ = connection_id; |
| 561 next_server_change_id_ = next_server_change_id; | 554 next_server_change_id_ = next_server_change_id; |
| 562 | 555 |
| 563 DCHECK(pending_transactions_.empty()); | 556 DCHECK(pending_transactions_.empty()); |
| 564 ViewManagerPrivate private_manager(view_manager()); | 557 ViewManagerPrivate private_manager(view_manager()); |
| 565 private_manager.AddRoot(BuildNodeTree(view_manager(), nodes)); | 558 private_manager.AddRoot(BuildNodeTree(view_manager(), nodes)); |
| 566 } | 559 } |
| 567 | 560 |
| 568 void ViewManagerSynchronizer::OnRootsAdded(Array<INodePtr> nodes) { | 561 void ViewManagerSynchronizer::OnRootsAdded(Array<INodePtr> nodes) { |
| 569 ViewManagerPrivate private_manager(view_manager()); | 562 ViewManagerPrivate private_manager(view_manager()); |
| 570 private_manager.AddRoot(BuildNodeTree(view_manager(), nodes)); | 563 private_manager.AddRoot(BuildNodeTree(view_manager(), nodes)); |
| 571 } | 564 } |
| 572 | 565 |
| 573 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( | 566 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( |
| 574 uint32_t next_server_change_id) { | 567 Id next_server_change_id) { |
| 575 next_server_change_id_ = next_server_change_id; | 568 next_server_change_id_ = next_server_change_id; |
| 576 } | 569 } |
| 577 | 570 |
| 578 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id, | 571 void ViewManagerSynchronizer::OnNodeBoundsChanged(Id node_id, |
| 579 RectPtr old_bounds, | 572 RectPtr old_bounds, |
| 580 RectPtr new_bounds) { | 573 RectPtr new_bounds) { |
| 581 ViewTreeNode* node = view_manager()->GetNodeById(node_id); | 574 ViewTreeNode* node = view_manager()->GetNodeById(node_id); |
| 582 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), | 575 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), |
| 583 new_bounds.To<gfx::Rect>()); | 576 new_bounds.To<gfx::Rect>()); |
| 584 } | 577 } |
| 585 | 578 |
| 586 void ViewManagerSynchronizer::OnNodeHierarchyChanged( | 579 void ViewManagerSynchronizer::OnNodeHierarchyChanged( |
| 587 uint32_t node_id, | 580 Id node_id, |
| 588 uint32_t new_parent_id, | 581 Id new_parent_id, |
| 589 uint32_t old_parent_id, | 582 Id old_parent_id, |
| 590 TransportChangeId server_change_id, | 583 Id server_change_id, |
| 591 mojo::Array<INodePtr> nodes) { | 584 mojo::Array<INodePtr> nodes) { |
| 592 // TODO: deal with |nodes|. | 585 // TODO: deal with |nodes|. |
| 593 next_server_change_id_ = server_change_id + 1; | 586 next_server_change_id_ = server_change_id + 1; |
| 594 | 587 |
| 595 BuildNodeTree(view_manager(), nodes); | 588 BuildNodeTree(view_manager(), nodes); |
| 596 | 589 |
| 597 ViewTreeNode* new_parent = view_manager()->GetNodeById(new_parent_id); | 590 ViewTreeNode* new_parent = view_manager()->GetNodeById(new_parent_id); |
| 598 ViewTreeNode* old_parent = view_manager()->GetNodeById(old_parent_id); | 591 ViewTreeNode* old_parent = view_manager()->GetNodeById(old_parent_id); |
| 599 ViewTreeNode* node = view_manager()->GetNodeById(node_id); | 592 ViewTreeNode* node = view_manager()->GetNodeById(node_id); |
| 600 if (new_parent) | 593 if (new_parent) |
| 601 ViewTreeNodePrivate(new_parent).LocalAddChild(node); | 594 ViewTreeNodePrivate(new_parent).LocalAddChild(node); |
| 602 else | 595 else |
| 603 ViewTreeNodePrivate(old_parent).LocalRemoveChild(node); | 596 ViewTreeNodePrivate(old_parent).LocalRemoveChild(node); |
| 604 } | 597 } |
| 605 | 598 |
| 606 void ViewManagerSynchronizer::OnNodeDeleted(uint32_t node_id, | 599 void ViewManagerSynchronizer::OnNodeDeleted(Id node_id, Id server_change_id) { |
| 607 uint32_t server_change_id) { | |
| 608 next_server_change_id_ = server_change_id + 1; | 600 next_server_change_id_ = server_change_id + 1; |
| 609 | 601 |
| 610 ViewTreeNode* node = view_manager()->GetNodeById(node_id); | 602 ViewTreeNode* node = view_manager()->GetNodeById(node_id); |
| 611 if (node) | 603 if (node) |
| 612 ViewTreeNodePrivate(node).LocalDestroy(); | 604 ViewTreeNodePrivate(node).LocalDestroy(); |
| 613 } | 605 } |
| 614 | 606 |
| 615 void ViewManagerSynchronizer::OnNodeViewReplaced(uint32_t node_id, | 607 void ViewManagerSynchronizer::OnNodeViewReplaced(Id node_id, |
| 616 uint32_t new_view_id, | 608 Id new_view_id, |
| 617 uint32_t old_view_id) { | 609 Id old_view_id) { |
| 618 ViewTreeNode* node = view_manager()->GetNodeById(node_id); | 610 ViewTreeNode* node = view_manager()->GetNodeById(node_id); |
| 619 View* new_view = view_manager()->GetViewById(new_view_id); | 611 View* new_view = view_manager()->GetViewById(new_view_id); |
| 620 if (!new_view && new_view_id != 0) { | 612 if (!new_view && new_view_id != 0) { |
| 621 // This client wasn't aware of this View until now. | 613 // This client wasn't aware of this View until now. |
| 622 new_view = ViewPrivate::LocalCreate(); | 614 new_view = ViewPrivate::LocalCreate(); |
| 623 ViewPrivate private_view(new_view); | 615 ViewPrivate private_view(new_view); |
| 624 private_view.set_view_manager(view_manager()); | 616 private_view.set_view_manager(view_manager()); |
| 625 private_view.set_id(new_view_id); | 617 private_view.set_id(new_view_id); |
| 626 private_view.set_node(node); | 618 private_view.set_node(node); |
| 627 ViewManagerPrivate(view_manager()).AddView(new_view->id(), new_view); | 619 ViewManagerPrivate(view_manager()).AddView(new_view->id(), new_view); |
| 628 } | 620 } |
| 629 View* old_view = view_manager()->GetViewById(old_view_id); | 621 View* old_view = view_manager()->GetViewById(old_view_id); |
| 630 DCHECK_EQ(old_view, node->active_view()); | 622 DCHECK_EQ(old_view, node->active_view()); |
| 631 ViewTreeNodePrivate(node).LocalSetActiveView(new_view); | 623 ViewTreeNodePrivate(node).LocalSetActiveView(new_view); |
| 632 } | 624 } |
| 633 | 625 |
| 634 void ViewManagerSynchronizer::OnViewDeleted(uint32_t view_id) { | 626 void ViewManagerSynchronizer::OnViewDeleted(Id view_id) { |
| 635 View* view = view_manager()->GetViewById(view_id); | 627 View* view = view_manager()->GetViewById(view_id); |
| 636 if (view) | 628 if (view) |
| 637 ViewPrivate(view).LocalDestroy(); | 629 ViewPrivate(view).LocalDestroy(); |
| 638 } | 630 } |
| 639 | 631 |
| 640 void ViewManagerSynchronizer::OnViewInputEvent( | 632 void ViewManagerSynchronizer::OnViewInputEvent( |
| 641 uint32_t view_id, | 633 Id view_id, |
| 642 EventPtr event, | 634 EventPtr event, |
| 643 const Callback<void()>& ack_callback) { | 635 const Callback<void()>& ack_callback) { |
| 644 View* view = view_manager_->GetViewById(view_id); | 636 View* view = view_manager_->GetViewById(view_id); |
| 645 if (view) { | 637 if (view) { |
| 646 FOR_EACH_OBSERVER(ViewObserver, | 638 FOR_EACH_OBSERVER(ViewObserver, |
| 647 *ViewPrivate(view).observers(), | 639 *ViewPrivate(view).observers(), |
| 648 OnViewInputEvent(view, event.Pass())); | 640 OnViewInputEvent(view, event.Pass())); |
| 649 } | 641 } |
| 650 ack_callback.Run(); | 642 ack_callback.Run(); |
| 651 } | 643 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 669 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 661 void ViewManagerSynchronizer::RemoveFromPendingQueue( |
| 670 ViewManagerTransaction* transaction) { | 662 ViewManagerTransaction* transaction) { |
| 671 DCHECK_EQ(transaction, pending_transactions_.front()); | 663 DCHECK_EQ(transaction, pending_transactions_.front()); |
| 672 pending_transactions_.erase(pending_transactions_.begin()); | 664 pending_transactions_.erase(pending_transactions_.begin()); |
| 673 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) | 665 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) |
| 674 changes_acked_callback_.Run(); | 666 changes_acked_callback_.Run(); |
| 675 } | 667 } |
| 676 | 668 |
| 677 } // namespace view_manager | 669 } // namespace view_manager |
| 678 } // namespace mojo | 670 } // namespace mojo |
| OLD | NEW |