Commit 465c9750 authored by sky@chromium.org's avatar sky@chromium.org

Change type of interface created by mojo:view_manager

It now creates a IViewManagerInit, which has the single method Connect
to connect to the route.

As suggested I disabled all the view_manager_lib_unittests until they
are converted to new connection logic.

BUG=365012
TEST=covered by tests
R=ben@chromium.org

Review URL: https://codereview.chromium.org/308803002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273812 0039d316-1c4b-4281-b951-d872f2087c98
parent 60d677dd
...@@ -287,10 +287,13 @@ ...@@ -287,10 +287,13 @@
'services/view_manager/root_node_manager.h', 'services/view_manager/root_node_manager.h',
'services/view_manager/root_view_manager.cc', 'services/view_manager/root_view_manager.cc',
'services/view_manager/root_view_manager.h', 'services/view_manager/root_view_manager.h',
'services/view_manager/root_view_manager_delegate.h',
'services/view_manager/view.cc', 'services/view_manager/view.cc',
'services/view_manager/view.h', 'services/view_manager/view.h',
'services/view_manager/view_manager_connection.cc', 'services/view_manager/view_manager_connection.cc',
'services/view_manager/view_manager_connection.h', 'services/view_manager/view_manager_connection.h',
'services/view_manager/view_manager_init_connection.cc',
'services/view_manager/view_manager_init_connection.h',
'services/view_manager/view_manager_export.h', 'services/view_manager/view_manager_export.h',
], ],
'defines': [ 'defines': [
......
...@@ -338,7 +338,9 @@ class HierarchyChanged_NodeCreatedObserver : public TreeObserverBase { ...@@ -338,7 +338,9 @@ class HierarchyChanged_NodeCreatedObserver : public TreeObserverBase {
DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeCreatedObserver); DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeCreatedObserver);
}; };
TEST_F(ViewManagerTest, HierarchyChanged_NodeCreated) { // TODO(beng): reenable these once converted to new way of connecting.
TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeCreated) {
HierarchyChanged_NodeCreatedObserver observer(view_manager_2()); HierarchyChanged_NodeCreatedObserver observer(view_manager_2());
ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1()); ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1());
view_manager_1()->tree()->AddChild(node1); view_manager_1()->tree()->AddChild(node1);
...@@ -375,7 +377,7 @@ class HierarchyChanged_NodeMovedObserver : public TreeObserverBase { ...@@ -375,7 +377,7 @@ class HierarchyChanged_NodeMovedObserver : public TreeObserverBase {
DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeMovedObserver); DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeMovedObserver);
}; };
TEST_F(ViewManagerTest, HierarchyChanged_NodeMoved) { TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeMoved) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
ViewTreeNode* node2 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node2 = CreateNodeInParent(view_manager_1()->tree());
ViewTreeNode* node21 = CreateNodeInParent(node2); ViewTreeNode* node21 = CreateNodeInParent(node2);
...@@ -418,7 +420,7 @@ class HierarchyChanged_NodeRemovedObserver : public TreeObserverBase { ...@@ -418,7 +420,7 @@ class HierarchyChanged_NodeRemovedObserver : public TreeObserverBase {
DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeRemovedObserver); DISALLOW_COPY_AND_ASSIGN(HierarchyChanged_NodeRemovedObserver);
}; };
TEST_F(ViewManagerTest, HierarchyChanged_NodeRemoved) { TEST_F(ViewManagerTest, DISABLED_HierarchyChanged_NodeRemoved) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -432,7 +434,7 @@ TEST_F(ViewManagerTest, HierarchyChanged_NodeRemoved) { ...@@ -432,7 +434,7 @@ TEST_F(ViewManagerTest, HierarchyChanged_NodeRemoved) {
EXPECT_TRUE(tree2->children().empty()); EXPECT_TRUE(tree2->children().empty());
} }
TEST_F(ViewManagerTest, NodeDestroyed) { TEST_F(ViewManagerTest, DISABLED_NodeDestroyed) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -448,7 +450,7 @@ TEST_F(ViewManagerTest, NodeDestroyed) { ...@@ -448,7 +450,7 @@ TEST_F(ViewManagerTest, NodeDestroyed) {
EXPECT_EQ(NULL, view_manager_2()->GetNodeById(id)); EXPECT_EQ(NULL, view_manager_2()->GetNodeById(id));
} }
TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNode) { TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupNode) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -462,7 +464,7 @@ TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNode) { ...@@ -462,7 +464,7 @@ TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNode) {
EXPECT_TRUE(view_manager_2()->tree()->children().empty()); EXPECT_TRUE(view_manager_2()->tree()->children().empty());
} }
TEST_F(ViewManagerTest, SetActiveView) { TEST_F(ViewManagerTest, DISABLED_SetActiveView) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -475,7 +477,7 @@ TEST_F(ViewManagerTest, SetActiveView) { ...@@ -475,7 +477,7 @@ TEST_F(ViewManagerTest, SetActiveView) {
EXPECT_EQ(node1_2->active_view()->id(), view1->id()); EXPECT_EQ(node1_2->active_view()->id(), view1->id());
} }
TEST_F(ViewManagerTest, DestroyView) { TEST_F(ViewManagerTest, DISABLED_DestroyView) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -497,7 +499,7 @@ TEST_F(ViewManagerTest, DestroyView) { ...@@ -497,7 +499,7 @@ TEST_F(ViewManagerTest, DestroyView) {
// Destroying the connection that created a node and view should result in that // Destroying the connection that created a node and view should result in that
// node and view disappearing from all connections that see them. // node and view disappearing from all connections that see them.
TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNodeAndView) { TEST_F(ViewManagerTest, DISABLED_ViewManagerDestroyed_CleanupNodeAndView) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -530,7 +532,7 @@ TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNodeAndView) { ...@@ -530,7 +532,7 @@ TEST_F(ViewManagerTest, ViewManagerDestroyed_CleanupNodeAndView) {
// -> the view should still exist (since the second connection is live) but // -> the view should still exist (since the second connection is live) but
// should be disconnected from any nodes. // should be disconnected from any nodes.
TEST_F(ViewManagerTest, TEST_F(ViewManagerTest,
ViewManagerDestroyed_CleanupNodeAndViewFromDifferentConnections) { DISABLED_ViewManagerDestroyed_CleanupNodeAndViewFromDifferentConnections) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -562,7 +564,7 @@ TEST_F(ViewManagerTest, ...@@ -562,7 +564,7 @@ TEST_F(ViewManagerTest,
// defined in a different connection. // defined in a different connection.
// TODO(beng): write these tests for ViewTreeNode::AddChild(), RemoveChild() and // TODO(beng): write these tests for ViewTreeNode::AddChild(), RemoveChild() and
// Contains(). // Contains().
TEST_F(ViewManagerTest, SetActiveViewAcrossConnection) { TEST_F(ViewManagerTest, DISABLED_SetActiveViewAcrossConnection) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -573,7 +575,7 @@ TEST_F(ViewManagerTest, SetActiveViewAcrossConnection) { ...@@ -573,7 +575,7 @@ TEST_F(ViewManagerTest, SetActiveViewAcrossConnection) {
// This test verifies that a node hierarchy constructed in one connection // This test verifies that a node hierarchy constructed in one connection
// becomes entirely visible to the second connection when the hierarchy is // becomes entirely visible to the second connection when the hierarchy is
// attached. // attached.
TEST_F(ViewManagerTest, MapSubtreeOnAttach) { TEST_F(ViewManagerTest, DISABLED_MapSubtreeOnAttach) {
ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1()); ViewTreeNode* node1 = ViewTreeNode::Create(view_manager_1());
ViewTreeNode* node11 = CreateNodeInParent(node1); ViewTreeNode* node11 = CreateNodeInParent(node1);
View* view11 = View::Create(view_manager_1()); View* view11 = View::Create(view_manager_1());
...@@ -596,7 +598,7 @@ TEST_F(ViewManagerTest, MapSubtreeOnAttach) { ...@@ -596,7 +598,7 @@ TEST_F(ViewManagerTest, MapSubtreeOnAttach) {
// Verifies that bounds changes applied to a node hierarchy in one connection // Verifies that bounds changes applied to a node hierarchy in one connection
// are reflected to another. // are reflected to another.
TEST_F(ViewManagerTest, SetBounds) { TEST_F(ViewManagerTest, DISABLED_SetBounds) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -610,7 +612,7 @@ TEST_F(ViewManagerTest, SetBounds) { ...@@ -610,7 +612,7 @@ TEST_F(ViewManagerTest, SetBounds) {
// Verifies that bounds changes applied to a node owned by a different // Verifies that bounds changes applied to a node owned by a different
// connection are refused. // connection are refused.
TEST_F(ViewManagerTest, SetBoundsSecurity) { TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
node1->SetBounds(gfx::Rect(800, 600)); node1->SetBounds(gfx::Rect(800, 600));
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
...@@ -622,7 +624,7 @@ TEST_F(ViewManagerTest, SetBoundsSecurity) { ...@@ -622,7 +624,7 @@ TEST_F(ViewManagerTest, SetBoundsSecurity) {
} }
// Verifies that a node can only be destroyed by the connection that created it. // Verifies that a node can only be destroyed by the connection that created it.
TEST_F(ViewManagerTest, DestroySecurity) { TEST_F(ViewManagerTest, DISABLED_DestroySecurity) {
ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree()); ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
WaitForTreeSizeToMatch(view_manager_2()->tree(), 2); WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
......
...@@ -13,6 +13,14 @@ struct INode { ...@@ -13,6 +13,14 @@ struct INode {
mojo.Rect bounds; mojo.Rect bounds;
}; };
// IViewManagerInit is responsible for launching the client that controls the
// root node. mojo::view_manager returns an instance of this. All other
// connections are established by the client this creates.
interface IViewManagerInit {
// Connects to |url| creating a connection that has the roots |nodes|.
Connect(string url) => (bool success);
};
// Functions that mutate the hierarchy take a change id. This is an ever // Functions that mutate the hierarchy take a change id. This is an ever
// increasing integer used to identify the change. Every hierarchy change // increasing integer used to identify the change. Every hierarchy change
// increases this value. The server only accepts changes where the supplied // increases this value. The server only accepts changes where the supplied
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/application/application.h"
#include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/view_manager_init_connection.h"
#include "mojo/services/view_manager/view_manager_connection.h"
namespace mojo { namespace mojo {
namespace view_manager { namespace view_manager {
...@@ -16,21 +15,21 @@ class ViewManagerApp : public Application { ...@@ -16,21 +15,21 @@ class ViewManagerApp : public Application {
virtual ~ViewManagerApp() {} virtual ~ViewManagerApp() {}
virtual void Initialize() MOJO_OVERRIDE { virtual void Initialize() MOJO_OVERRIDE {
root_node_manager_.reset(new RootNodeManager(service_provider())); // TODO(sky): this needs some sort of authentication as well as making sure
AddService<ViewManagerConnection>(root_node_manager_.get()); // we only ever have one active at a time.
AddService<ViewManagerInitConnection>(service_provider());
} }
private: private:
scoped_ptr<RootNodeManager> root_node_manager_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerApp); DISALLOW_COPY_AND_ASSIGN(ViewManagerApp);
}; };
} } // namespace service
} } // namespace view_manager
// static // static
Application* Application::Create() { Application* Application::Create() {
return new mojo::view_manager::service::ViewManagerApp(); return new mojo::view_manager::service::ViewManagerApp();
} }
} } // namespace mojo
...@@ -33,15 +33,17 @@ RootNodeManager::Context::Context() { ...@@ -33,15 +33,17 @@ RootNodeManager::Context::Context() {
} }
RootNodeManager::Context::~Context() { RootNodeManager::Context::~Context() {
aura::Env::DeleteInstance();
} }
RootNodeManager::RootNodeManager(ServiceProvider* service_provider) RootNodeManager::RootNodeManager(ServiceProvider* service_provider,
RootViewManagerDelegate* view_manager_delegate)
: service_provider_(service_provider), : service_provider_(service_provider),
next_connection_id_(1), next_connection_id_(1),
next_server_change_id_(1), next_server_change_id_(1),
change_source_(kRootConnection), change_source_(kRootConnection),
is_processing_delete_node_(false), is_processing_delete_node_(false),
root_view_manager_(service_provider, this), root_view_manager_(service_provider, this, view_manager_delegate),
root_(this, RootNodeId()) { root_(this, RootNodeId()) {
} }
...@@ -68,14 +70,16 @@ void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) { ...@@ -68,14 +70,16 @@ void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) {
connections_created_by_connect_.erase(connection); connections_created_by_connect_.erase(connection);
} }
void RootNodeManager::InitialConnect(const std::string& url) {
CHECK(connection_map_.empty());
Array<TransportNodeId> roots(0);
ConnectImpl(String::From(url), roots);
}
void RootNodeManager::Connect(const String& url, void RootNodeManager::Connect(const String& url,
const Array<TransportNodeId>& node_ids) { const Array<TransportNodeId>& node_ids) {
MessagePipe pipe; CHECK_GT(node_ids.size(), 0u);
service_provider_->ConnectToService(url, pipe.handle1.Pass()); ConnectImpl(url, node_ids)->set_delete_on_connection_error();
ViewManagerConnection* connection = new ViewManagerConnection(this);
connection->SetRoots(node_ids);
BindToPipe(connection, pipe.handle0.Pass());
connections_created_by_connect_.insert(connection);
} }
ViewManagerConnection* RootNodeManager::GetConnection( ViewManagerConnection* RootNodeManager::GetConnection(
...@@ -159,6 +163,18 @@ void RootNodeManager::FinishChange(ChangeType change_type) { ...@@ -159,6 +163,18 @@ void RootNodeManager::FinishChange(ChangeType change_type) {
next_server_change_id_++; next_server_change_id_++;
} }
ViewManagerConnection* RootNodeManager::ConnectImpl(
const String& url,
const Array<TransportNodeId>& node_ids) {
MessagePipe pipe;
service_provider_->ConnectToService(url, pipe.handle1.Pass());
ViewManagerConnection* connection = new ViewManagerConnection(this);
connection->SetRoots(node_ids);
BindToPipe(connection, pipe.handle0.Pass());
connections_created_by_connect_.insert(connection);
return connection;
}
void RootNodeManager::OnNodeHierarchyChanged(const Node* node, void RootNodeManager::OnNodeHierarchyChanged(const Node* node,
const Node* new_parent, const Node* new_parent,
const Node* old_parent) { const Node* old_parent) {
......
...@@ -23,6 +23,7 @@ class ServiceProvider; ...@@ -23,6 +23,7 @@ class ServiceProvider;
namespace view_manager { namespace view_manager {
namespace service { namespace service {
class RootViewManagerDelegate;
class View; class View;
class ViewManagerConnection; class ViewManagerConnection;
...@@ -54,7 +55,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { ...@@ -54,7 +55,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate {
DISALLOW_COPY_AND_ASSIGN(ScopedChange); DISALLOW_COPY_AND_ASSIGN(ScopedChange);
}; };
explicit RootNodeManager(ServiceProvider* service_provider); RootNodeManager(ServiceProvider* service_provider,
RootViewManagerDelegate* view_manager_delegate);
virtual ~RootNodeManager(); virtual ~RootNodeManager();
// Returns the id for the next ViewManagerConnection. // Returns the id for the next ViewManagerConnection.
...@@ -67,6 +69,12 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { ...@@ -67,6 +69,12 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate {
void AddConnection(ViewManagerConnection* connection); void AddConnection(ViewManagerConnection* connection);
void RemoveConnection(ViewManagerConnection* connection); void RemoveConnection(ViewManagerConnection* connection);
// Establishes the initial client. Similar to Connect(), but the resulting
// client is allowed to do anything.
void InitialConnect(const std::string& url);
// See description of IViewManager::Connect() for details. This assumes
// |node_ids| has been validated.
void Connect(const String& url, const Array<TransportNodeId>& node_ids); void Connect(const String& url, const Array<TransportNodeId>& node_ids);
// Returns the connection by id. // Returns the connection by id.
...@@ -123,6 +131,10 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { ...@@ -123,6 +131,10 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate {
return connection_id == change_source_; return connection_id == change_source_;
} }
// Implementation of the two connect variants.
ViewManagerConnection* ConnectImpl(const String& url,
const Array<TransportNodeId>& node_ids);
// Overridden from NodeDelegate: // Overridden from NodeDelegate:
virtual void OnNodeHierarchyChanged(const Node* node, virtual void OnNodeHierarchyChanged(const Node* node,
const Node* new_parent, const Node* new_parent,
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "mojo/aura/screen_mojo.h" #include "mojo/aura/screen_mojo.h"
#include "mojo/aura/window_tree_host_mojo.h" #include "mojo/aura/window_tree_host_mojo.h"
#include "mojo/public/cpp/application/connect.h" #include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/root_view_manager_delegate.h"
#include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/window_tree_client.h" #include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -48,8 +48,9 @@ class WindowTreeClientImpl : public aura::client::WindowTreeClient { ...@@ -48,8 +48,9 @@ class WindowTreeClientImpl : public aura::client::WindowTreeClient {
}; };
RootViewManager::RootViewManager(ServiceProvider* service_provider, RootViewManager::RootViewManager(ServiceProvider* service_provider,
RootNodeManager* root_node) RootNodeManager* root_node,
: service_provider_(service_provider), RootViewManagerDelegate* delegate)
: delegate_(delegate),
root_node_manager_(root_node), root_node_manager_(root_node),
in_setup_(false) { in_setup_(false) {
screen_.reset(ScreenMojo::Create()); screen_.reset(ScreenMojo::Create());
...@@ -84,6 +85,8 @@ void RootViewManager::OnCompositorCreated() { ...@@ -84,6 +85,8 @@ void RootViewManager::OnCompositorCreated() {
new WindowTreeClientImpl(window_tree_host_->window())); new WindowTreeClientImpl(window_tree_host_->window()));
window_tree_host_->Show(); window_tree_host_->Show();
delegate_->OnRootViewManagerWindowTreeHostCreated();
} }
} // namespace service } // namespace service
......
...@@ -31,12 +31,14 @@ namespace view_manager { ...@@ -31,12 +31,14 @@ namespace view_manager {
namespace service { namespace service {
class RootNodeManager; class RootNodeManager;
class RootViewManagerDelegate;
// RootViewManager binds the root node to an actual display. // RootViewManager binds the root node to an actual display.
class MOJO_VIEW_MANAGER_EXPORT RootViewManager { class MOJO_VIEW_MANAGER_EXPORT RootViewManager {
public: public:
RootViewManager(ServiceProvider* service_provider, RootViewManager(ServiceProvider* service_provider,
RootNodeManager* root_node); RootNodeManager* root_node,
RootViewManagerDelegate* delegate);
virtual ~RootViewManager(); virtual ~RootViewManager();
// See description above field for details. // See description above field for details.
...@@ -45,7 +47,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootViewManager { ...@@ -45,7 +47,8 @@ class MOJO_VIEW_MANAGER_EXPORT RootViewManager {
private: private:
void OnCompositorCreated(); void OnCompositorCreated();
ServiceProvider* service_provider_; RootViewManagerDelegate* delegate_;
RootNodeManager* root_node_manager_; RootNodeManager* root_node_manager_;
GLES2Initializer gles_initializer_; GLES2Initializer gles_initializer_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_SERVICES_VIEW_MANAGER_ROOT_VIEW_MANAGER_DELEGATE_H_
#define MOJO_SERVICES_VIEW_MANAGER_ROOT_VIEW_MANAGER_DELEGATE_H_
#include "mojo/services/view_manager/view_manager_export.h"
namespace mojo {
namespace view_manager {
namespace service {
class MOJO_VIEW_MANAGER_EXPORT RootViewManagerDelegate {
public:
// Invoked when the WindowTreeHost is ready.
virtual void OnRootViewManagerWindowTreeHostCreated() = 0;
protected:
virtual ~RootViewManagerDelegate() {}
};
} // namespace service
} // namespace view_manager
} // namespace mojo
#endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_VIEW_MANAGER_H_
...@@ -34,7 +34,8 @@ void GetDescendants(const Node* node, std::vector<const Node*>* nodes) { ...@@ -34,7 +34,8 @@ void GetDescendants(const Node* node, std::vector<const Node*>* nodes) {
ViewManagerConnection::ViewManagerConnection(RootNodeManager* root_node_manager) ViewManagerConnection::ViewManagerConnection(RootNodeManager* root_node_manager)
: root_node_manager_(root_node_manager), : root_node_manager_(root_node_manager),
id_(0) { id_(root_node_manager_->GetAndAdvanceNextConnectionId()),
delete_on_connection_error_(false) {
} }
ViewManagerConnection::~ViewManagerConnection() { ViewManagerConnection::~ViewManagerConnection() {
...@@ -87,7 +88,7 @@ const View* ViewManagerConnection::GetView(const ViewId& id) const { ...@@ -87,7 +88,7 @@ const View* ViewManagerConnection::GetView(const ViewId& id) const {
} }
void ViewManagerConnection::SetRoots(const Array<TransportNodeId>& node_ids) { void ViewManagerConnection::SetRoots(const Array<TransportNodeId>& node_ids) {
DCHECK_EQ(0, id_); // Only valid before connection established. DCHECK(roots_.empty());
NodeIdSet roots; NodeIdSet roots;
for (size_t i = 0; i < node_ids.size(); ++i) { for (size_t i = 0; i < node_ids.size(); ++i) {
DCHECK(GetNode(NodeIdFromTransportId(node_ids[i]))); DCHECK(GetNode(NodeIdFromTransportId(node_ids[i])));
...@@ -198,8 +199,8 @@ void ViewManagerConnection::ProcessViewDeleted(const ViewId& view, ...@@ -198,8 +199,8 @@ void ViewManagerConnection::ProcessViewDeleted(const ViewId& view,
} }
void ViewManagerConnection::OnConnectionError() { void ViewManagerConnection::OnConnectionError() {
// TODO(sky): figure out if need to cleanup here if this if (delete_on_connection_error_)
// ViewManagerConnection is the result of a Connect(). delete this;
} }
bool ViewManagerConnection::CanRemoveNodeFromParent(const Node* node) const { bool ViewManagerConnection::CanRemoveNodeFromParent(const Node* node) const {
...@@ -614,10 +615,6 @@ void ViewManagerConnection::OnNodeViewReplaced(const Node* node, ...@@ -614,10 +615,6 @@ void ViewManagerConnection::OnNodeViewReplaced(const Node* node,
} }
void ViewManagerConnection::OnConnectionEstablished() { void ViewManagerConnection::OnConnectionEstablished() {
DCHECK_EQ(0, id_); // Should only get OnConnectionEstablished() once.
id_ = root_node_manager_->GetAndAdvanceNextConnectionId();
root_node_manager_->AddConnection(this); root_node_manager_->AddConnection(this);
std::vector<const Node*> to_send; std::vector<const Node*> to_send;
......
...@@ -43,6 +43,10 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -43,6 +43,10 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
explicit ViewManagerConnection(RootNodeManager* root_node_manager); explicit ViewManagerConnection(RootNodeManager* root_node_manager);
virtual ~ViewManagerConnection(); virtual ~ViewManagerConnection();
// Used to mark this connection as originating from a call to
// IViewManager::Connect(). When set OnConnectionError() deletes |this|.
void set_delete_on_connection_error() { delete_on_connection_error_ = true; }
TransportConnectionId id() const { return id_; } TransportConnectionId id() const { return id_; }
// Returns the Node with the specified id. // Returns the Node with the specified id.
...@@ -185,9 +189,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -185,9 +189,8 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
RootNodeManager* root_node_manager_; RootNodeManager* root_node_manager_;
// Id of this connection as assigned by RootNodeManager. Assigned in // Id of this connection as assigned by RootNodeManager.
// OnConnectionEstablished(). const TransportConnectionId id_;
TransportConnectionId id_;
NodeMap node_map_; NodeMap node_map_;
...@@ -204,6 +207,9 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection ...@@ -204,6 +207,9 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
// invalid node is added here to ensure this connection is still constrained. // invalid node is added here to ensure this connection is still constrained.
NodeIdSet roots_; NodeIdSet roots_;
// See description above setter.
bool delete_on_connection_error_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection);
}; };
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/services/view_manager/view_manager_init_connection.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/view_manager/ids.h"
#include "mojo/services/view_manager/view_manager_connection.h"
namespace mojo {
namespace view_manager {
namespace service {
ViewManagerInitConnection::ConnectParams::ConnectParams() {}
ViewManagerInitConnection::ConnectParams::~ConnectParams() {}
ViewManagerInitConnection::ViewManagerInitConnection(
ServiceProvider* service_provider)
: service_provider_(service_provider),
root_node_manager_(service_provider, this),
is_tree_host_ready_(false) {
}
ViewManagerInitConnection::~ViewManagerInitConnection() {
}
void ViewManagerInitConnection::MaybeConnect(
const std::string& url,
const Callback<void(bool)>& callback) {
if (!is_tree_host_ready_)
return;
root_node_manager_.InitialConnect(url);
callback.Run(true);
}
void ViewManagerInitConnection::Connect(const String& url,
const Callback<void(bool)>& callback) {
if (connect_params_.get()) {
DVLOG(1) << "Ignoring second connect";
callback.Run(false);
return;
}
connect_params_.reset(new ConnectParams);
connect_params_->url = url.To<std::string>();
connect_params_->callback = callback;
MaybeConnect(url.To<std::string>(), callback);
}
void ViewManagerInitConnection::OnRootViewManagerWindowTreeHostCreated() {
DCHECK(!is_tree_host_ready_);
is_tree_host_ready_ = true;
if (connect_params_.get())
MaybeConnect(connect_params_->url, connect_params_->callback);
}
} // namespace service
} // namespace view_manager
} // namespace mojo
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_CONNECTION_H_
#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_CONNECTION_H_
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "mojo/services/view_manager/root_node_manager.h"
#include "mojo/services/view_manager/root_view_manager_delegate.h"
#include "mojo/services/view_manager/view_manager_export.h"
namespace mojo {
class ServiceProvider;
namespace view_manager {
namespace service {
#if defined(OS_WIN)
// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
// below.
#pragma warning(push)
#pragma warning(disable : 4275)
#endif
// Used to create the initial IViewManagerClient. Doesn't initiate the Connect()
// until the WindowTreeHost has been created.
class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitConnection
: public InterfaceImpl<IViewManagerInit>,
public RootViewManagerDelegate {
public:
explicit ViewManagerInitConnection(ServiceProvider* service_provider);
virtual ~ViewManagerInitConnection();
private:
struct ConnectParams {
ConnectParams();
~ConnectParams();
std::string url;
Callback<void(bool)> callback;
};
void MaybeConnect(const std::string& url,
const Callback<void(bool)>& callback);
// IViewManagerInit overrides:
virtual void Connect(const String& url,
const Callback<void(bool)>& callback) OVERRIDE;
// RootViewManagerDelegate overrides:
virtual void OnRootViewManagerWindowTreeHostCreated() OVERRIDE;
ServiceProvider* service_provider_;
RootNodeManager root_node_manager_;
// Parameters passed to Connect(). If non-null Connect() has been invoked.
scoped_ptr<ConnectParams> connect_params_;
bool is_tree_host_ready_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerInitConnection);
};
#if defined(OS_WIN)
#pragma warning(pop)
#endif
} // namespace service
} // namespace view_manager
} // namespace mojo
#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_CONNECTION_H_
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
#include "mojo/shell/view_manager_loader.h" #include "mojo/shell/view_manager_loader.h"
#include "mojo/public/cpp/application/application.h" #include "mojo/public/cpp/application/application.h"
#include "mojo/services/view_manager/root_node_manager.h" #include "mojo/services/view_manager/view_manager_init_connection.h"
#include "mojo/services/view_manager/view_manager_connection.h"
namespace mojo { namespace mojo {
namespace shell { namespace shell {
...@@ -21,13 +20,11 @@ void ViewManagerLoader::LoadService( ...@@ -21,13 +20,11 @@ void ViewManagerLoader::LoadService(
ServiceManager* manager, ServiceManager* manager,
const GURL& url, const GURL& url,
ScopedMessagePipeHandle service_provider_handle) { ScopedMessagePipeHandle service_provider_handle) {
// TODO(sky): this needs some sort of authentication as well as making sure
// we only ever have one active at a time.
scoped_ptr<Application> app(new Application(service_provider_handle.Pass())); scoped_ptr<Application> app(new Application(service_provider_handle.Pass()));
if (!root_node_manager_.get()) { app->AddService<view_manager::service::ViewManagerInitConnection>(
root_node_manager_.reset( app->service_provider());
new view_manager::service::RootNodeManager(app->service_provider()));
}
app->AddService<view_manager::service::ViewManagerConnection>(
root_node_manager_.get());
apps_.push_back(app.release()); apps_.push_back(app.release());
} }
......
...@@ -10,11 +10,6 @@ ...@@ -10,11 +10,6 @@
#include "mojo/service_manager/service_loader.h" #include "mojo/service_manager/service_loader.h"
namespace mojo { namespace mojo {
namespace view_manager {
namespace service {
class RootNodeManager;
}
}
class Application; class Application;
...@@ -35,7 +30,6 @@ class ViewManagerLoader : public ServiceLoader { ...@@ -35,7 +30,6 @@ class ViewManagerLoader : public ServiceLoader {
virtual void OnServiceError(ServiceManager* manager, virtual void OnServiceError(ServiceManager* manager,
const GURL& url) OVERRIDE; const GURL& url) OVERRIDE;
scoped_ptr<view_manager::service::RootNodeManager> root_node_manager_;
ScopedVector<Application> apps_; ScopedVector<Application> apps_;
DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader); DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment