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_impl.h" 6 7 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 8 #include "mojo/services/view_manager/ids.h" 9 #include "mojo/services/view_manager/view_manager_service_impl.h" 10 11 namespace mojo { 12 namespace view_manager { 13 namespace service { 14 ConnectParams()15ViewManagerInitServiceImpl::ConnectParams::ConnectParams() {} 16 ~ConnectParams()17ViewManagerInitServiceImpl::ConnectParams::~ConnectParams() {} 18 ViewManagerInitServiceImpl(ServiceProvider * service_provider)19ViewManagerInitServiceImpl::ViewManagerInitServiceImpl( 20 ServiceProvider* service_provider) 21 : service_provider_(service_provider), 22 root_node_manager_(service_provider, this), 23 is_tree_host_ready_(false) { 24 } 25 ~ViewManagerInitServiceImpl()26ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() { 27 } 28 MaybeEmbedRoot(const std::string & url,const Callback<void (bool)> & callback)29void ViewManagerInitServiceImpl::MaybeEmbedRoot( 30 const std::string& url, 31 const Callback<void(bool)>& callback) { 32 if (!is_tree_host_ready_) 33 return; 34 35 root_node_manager_.EmbedRoot(url); 36 callback.Run(true); 37 } 38 EmbedRoot(const String & url,const Callback<void (bool)> & callback)39void ViewManagerInitServiceImpl::EmbedRoot( 40 const String& url, 41 const Callback<void(bool)>& callback) { 42 if (connect_params_.get()) { 43 DVLOG(1) << "Ignoring second connect"; 44 callback.Run(false); 45 return; 46 } 47 connect_params_.reset(new ConnectParams); 48 connect_params_->url = url.To<std::string>(); 49 connect_params_->callback = callback; 50 MaybeEmbedRoot(url.To<std::string>(), callback); 51 } 52 OnRootViewManagerWindowTreeHostCreated()53void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() { 54 DCHECK(!is_tree_host_ready_); 55 is_tree_host_ready_ = true; 56 if (connect_params_.get()) 57 MaybeEmbedRoot(connect_params_->url, connect_params_->callback); 58 } 59 60 } // namespace service 61 } // namespace view_manager 62 } // namespace mojo 63