summaryrefslogtreecommitdiffstats
path: root/mojo/services
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 14:54:00 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 14:54:00 +0000
commit55b1b08cf398a46e62a210dc222026e16c7df142 (patch)
tree4fe493b92dc17a2adbc4bf4b11b0c7e787d910af /mojo/services
parentcd5b4adb9b74e959afd6fc4bab8758341c0e2e3d (diff)
downloadchromium_src-55b1b08cf398a46e62a210dc222026e16c7df142.zip
chromium_src-55b1b08cf398a46e62a210dc222026e16c7df142.tar.gz
chromium_src-55b1b08cf398a46e62a210dc222026e16c7df142.tar.bz2
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
Diffstat (limited to 'mojo/services')
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom14
-rw-r--r--mojo/services/view_manager/ids.h2
-rw-r--r--mojo/services/view_manager/root_node_manager.cc8
-rw-r--r--mojo/services/view_manager/root_node_manager.h8
-rw-r--r--mojo/services/view_manager/view_manager_connection.cc20
-rw-r--r--mojo/services/view_manager/view_manager_connection.h21
-rw-r--r--mojo/services/view_manager/view_manager_connection_unittest.cc19
7 files changed, 49 insertions, 43 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..c5a96a5 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -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);
};
}
diff --git a/mojo/services/view_manager/ids.h b/mojo/services/view_manager/ids.h
index d42e18f..11ffc35 100644
--- a/mojo/services/view_manager/ids.h
+++ b/mojo/services/view_manager/ids.h
@@ -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)
diff --git a/mojo/services/view_manager/root_node_manager.cc b/mojo/services/view_manager/root_node_manager.cc
index 210427a..6c2bf6d 100644
--- a/mojo/services/view_manager/root_node_manager.cc
+++ b/mojo/services/view_manager/root_node_manager.cc
@@ -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));
}
diff --git a/mojo/services/view_manager/root_node_manager.h b/mojo/services/view_manager/root_node_manager.h
index 98f347e..f9d1d97 100644
--- a/mojo/services/view_manager/root_node_manager.h
+++ b/mojo/services/view_manager/root_node_manager.h
@@ -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();
diff --git a/mojo/services/view_manager/view_manager_connection.cc b/mojo/services/view_manager/view_manager_connection.cc
index 2a1b173..7bdf0c4 100644
--- a/mojo/services/view_manager/view_manager_connection.cc
+++ b/mojo/services/view_manager/view_manager_connection.cc
@@ -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),
diff --git a/mojo/services/view_manager/view_manager_connection.h b/mojo/services/view_manager/view_manager_connection.h
index 974e033..02bfa52 100644
--- a/mojo/services/view_manager/view_manager_connection.h
+++ b/mojo/services/view_manager/view_manager_connection.h
@@ -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:
diff --git a/mojo/services/view_manager/view_manager_connection_unittest.cc b/mojo/services/view_manager/view_manager_connection_unittest.cc
index 231c903..abd03b3 100644
--- a/mojo/services/view_manager/view_manager_connection_unittest.cc
+++ b/mojo/services/view_manager/view_manager_connection_unittest.cc
@@ -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();