OLD | NEW |
(Empty) | |
| 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 #include "mojo/services/view_manager/view_manager_init_service_context.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "mojo/services/view_manager/root_node_manager.h" |
| 9 #include "mojo/services/view_manager/view_manager_init_service_impl.h" |
| 10 |
| 11 namespace mojo { |
| 12 namespace view_manager { |
| 13 namespace service { |
| 14 |
| 15 ViewManagerInitServiceContext::ViewManagerInitServiceContext() |
| 16 : is_tree_host_ready_(false) {} |
| 17 ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {} |
| 18 |
| 19 void ViewManagerInitServiceContext::AddConnection( |
| 20 ViewManagerInitServiceImpl* connection) { |
| 21 DCHECK(std::find(connections_.begin(), connections_.end(), connection) == |
| 22 connections_.end()); |
| 23 connections_.push_back(connection); |
| 24 } |
| 25 |
| 26 void ViewManagerInitServiceContext::RemoveConnection( |
| 27 ViewManagerInitServiceImpl* connection) { |
| 28 Connections::iterator it = |
| 29 std::find(connections_.begin(), connections_.end(), connection); |
| 30 DCHECK(it != connections_.end()); |
| 31 connections_.erase(it); |
| 32 |
| 33 // This object is owned by an object that outlives the current thread's |
| 34 // message loop, so we need to destroy the RootNodeManager earlier, as it may |
| 35 // attempt to post tasks during its destruction. |
| 36 if (connections_.empty()) |
| 37 root_node_manager_.reset(); |
| 38 } |
| 39 |
| 40 void ViewManagerInitServiceContext::ConfigureIncomingConnection( |
| 41 ApplicationConnection* connection) { |
| 42 if (!root_node_manager_.get()) { |
| 43 root_node_manager_.reset(new RootNodeManager( |
| 44 connection, |
| 45 this, |
| 46 base::Bind(&ViewManagerInitServiceContext::OnNativeViewportDeleted, |
| 47 base::Unretained(this)))); |
| 48 } |
| 49 } |
| 50 |
| 51 void ViewManagerInitServiceContext::OnNativeViewportDeleted() { |
| 52 for (Connections::const_iterator it = connections_.begin(); |
| 53 it != connections_.end(); ++it) { |
| 54 (*it)->OnNativeViewportDeleted(); |
| 55 } |
| 56 } |
| 57 |
| 58 void ViewManagerInitServiceContext::OnRootViewManagerWindowTreeHostCreated() { |
| 59 DCHECK(!is_tree_host_ready_); |
| 60 is_tree_host_ready_ = true; |
| 61 for (Connections::const_iterator it = connections_.begin(); |
| 62 it != connections_.end(); ++it) { |
| 63 (*it)->OnRootViewManagerWindowTreeHostCreated(); |
| 64 } |
| 65 } |
| 66 |
| 67 } // namespace service |
| 68 } // namespace view_manager |
| 69 } // namespace mojo |
OLD | NEW |