summaryrefslogtreecommitdiffstats
path: root/mojo/services
diff options
context:
space:
mode:
authoryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-25 08:52:54 +0000
committeryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-25 08:52:54 +0000
commit2916b9f78088ccb4df3cf152a8727a1c14ae881c (patch)
tree9ae473ce5dde4f438c25a211c93aebe806021c35 /mojo/services
parent79323cd4e92f3f49a2c44f62dd4e1a04521227d5 (diff)
downloadchromium_src-2916b9f78088ccb4df3cf152a8727a1c14ae881c.zip
chromium_src-2916b9f78088ccb4df3cf152a8727a1c14ae881c.tar.gz
chromium_src-2916b9f78088ccb4df3cf152a8727a1c14ae881c.tar.bz2
Revert 266159 "Adds more to viewmanager"
Compilation error: c:\b\build\slave\cr-win-rel-x64\build\src\mojo\services\view_manager\view_manager_connection.cc(199) : error C2723: 'mojo::services::view_manager::ViewManagerConnection::DeleteView' : 'override' specifier illegal on function definition http://build.chromium.org/p/chromium.win/builders/Win%20x64%20Builder/builds/17746/steps/compile/logs/stdio > Adds more to viewmanager > > Specifically ability to delete nodes, create views and attach them. > > BUG=365012 > TEST=covered by tests > R=ben@chromium.org > > Review URL: https://codereview.chromium.org/250633003 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/250733003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266162 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/services')
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom18
-rw-r--r--mojo/services/view_manager/ids.h12
-rw-r--r--mojo/services/view_manager/node.cc33
-rw-r--r--mojo/services/view_manager/node.h14
-rw-r--r--mojo/services/view_manager/node_delegate.h6
-rw-r--r--mojo/services/view_manager/root_node_manager.cc29
-rw-r--r--mojo/services/view_manager/root_node_manager.h15
-rw-r--r--mojo/services/view_manager/view.cc20
-rw-r--r--mojo/services/view_manager/view.h46
-rw-r--r--mojo/services/view_manager/view_manager_connection.cc130
-rw-r--r--mojo/services/view_manager/view_manager_connection.h45
-rw-r--r--mojo/services/view_manager/view_manager_connection_unittest.cc231
12 files changed, 10 insertions, 589 deletions
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 673068c..ef5dcf3 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -21,10 +21,6 @@ interface ViewManager {
// the id is unique to the connection (the id need not be globally unique).
CreateNode(uint16 node_id) => (bool success);
- // Deletes a node. This does not recurse. Children are removed from the node
- // before it is destroyed.
- DeleteNode(uint32 node_id, int32 change_id) => (bool success);
-
// Reparents a node. See description above class for details of |change_id|.
AddNode(uint32 parent, uint32 child, int32 change_id) => (bool success);
@@ -34,13 +30,10 @@ interface ViewManager {
// Creates a new view with the specified id. It is up to the client to ensure
// the id is unique to the connection (the id need not be globally unique).
- CreateView(uint16 view_id) => (bool success);
-
- // Deletes the view with the specified id.
- DeleteView(uint32 view_id, int32 change_id) => (bool success);
+ // CreateView(uint16 view_id) => (bool success);
// Sets the view a node is showing.
- SetView(uint32 node_id, uint32 view_id, int32 change_id) => (bool success);
+ // SetView(uint32 node, uint32 view) => (bool success);
};
[Peer=ViewManager]
@@ -56,13 +49,6 @@ interface ViewManagerClient {
uint32 new_parent,
uint32 old_parent,
int32 change_id);
-
- // Invoked when the view associated with a node is replaced by another view.
- // 0 is used to identify a null view.
- OnNodeViewReplaced(uint32 node,
- uint32 new_view_id,
- uint32 old_view_id,
- int32 change_id);
};
}
diff --git a/mojo/services/view_manager/ids.h b/mojo/services/view_manager/ids.h
index d42e18f..257402b 100644
--- a/mojo/services/view_manager/ids.h
+++ b/mojo/services/view_manager/ids.h
@@ -23,10 +23,6 @@ struct MOJO_VIEW_MANAGER_EXPORT NodeId {
other.node_id == node_id;
}
- bool operator!=(const NodeId& other) const {
- return !(*this == other);
- }
-
uint16_t connection_id;
uint16_t node_id;
};
@@ -43,10 +39,6 @@ struct MOJO_VIEW_MANAGER_EXPORT ViewId {
other.view_id == view_id;
}
- bool operator!=(const ViewId& other) const {
- return !(*this == other);
- }
-
uint16_t connection_id;
uint16_t view_id;
};
@@ -72,10 +64,6 @@ inline ViewId ViewIdFromTransportId(uint32_t id) {
return ViewId(FirstIdFromTransportId(id), SecondIdFromTransportId(id));
}
-inline uint32_t ViewIdToTransportId(const ViewId& id) {
- return (id.connection_id << 16) | id.view_id;
-}
-
} // namespace view_manager
} // namespace services
} // namespace mojo
diff --git a/mojo/services/view_manager/node.cc b/mojo/services/view_manager/node.cc
index e2436da..1457a7e 100644
--- a/mojo/services/view_manager/node.cc
+++ b/mojo/services/view_manager/node.cc
@@ -5,7 +5,6 @@
#include "mojo/services/view_manager/node.h"
#include "mojo/services/view_manager/node_delegate.h"
-#include "mojo/services/view_manager/view.h"
#include "ui/aura/window_property.h"
DECLARE_WINDOW_PROPERTY_TYPE(mojo::services::view_manager::Node*);
@@ -19,7 +18,6 @@ DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL);
Node::Node(NodeDelegate* delegate, const NodeId& id)
: delegate_(delegate),
id_(id),
- view_(NULL),
window_(NULL) {
DCHECK(delegate); // Must provide a delegate.
window_.set_owned_by_parent(false);
@@ -28,7 +26,6 @@ Node::Node(NodeDelegate* delegate, const NodeId& id)
}
Node::~Node() {
- SetView(NULL);
}
Node* Node::GetParent() {
@@ -45,36 +42,6 @@ void Node::Remove(Node* child) {
window_.RemoveChild(&child->window_);
}
-std::vector<Node*> Node::GetChildren() {
- std::vector<Node*> children;
- children.reserve(window_.children().size());
- for (size_t i = 0; i < window_.children().size(); ++i)
- children.push_back(window_.children()[i]->GetProperty(kNodeKey));
- return children;
-}
-
-void Node::SetView(View* view) {
- if (view == view_)
- return;
-
- // Detach view from existing node. This way notifications are sent out.
- if (view && view->node())
- view->node()->SetView(NULL);
-
- ViewId old_view_id;
- if (view_) {
- view_->set_node(NULL);
- old_view_id = view_->id();
- }
- view_ = view;
- ViewId view_id;
- if (view) {
- view_id = view->id();
- view->set_node(this);
- }
- delegate_->OnNodeViewReplaced(id_, view_id, old_view_id);
-}
-
void Node::OnWindowHierarchyChanged(
const aura::WindowObserver::HierarchyChangeParams& params) {
if (params.target != &window_ || params.receiver != &window_)
diff --git a/mojo/services/view_manager/node.h b/mojo/services/view_manager/node.h
index ed68874..5892af0 100644
--- a/mojo/services/view_manager/node.h
+++ b/mojo/services/view_manager/node.h
@@ -5,8 +5,6 @@
#ifndef MOJO_SERVICES_VIEW_MANAGER_NODE_H_
#define MOJO_SERVICES_VIEW_MANAGER_NODE_H_
-#include <vector>
-
#include "base/logging.h"
#include "mojo/services/view_manager/ids.h"
#include "mojo/services/view_manager/view_manager_export.h"
@@ -18,7 +16,6 @@ namespace services {
namespace view_manager {
class NodeDelegate;
-class View;
// Represents a node in the graph. Delegate is informed of interesting events.
class MOJO_VIEW_MANAGER_EXPORT Node : public aura::WindowObserver {
@@ -36,12 +33,6 @@ class MOJO_VIEW_MANAGER_EXPORT Node : public aura::WindowObserver {
Node* GetParent();
- std::vector<Node*> GetChildren();
-
- // Sets the view associated with this node. Node does not own its View.
- void SetView(View* view);
- View* view() { return view_; }
-
private:
// WindowObserver overrides:
virtual void OnWindowHierarchyChanged(
@@ -49,12 +40,7 @@ class MOJO_VIEW_MANAGER_EXPORT Node : public aura::WindowObserver {
NodeDelegate* delegate_;
const NodeId id_;
-
- // Weak pointer to view associated with this node.
- View* view_;
-
ViewId view_id_;
-
aura::Window window_;
DISALLOW_COPY_AND_ASSIGN(Node);
diff --git a/mojo/services/view_manager/node_delegate.h b/mojo/services/view_manager/node_delegate.h
index 5cec703..3e34940 100644
--- a/mojo/services/view_manager/node_delegate.h
+++ b/mojo/services/view_manager/node_delegate.h
@@ -12,7 +12,6 @@ namespace services {
namespace view_manager {
struct NodeId;
-struct ViewId;
class MOJO_VIEW_MANAGER_EXPORT NodeDelegate {
public:
@@ -21,11 +20,6 @@ class MOJO_VIEW_MANAGER_EXPORT NodeDelegate {
const NodeId& new_parent,
const NodeId& old_parent) = 0;
- // Invoked when the View associated with a node changes.
- virtual void OnNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id) = 0;
-
protected:
virtual ~NodeDelegate() {}
};
diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc
index 210427a..f35df3d 100644
--- a/mojo/services/view_manager/root_node_manager.cc
+++ b/mojo/services/view_manager/root_node_manager.cc
@@ -51,11 +51,6 @@ void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) {
connection_map_.erase(connection->id());
}
-ViewManagerConnection* RootNodeManager::GetConnection(uint16_t connection_id) {
- ConnectionMap::iterator i = connection_map_.find(connection_id);
- return i == connection_map_.end() ? NULL : i->second;
-}
-
Node* RootNodeManager::GetNode(const NodeId& id) {
if (id == root_.id())
return &root_;
@@ -63,11 +58,6 @@ Node* RootNodeManager::GetNode(const NodeId& id) {
return i == connection_map_.end() ? NULL : i->second->GetNode(id);
}
-View* RootNodeManager::GetView(const ViewId& id) {
- ConnectionMap::iterator i = connection_map_.find(id.connection_id);
- return i == connection_map_.end() ? NULL : i->second->GetView(id);
-}
-
void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent) {
@@ -80,19 +70,6 @@ void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node,
}
}
-void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id) {
- // TODO(sky): make a macro for this.
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end(); ++i) {
- const int32_t change_id = (change_ && i->first == change_->connection_id) ?
- change_->change_id : 0;
- i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id,
- change_id);
- }
-}
-
void RootNodeManager::PrepareForChange(ViewManagerConnection* connection,
int32_t change_id) {
DCHECK(!change_.get()); // Should only ever have one change in flight.
@@ -124,12 +101,6 @@ void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node,
NotifyNodeHierarchyChanged(node, new_parent, old_parent);
}
-void RootNodeManager::OnNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id) {
- NotifyNodeViewReplaced(node, new_view_id, old_view_id);
-}
-
} // namespace view_manager
} // namespace services
} // namespace mojo
diff --git a/mojo/services/view_manager/root_node_manager.h b/mojo/services/view_manager/root_node_manager.h
index 98f347e..aecfa8b 100644
--- a/mojo/services/view_manager/root_node_manager.h
+++ b/mojo/services/view_manager/root_node_manager.h
@@ -50,23 +50,13 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
void AddConnection(ViewManagerConnection* connection);
void RemoveConnection(ViewManagerConnection* connection);
- // Returns the connection by id.
- ViewManagerConnection* GetConnection(uint16_t connection_id);
-
// Returns the Node identified by |id|.
Node* GetNode(const NodeId& id);
- // Returns the View identified by |id|.
- View* GetView(const ViewId& id);
-
- // These functions trivially delegate to all ViewManagerConnections, which in
- // term notify their clients.
+ // Notifies all ViewManagerConnections of a hierarchy change.
void NotifyNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent);
- void NotifyNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id);
private:
// Tracks a change.
@@ -104,9 +94,6 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
virtual void OnNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent) OVERRIDE;
- virtual void OnNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id) OVERRIDE;
// ID to use for next ViewManagerConnection.
uint16_t next_connection_id_;
diff --git a/mojo/services/view_manager/view.cc b/mojo/services/view_manager/view.cc
deleted file mode 100644
index 0e9fc13..0000000
--- a/mojo/services/view_manager/view.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// 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.h"
-
-#include "mojo/services/view_manager/node.h"
-
-namespace mojo {
-namespace services {
-namespace view_manager {
-
-View::View(const ViewId& id) : id_(id), node_(NULL) {}
-
-View::~View() {
-}
-
-} // namespace view_manager
-} // namespace services
-} // namespace mojo
diff --git a/mojo/services/view_manager/view.h b/mojo/services/view_manager/view.h
deleted file mode 100644
index 83251c0..0000000
--- a/mojo/services/view_manager/view.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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_H_
-#define MOJO_SERVICES_VIEW_MANAGER_VIEW_H_
-
-#include <vector>
-
-#include "base/logging.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace mojo {
-namespace services {
-namespace view_manager {
-
-class Node;
-
-// Represents a view. A view may be associated with a single Node.
-class MOJO_VIEW_MANAGER_EXPORT View {
- public:
- explicit View(const ViewId& id);
- ~View();
-
- const ViewId& id() const { return id_; }
-
- Node* node() { return node_; }
-
- private:
- // Node is responsible for maintaining |node_|.
- friend class Node;
-
- void set_node(Node* node) { node_ = node; }
-
- const ViewId id_;
- Node* node_;
-
- DISALLOW_COPY_AND_ASSIGN(View);
-};
-
-} // namespace view_manager
-} // namespace services
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_H_
diff --git a/mojo/services/view_manager/view_manager_connection.cc b/mojo/services/view_manager/view_manager_connection.cc
index 4aa2d4e..83c061b 100644
--- a/mojo/services/view_manager/view_manager_connection.cc
+++ b/mojo/services/view_manager/view_manager_connection.cc
@@ -7,7 +7,6 @@
#include "base/stl_util.h"
#include "mojo/services/view_manager/node.h"
#include "mojo/services/view_manager/root_node_manager.h"
-#include "mojo/services/view_manager/view.h"
namespace mojo {
namespace services {
@@ -17,20 +16,6 @@ ViewManagerConnection::ViewManagerConnection() : id_(0) {
}
ViewManagerConnection::~ViewManagerConnection() {
- // Delete any views we own.
- while (!view_map_.empty()) {
- bool result = DeleteViewImpl(this, view_map_.begin()->second->id(), 0);
- DCHECK(result);
- }
-
- // We're about to destroy all our nodes. Detach any views from them.
- for (NodeMap::iterator i = node_map_.begin(); i != node_map_.end(); ++i) {
- if (i->second->view()) {
- bool result = SetViewImpl(i->second->id(), ViewId(), 0);
- DCHECK(result);
- }
- }
-
STLDeleteContainerPairSecondPointers(node_map_.begin(), node_map_.end());
context()->RemoveConnection(this);
}
@@ -54,14 +39,6 @@ Node* ViewManagerConnection::GetNode(const NodeId& id) {
return context()->GetNode(id);
}
-View* ViewManagerConnection::GetView(const ViewId& id) {
- if (id_ == id.connection_id) {
- ViewMap::const_iterator i = view_map_.find(id.view_id);
- return i == view_map_.end() ? NULL : i->second;
- }
- return context()->GetView(id);
-}
-
void ViewManagerConnection::NotifyNodeHierarchyChanged(
const NodeId& node,
const NodeId& new_parent,
@@ -73,64 +50,6 @@ void ViewManagerConnection::NotifyNodeHierarchyChanged(
change_id);
}
-void ViewManagerConnection::NotifyNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id,
- int32_t change_id) {
- client()->OnNodeViewReplaced(NodeIdToTransportId(node),
- ViewIdToTransportId(new_view_id),
- ViewIdToTransportId(old_view_id),
- change_id);
-}
-
-bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source,
- const NodeId& node_id,
- int32_t change_id) {
- DCHECK_EQ(node_id.connection_id, id_);
- Node* node = GetNode(node_id);
- if (!node)
- return false;
- RootNodeManager::ScopedChange change(source, context(), change_id);
- if (node->GetParent())
- node->GetParent()->Remove(node);
- std::vector<Node*> children(node->GetChildren());
- for (size_t i = 0; i < children.size(); ++i)
- node->Remove(children[i]);
- DCHECK(node->GetChildren().empty());
- node_map_.erase(node_id.node_id);
- delete node;
- return true;
-}
-
-bool ViewManagerConnection::DeleteViewImpl(ViewManagerConnection* source,
- const ViewId& view_id,
- int32_t change_id) {
- DCHECK_EQ(view_id.connection_id, id_);
- View* view = GetView(view_id);
- if (!view)
- return false;
- RootNodeManager::ScopedChange change(source, context(), change_id);
- if (view->node())
- view->node()->SetView(NULL);
- view_map_.erase(view_id.view_id);
- delete view;
- return true;
-}
-
-bool ViewManagerConnection::SetViewImpl(const NodeId& node_id,
- const ViewId& view_id,
- int32_t change_id) {
- Node* node = GetNode(node_id);
- if (!node)
- return false;
- View* view = GetView(view_id);
- if (!view && view_id != ViewId())
- return false;
- RootNodeManager::ScopedChange change(this, context(), change_id);
- node->SetView(view);
- return true;
-}
-
void ViewManagerConnection::CreateNode(
uint16_t node_id,
const Callback<void(bool)>& callback) {
@@ -143,17 +62,6 @@ void ViewManagerConnection::CreateNode(
callback.Run(true);
}
-void ViewManagerConnection::DeleteNode(
- uint32_t transport_node_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) {
- const NodeId node_id(NodeIdFromTransportId(transport_node_id));
- ViewManagerConnection* connection = context()->GetConnection(
- node_id.connection_id);
- callback.Run(connection &&
- connection->DeleteNodeImpl(this, node_id, change_id));
-}
-
void ViewManagerConnection::AddNode(
uint32_t parent_id,
uint32_t child_id,
@@ -182,50 +90,12 @@ void ViewManagerConnection::RemoveNodeFromParent(
callback.Run(success);
}
-void ViewManagerConnection::CreateView(
- uint16_t view_id,
- const mojo::Callback<void(bool)>& callback) {
- if (view_map_.count(view_id)) {
- callback.Run(false);
- return;
- }
- view_map_[view_id] = new View(ViewId(id_, view_id));
- callback.Run(true);
-}
-
-void ViewManagerConnection::DeleteView(
- uint32_t transport_view_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE {
- const ViewId view_id(ViewIdFromTransportId(transport_view_id));
- ViewManagerConnection* connection = context()->GetConnection(
- view_id.connection_id);
- callback.Run(connection &&
- connection->DeleteViewImpl(this, view_id, change_id));
-}
-
-void ViewManagerConnection::SetView(
- uint32_t transport_node_id,
- uint32_t transport_view_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) {
- const NodeId node_id(NodeIdFromTransportId(transport_node_id));
- callback.Run(SetViewImpl(node_id, ViewIdFromTransportId(transport_view_id),
- change_id));
-}
-
void ViewManagerConnection::OnNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent) {
context()->NotifyNodeHierarchyChanged(node, new_parent, old_parent);
}
-void ViewManagerConnection::OnNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id) {
- context()->NotifyNodeViewReplaced(node, new_view_id, old_view_id);
-}
-
} // namespace view_manager
} // namespace services
} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_connection.h b/mojo/services/view_manager/view_manager_connection.h
index c9124f6..a03ef6a 100644
--- a/mojo/services/view_manager/view_manager_connection.h
+++ b/mojo/services/view_manager/view_manager_connection.h
@@ -19,7 +19,6 @@ namespace view_manager {
class Node;
class RootNodeManager;
-class View;
// Manages a connection from the client.
class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
@@ -37,49 +36,21 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory,
ScopedMessagePipeHandle client_handle);
- // Returns the Node with the specified id.
+ // Returns the Node by id.
Node* GetNode(const NodeId& id);
- // Returns the View with the specified id.
- View* GetView(const ViewId& id);
-
// Notifies the client of a hierarchy change.
void NotifyNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent,
int32_t change_id);
- void NotifyNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id,
- int32_t change_id);
private:
typedef std::map<uint16_t, Node*> NodeMap;
- typedef std::map<uint16_t, View*> ViewMap;
-
- // Deletes a node owned by this connection. Returns true on success. |source|
- // is the connection that originated the change.
- bool DeleteNodeImpl(ViewManagerConnection* source,
- const NodeId& node_id,
- int32_t change_id);
-
- // Deletes a view owned by this connection. Returns true on success. |source|
- // is the connection that originated the change.
- bool DeleteViewImpl(ViewManagerConnection* source,
- const ViewId& view_id,
- int32_t change_id);
-
- // Sets the view associated with a node.
- bool SetViewImpl(const NodeId& node_id,
- const ViewId& view_id,
- int32_t change_id);
// Overridden from ViewManager:
virtual void CreateNode(uint16_t node_id,
const Callback<void(bool)>& callback) OVERRIDE;
- virtual void DeleteNode(uint32_t transport_node_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE;
virtual void AddNode(uint32_t parent_id,
uint32_t child_id,
int32_t change_id,
@@ -88,23 +59,11 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
uint32_t node_id,
int32_t change_id,
const Callback<void(bool)>& callback) OVERRIDE;
- virtual void CreateView(uint16_t view_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE;
- virtual void DeleteView(uint32_t transport_view_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE;
- virtual void SetView(uint32_t transport_node_id,
- uint32_t transport_view_id,
- int32_t change_id,
- const mojo::Callback<void(bool)>& callback) OVERRIDE;
// Overriden from NodeDelegate:
virtual void OnNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent) OVERRIDE;
- virtual void OnNodeViewReplaced(const NodeId& node,
- const ViewId& new_view_id,
- const ViewId& old_view_id);
// Id of this connection as assigned by RootNodeManager. Assigned in
// Initialize().
@@ -112,8 +71,6 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
NodeMap node_map_;
- ViewMap view_map_;
-
DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection);
};
diff --git a/mojo/services/view_manager/view_manager_connection_unittest.cc b/mojo/services/view_manager/view_manager_connection_unittest.cc
index 231c903..88bf323 100644
--- a/mojo/services/view_manager/view_manager_connection_unittest.cc
+++ b/mojo/services/view_manager/view_manager_connection_unittest.cc
@@ -53,11 +53,6 @@ uint32_t CreateNodeId(uint16_t connection_id, uint16_t node_id) {
return NodeIdToTransportId(NodeId(connection_id, node_id));
}
-// Creates an id used for transport from the specified parameters.
-uint32_t CreateViewId(uint16_t connection_id, uint16_t view_id) {
- return ViewIdToTransportId(ViewId(connection_id, view_id));
-}
-
// Creates a node with the specified id. Returns true on success. Blocks until
// we get back result from server.
bool CreateNode(ViewManager* view_manager, uint16_t id) {
@@ -67,19 +62,6 @@ bool CreateNode(ViewManager* view_manager, uint16_t id) {
return result;
}
-// TODO(sky): make a macro for these functions, they are all the same.
-
-// Deletes a node, blocking until done.
-bool DeleteNode(ViewManager* view_manager,
- uint32_t node_id,
- int32_t change_id) {
- bool result = false;
- view_manager->DeleteNode(node_id, change_id,
- base::Bind(&BooleanCallback, &result));
- DoRunLoop();
- return result;
-}
-
// Adds a node, blocking until done.
bool AddNode(ViewManager* view_manager,
uint32_t parent,
@@ -103,28 +85,6 @@ bool RemoveNodeFromParent(ViewManager* view_manager,
return result;
}
-// Creates a view with the specified id. Returns true on success. Blocks until
-// we get back result from server.
-bool CreateView(ViewManager* view_manager, uint16_t id) {
- bool result = false;
- view_manager->CreateView(id, base::Bind(&BooleanCallback, &result));
- DoRunLoop();
- return result;
-}
-
-// Sets a view on the specified node. Returns true on success. Blocks until we
-// get back result from server.
-bool SetView(ViewManager* view_manager,
- uint32_t node_id,
- uint32_t view_id,
- int32_t change_id) {
- bool result = false;
- view_manager->SetView(node_id, view_id, change_id,
- base::Bind(&BooleanCallback, &result));
- DoRunLoop();
- return result;
-}
-
} // namespace
typedef std::vector<std::string> Changes;
@@ -159,24 +119,10 @@ class ViewManagerClientImpl : public ViewManagerClient {
change_id, NodeIdToString(node).c_str(),
NodeIdToString(new_parent).c_str(),
NodeIdToString(old_parent).c_str()));
- QuitIfNecessary();
- }
- virtual void OnNodeViewReplaced(uint32_t node,
- uint32_t new_view_id,
- uint32_t old_view_id,
- int32_t change_id) OVERRIDE {
- changes_.push_back(
- base::StringPrintf(
- "change_id=%d node=%s new_view=%s old_view=%s",
- change_id, NodeIdToString(node).c_str(),
- NodeIdToString(new_view_id).c_str(),
- NodeIdToString(old_view_id).c_str()));
- QuitIfNecessary();
- }
-
- void QuitIfNecessary() {
- if (quit_count_ > 0 && --quit_count_ == 0)
- current_run_loop->Quit();
+ if (quit_count_ > 0) {
+ if (--quit_count_ == 0)
+ current_run_loop->Quit();
+ }
}
uint16_t id_;
@@ -216,11 +162,6 @@ class ViewManagerConnectionTest : public testing::Test {
DoRunLoop();
}
- void DestroySecondConnection() {
- connection2_.reset();
- view_manager2_.reset();
- }
-
Environment env_;
base::MessageLoop loop_;
RootNodeManager root_node_manager_;
@@ -238,9 +179,7 @@ class ViewManagerConnectionTest : public testing::Test {
// Verifies client gets a valid id.
TEST_F(ViewManagerConnectionTest, ValidId) {
- // All these tests assume 1 for the client id. The only real assertion here is
- // the client id is not zero, but adding this as rest of code here assumes 1.
- EXPECT_EQ(1, client_.id());
+ EXPECT_NE(0, client_.id());
}
// Verifies two clients/connections get different ids.
@@ -333,6 +272,7 @@ TEST_F(ViewManagerConnectionTest, AddRemoveNotifyMultipleConnections) {
TEST_F(ViewManagerConnectionTest, AddToRoot) {
ASSERT_TRUE(CreateNode(view_manager_.get(), 21));
ASSERT_TRUE(CreateNode(view_manager_.get(), 3));
+
EXPECT_TRUE(client_.GetAndClearChanges().empty());
// Make 3 a child of 21.
@@ -362,165 +302,6 @@ TEST_F(ViewManagerConnectionTest, AddToRoot) {
}
}
-// Verifies DeleteNode works.
-TEST_F(ViewManagerConnectionTest, DeleteNode) {
- ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
- ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
- EXPECT_TRUE(client_.GetAndClearChanges().empty());
-
- // Make 2 a child of 1.
- {
- AllocationScope scope;
- ASSERT_TRUE(AddNode(view_manager_.get(),
- CreateNodeId(client_.id(), 1),
- CreateNodeId(client_.id(), 2),
- 11));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=11 node=1,2 new_parent=1,1 old_parent=null",
- changes[0]);
- }
-
- // Add 1 to the root
- {
- AllocationScope scope;
- ASSERT_TRUE(AddNode(view_manager_.get(),
- CreateNodeId(0, 1),
- CreateNodeId(client_.id(), 1),
- 101));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=101 node=1,1 new_parent=0,1 old_parent=null",
- changes[0]);
- }
-
- // Delete 1.
- {
- AllocationScope scope;
- ASSERT_TRUE(DeleteNode(view_manager_.get(),
- CreateNodeId(client_.id(), 1),
- 121));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(2u, changes.size());
- EXPECT_EQ("change_id=121 node=1,1 new_parent=null old_parent=0,1",
- changes[0]);
- EXPECT_EQ("change_id=121 node=1,2 new_parent=null old_parent=1,1",
- changes[1]);
- }
-}
-
-// Assertions around setting a view.
-TEST_F(ViewManagerConnectionTest, SetView) {
- ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
- ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
- ASSERT_TRUE(CreateView(view_manager_.get(), 11));
- EXPECT_TRUE(client_.GetAndClearChanges().empty());
-
- // Set view 11 on node 1.
- {
- ASSERT_TRUE(SetView(view_manager_.get(),
- CreateNodeId(client_.id(), 1),
- CreateViewId(client_.id(), 11),
- 21));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=21 node=1,1 new_view=1,11 old_view=null",
- changes[0]);
- }
-
- // Set view 11 on node 2.
- {
- ASSERT_TRUE(SetView(view_manager_.get(),
- CreateNodeId(client_.id(), 2),
- CreateViewId(client_.id(), 11),
- 22));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(2u, changes.size());
- EXPECT_EQ("change_id=22 node=1,1 new_view=null old_view=1,11",
- changes[0]);
- EXPECT_EQ("change_id=22 node=1,2 new_view=1,11 old_view=null",
- changes[1]);
- }
-}
-
-// Verifies deleting a node with a view sends correct notifications.
-TEST_F(ViewManagerConnectionTest, DeleteNodeWithView) {
- ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
- ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
- ASSERT_TRUE(CreateView(view_manager_.get(), 11));
- EXPECT_TRUE(client_.GetAndClearChanges().empty());
-
- // Set view 11 on node 1.
- ASSERT_TRUE(SetView(view_manager_.get(),
- CreateNodeId(client_.id(), 1),
- CreateViewId(client_.id(), 11),
- 21));
- client_.GetAndClearChanges();
-
- // Delete node 1.
- {
- ASSERT_TRUE(DeleteNode(view_manager_.get(),
- CreateNodeId(client_.id(), 1),
- 121));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=121 node=1,1 new_view=null old_view=1,11",
- changes[0]);
- }
-
- // Set view 11 on node 2.
- {
- ASSERT_TRUE(SetView(view_manager_.get(),
- CreateNodeId(client_.id(), 2),
- CreateViewId(client_.id(), 11),
- 22));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=22 node=1,2 new_view=1,11 old_view=null", changes[0]);
- }
-}
-
-// Sets view from one connection on another.
-TEST_F(ViewManagerConnectionTest, SetViewFromSecondConnection) {
- EstablishSecondConnection();
-
- // Create two nodes in first connection.
- ASSERT_TRUE(CreateNode(view_manager_.get(), 1));
- ASSERT_TRUE(CreateNode(view_manager_.get(), 2));
-
- EXPECT_TRUE(client_.GetAndClearChanges().empty());
- EXPECT_TRUE(client2_.GetAndClearChanges().empty());
-
- // Create a view in the second connection.
- ASSERT_TRUE(CreateView(view_manager2_.get(), 51));
-
- // Attach view to node 1 in the first connection.
- {
- ASSERT_TRUE(SetView(view_manager2_.get(),
- CreateNodeId(client_.id(), 1),
- CreateViewId(client2_.id(), 51),
- 22));
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=0 node=1,1 new_view=2,51 old_view=null", changes[0]);
-
- changes = client2_.GetAndClearChanges();
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=22 node=1,1 new_view=2,51 old_view=null", changes[0]);
- }
-
- // Shutdown the second connection and verify view is removed.
- {
- DestroySecondConnection();
- client_.set_quit_count(1);
- DoRunLoop();
-
- Changes changes(client_.GetAndClearChanges());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("change_id=0 node=1,1 new_view=null old_view=2,51", changes[0]);
- }
-}
-
} // namespace view_manager
} // namespace services
} // namespace mojo