Commit 55b1b08c authored by sky@chromium.org's avatar sky@chromium.org

Makes change_id unsigned

Easier this way for clients to track and not worry about overflow.

BUG=none
TEST=none
R=ben@chromium.org

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=266793

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266886 0039d316-1c4b-4281-b951-d872f2087c98
parent cd5b4adb
......@@ -49,12 +49,12 @@ class SampleApp : public Application,
virtual void OnNodeHierarchyChanged(uint32_t node,
uint32_t new_parent,
uint32_t old_parent,
int32_t change_id) OVERRIDE {
uint32_t change_id) OVERRIDE {
}
virtual void OnNodeViewReplaced(uint32_t node,
uint32_t old_view_id,
uint32_t new_view_id,
int32_t change_id) OVERRIDE {
uint32_t change_id) OVERRIDE {
}
private:
......
......@@ -23,24 +23,24 @@ interface ViewManager {
// 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);
DeleteNode(uint32 node_id, uint32 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);
AddNode(uint32 parent, uint32 child, uint32 change_id) => (bool success);
// Removes a view from its current parent. See description above class for
// details of |change_id|.
RemoveNodeFromParent(uint32 node_id, int32 change_id) => (bool success);
RemoveNodeFromParent(uint32 node_id, uint32 change_id) => (bool success);
// 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);
DeleteView(uint32 view_id, uint32 change_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_id, uint32 view_id, uint32 change_id) => (bool success);
};
[Peer=ViewManager]
......@@ -55,14 +55,14 @@ interface ViewManagerClient {
OnNodeHierarchyChanged(uint32 node,
uint32 new_parent,
uint32 old_parent,
int32 change_id);
uint32 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);
uint32 change_id);
};
}
......@@ -11,6 +11,8 @@ namespace mojo {
namespace services {
namespace view_manager {
typedef uint32_t ChangeId;
// Adds a bit of type safety to node ids.
struct MOJO_VIEW_MANAGER_EXPORT NodeId {
NodeId(uint16_t connection_id, uint16_t node_id)
......
......@@ -19,7 +19,7 @@ const uint16_t kRootId = 1;
RootNodeManager::ScopedChange::ScopedChange(ViewManagerConnection* connection,
RootNodeManager* root,
int32_t change_id)
ChangeId change_id)
: root_(root) {
root_->PrepareForChange(connection, change_id);
}
......@@ -73,7 +73,7 @@ void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node,
const NodeId& old_parent) {
for (ConnectionMap::iterator i = connection_map_.begin();
i != connection_map_.end(); ++i) {
const int32_t change_id = (change_ && i->first == change_->connection_id) ?
const ChangeId change_id = (change_ && i->first == change_->connection_id) ?
change_->change_id : 0;
i->second->NotifyNodeHierarchyChanged(
node, new_parent, old_parent, change_id);
......@@ -86,7 +86,7 @@ void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node,
// 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) ?
const ChangeId change_id = (change_ && i->first == change_->connection_id) ?
change_->change_id : 0;
i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id,
change_id);
......@@ -94,7 +94,7 @@ void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node,
}
void RootNodeManager::PrepareForChange(ViewManagerConnection* connection,
int32_t change_id) {
ChangeId change_id) {
DCHECK(!change_.get()); // Should only ever have one change in flight.
change_.reset(new Change(connection->id(), change_id));
}
......
......@@ -32,7 +32,7 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
public:
ScopedChange(ViewManagerConnection* connection,
RootNodeManager* root,
int32_t change_id);
ChangeId change_id);
~ScopedChange();
private:
......@@ -71,13 +71,13 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
private:
// Tracks a change.
struct Change {
Change(int32_t connection_id, int32_t change_id)
Change(int32_t connection_id, ChangeId change_id)
: connection_id(connection_id),
change_id(change_id) {
}
int32_t connection_id;
int32_t change_id;
ChangeId change_id;
};
typedef std::map<uint16_t, ViewManagerConnection*> ConnectionMap;
......@@ -88,7 +88,7 @@ class MOJO_VIEW_MANAGER_EXPORT RootNodeManager
// Changes should never nest, meaning each PrepareForChange() must be
// balanced with a call to FinishChange() with no PrepareForChange()
// in between.
void PrepareForChange(ViewManagerConnection* connection, int32_t change_id);
void PrepareForChange(ViewManagerConnection* connection, ChangeId change_id);
// Balances a call to PrepareForChange().
void FinishChange();
......
......@@ -66,7 +66,7 @@ void ViewManagerConnection::NotifyNodeHierarchyChanged(
const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent,
int32_t change_id) {
ChangeId change_id) {
client()->OnNodeHierarchyChanged(NodeIdToTransportId(node),
NodeIdToTransportId(new_parent),
NodeIdToTransportId(old_parent),
......@@ -76,7 +76,7 @@ void ViewManagerConnection::NotifyNodeHierarchyChanged(
void ViewManagerConnection::NotifyNodeViewReplaced(const NodeId& node,
const ViewId& new_view_id,
const ViewId& old_view_id,
int32_t change_id) {
ChangeId change_id) {
client()->OnNodeViewReplaced(NodeIdToTransportId(node),
ViewIdToTransportId(new_view_id),
ViewIdToTransportId(old_view_id),
......@@ -85,7 +85,7 @@ void ViewManagerConnection::NotifyNodeViewReplaced(const NodeId& node,
bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source,
const NodeId& node_id,
int32_t change_id) {
ChangeId change_id) {
DCHECK_EQ(node_id.connection_id, id_);
Node* node = GetNode(node_id);
if (!node)
......@@ -104,7 +104,7 @@ bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source,
bool ViewManagerConnection::DeleteViewImpl(ViewManagerConnection* source,
const ViewId& view_id,
int32_t change_id) {
ChangeId change_id) {
DCHECK_EQ(view_id.connection_id, id_);
View* view = GetView(view_id);
if (!view)
......@@ -119,7 +119,7 @@ bool ViewManagerConnection::DeleteViewImpl(ViewManagerConnection* source,
bool ViewManagerConnection::SetViewImpl(const NodeId& node_id,
const ViewId& view_id,
int32_t change_id) {
ChangeId change_id) {
Node* node = GetNode(node_id);
if (!node)
return false;
......@@ -145,7 +145,7 @@ void ViewManagerConnection::CreateNode(
void ViewManagerConnection::DeleteNode(
uint32_t transport_node_id,
int32_t change_id,
ChangeId change_id,
const mojo::Callback<void(bool)>& callback) {
const NodeId node_id(NodeIdFromTransportId(transport_node_id));
ViewManagerConnection* connection = context()->GetConnection(
......@@ -157,7 +157,7 @@ void ViewManagerConnection::DeleteNode(
void ViewManagerConnection::AddNode(
uint32_t parent_id,
uint32_t child_id,
int32_t change_id,
ChangeId change_id,
const Callback<void(bool)>& callback) {
Node* parent = GetNode(NodeIdFromTransportId(parent_id));
Node* child = GetNode(NodeIdFromTransportId(child_id));
......@@ -171,7 +171,7 @@ void ViewManagerConnection::AddNode(
void ViewManagerConnection::RemoveNodeFromParent(
uint32_t node_id,
int32_t change_id,
ChangeId change_id,
const Callback<void(bool)>& callback) {
Node* node = GetNode(NodeIdFromTransportId(node_id));
const bool success = (node && node->GetParent());
......@@ -195,7 +195,7 @@ void ViewManagerConnection::CreateView(
void ViewManagerConnection::DeleteView(
uint32_t transport_view_id,
int32_t change_id,
ChangeId change_id,
const mojo::Callback<void(bool)>& callback) {
const ViewId view_id(ViewIdFromTransportId(transport_view_id));
ViewManagerConnection* connection = context()->GetConnection(
......@@ -207,7 +207,7 @@ void ViewManagerConnection::DeleteView(
void ViewManagerConnection::SetView(
uint32_t transport_node_id,
uint32_t transport_view_id,
int32_t change_id,
ChangeId 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),
......
......@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "mojo/public/cpp/shell/service.h"
#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
#include "mojo/services/view_manager/ids.h"
#include "mojo/services/view_manager/node_delegate.h"
#include "mojo/services/view_manager/view_manager_export.h"
......@@ -47,11 +48,11 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
void NotifyNodeHierarchyChanged(const NodeId& node,
const NodeId& new_parent,
const NodeId& old_parent,
int32_t change_id);
ChangeId change_id);
void NotifyNodeViewReplaced(const NodeId& node,
const ViewId& new_view_id,
const ViewId& old_view_id,
int32_t change_id);
ChangeId change_id);
private:
typedef std::map<uint16_t, Node*> NodeMap;
......@@ -61,41 +62,41 @@ class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection
// is the connection that originated the change.
bool DeleteNodeImpl(ViewManagerConnection* source,
const NodeId& node_id,
int32_t change_id);
ChangeId 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);
ChangeId change_id);
// Sets the view associated with a node.
bool SetViewImpl(const NodeId& node_id,
const ViewId& view_id,
int32_t change_id);
ChangeId 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,
ChangeId change_id,
const mojo::Callback<void(bool)>& callback) OVERRIDE;
virtual void AddNode(uint32_t parent_id,
uint32_t child_id,
int32_t change_id,
ChangeId change_id,
const Callback<void(bool)>& callback) OVERRIDE;
virtual void RemoveNodeFromParent(
uint32_t node_id,
int32_t change_id,
ChangeId 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,
ChangeId 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,
ChangeId change_id,
const mojo::Callback<void(bool)>& callback) OVERRIDE;
// Overriden from NodeDelegate:
......
......@@ -23,6 +23,9 @@ namespace view_manager {
namespace {
// TODO(sky): move ids.h into common place and include that.
typedef uint32_t ChangeId;
base::RunLoop* current_run_loop = NULL;
// Sets |current_run_loop| and runs it. It is expected that someone else quits
......@@ -72,7 +75,7 @@ bool CreateNode(ViewManager* view_manager, uint16_t id) {
// Deletes a node, blocking until done.
bool DeleteNode(ViewManager* view_manager,
uint32_t node_id,
int32_t change_id) {
ChangeId change_id) {
bool result = false;
view_manager->DeleteNode(node_id, change_id,
base::Bind(&BooleanCallback, &result));
......@@ -84,7 +87,7 @@ bool DeleteNode(ViewManager* view_manager,
bool AddNode(ViewManager* view_manager,
uint32_t parent,
uint32_t child,
int32_t change_id) {
ChangeId change_id) {
bool result = false;
view_manager->AddNode(parent, child, change_id,
base::Bind(&BooleanCallback, &result));
......@@ -95,7 +98,7 @@ bool AddNode(ViewManager* view_manager,
// Removes a node, blocking until done.
bool RemoveNodeFromParent(ViewManager* view_manager,
uint32_t node_id,
int32_t change_id) {
ChangeId change_id) {
bool result = false;
view_manager->RemoveNodeFromParent(node_id, change_id,
base::Bind(&BooleanCallback, &result));
......@@ -117,7 +120,7 @@ bool CreateView(ViewManager* view_manager, uint16_t id) {
bool SetView(ViewManager* view_manager,
uint32_t node_id,
uint32_t view_id,
int32_t change_id) {
ChangeId change_id) {
bool result = false;
view_manager->SetView(node_id, view_id, change_id,
base::Bind(&BooleanCallback, &result));
......@@ -152,11 +155,11 @@ class ViewManagerClientImpl : public ViewManagerClient {
virtual void OnNodeHierarchyChanged(uint32_t node,
uint32_t new_parent,
uint32_t old_parent,
int32_t change_id) OVERRIDE {
ChangeId change_id) OVERRIDE {
changes_.push_back(
base::StringPrintf(
"change_id=%d node=%s new_parent=%s old_parent=%s",
change_id, NodeIdToString(node).c_str(),
static_cast<int>(change_id), NodeIdToString(node).c_str(),
NodeIdToString(new_parent).c_str(),
NodeIdToString(old_parent).c_str()));
QuitIfNecessary();
......@@ -164,11 +167,11 @@ class ViewManagerClientImpl : public ViewManagerClient {
virtual void OnNodeViewReplaced(uint32_t node,
uint32_t new_view_id,
uint32_t old_view_id,
int32_t change_id) OVERRIDE {
ChangeId 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(),
static_cast<int>(change_id), NodeIdToString(node).c_str(),
NodeIdToString(new_view_id).c_str(),
NodeIdToString(old_view_id).c_str()));
QuitIfNecessary();
......
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