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/view_manager/view_manager_init_service_impl.h" | 5 #include "mojo/services/view_manager/view_manager_init_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "mojo/services/view_manager/ids.h" | 8 #include "mojo/services/view_manager/ids.h" |
9 #include "mojo/services/view_manager/view_manager_init_service_context.h" | 9 #include "mojo/services/view_manager/view_manager_init_service_context.h" |
10 #include "mojo/services/view_manager/view_manager_service_impl.h" | 10 #include "mojo/services/view_manager/view_manager_service_impl.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 class ApplicationConnection; | |
14 namespace service { | 13 namespace service { |
15 | 14 |
16 ViewManagerInitServiceImpl::ConnectParams::ConnectParams() {} | |
17 | |
18 ViewManagerInitServiceImpl::ConnectParams::~ConnectParams() {} | |
19 | |
20 ViewManagerInitServiceImpl::ViewManagerInitServiceImpl( | 15 ViewManagerInitServiceImpl::ViewManagerInitServiceImpl( |
21 ApplicationConnection* connection, | 16 ApplicationConnection* connection, |
22 ViewManagerInitServiceContext* context) | 17 ViewManagerInitServiceContext* context) |
23 : context_(context) { | 18 : context_(context) { |
24 context_->AddConnection(this); | 19 context_->AddConnection(this); |
25 } | 20 } |
26 | 21 |
27 ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() { | 22 ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() { |
28 context_->RemoveConnection(this); | 23 context_->RemoveConnection(this); |
29 } | 24 } |
30 | 25 |
31 void ViewManagerInitServiceImpl::OnNativeViewportDeleted() { | |
32 delete this; | |
33 } | |
34 | |
35 void ViewManagerInitServiceImpl::OnRootViewManagerWindowTreeHostCreated() { | |
36 MaybeEmbed(); | |
37 } | |
38 | |
39 void ViewManagerInitServiceImpl::MaybeEmbed() { | |
40 if (!context_->is_tree_host_ready()) | |
41 return; | |
42 | |
43 ScopedVector<ConnectParams>::const_iterator it = connect_params_.begin(); | |
44 for (; it != connect_params_.end(); ++it) { | |
45 context_->root_node_manager()->EmbedRoot((*it)->url, | |
46 (*it)->service_provider.Pass()); | |
47 (*it)->callback.Run(true); | |
48 } | |
49 connect_params_.clear(); | |
50 } | |
51 | |
52 void ViewManagerInitServiceImpl::Embed( | 26 void ViewManagerInitServiceImpl::Embed( |
53 const String& url, | 27 const String& url, |
54 ServiceProviderPtr service_provider, | 28 ServiceProviderPtr service_provider, |
55 const Callback<void(bool)>& callback) { | 29 const Callback<void(bool)>& callback) { |
56 ConnectParams* params = new ConnectParams; | 30 context_->Embed(url, service_provider.Pass(), callback); |
57 params->url = url.To<std::string>(); | |
58 params->callback = callback; | |
59 params->service_provider.Bind(service_provider.PassMessagePipe()); | |
60 connect_params_.push_back(params); | |
61 MaybeEmbed(); | |
62 } | 31 } |
63 | 32 |
64 } // namespace service | 33 } // namespace service |
65 } // namespace mojo | 34 } // namespace mojo |
OLD | NEW |