Index: chrome/browser/sync/glue/tab_node_pool.cc |
diff --git a/chrome/browser/sync/glue/tab_node_pool.cc b/chrome/browser/sync/glue/tab_node_pool.cc |
index 69ed09f83d70f7746a380af96b6c0beb72d27733..194eaeb94b546b8ddab51fa90fd1c89fc71225d2 100644 |
--- a/chrome/browser/sync/glue/tab_node_pool.cc |
+++ b/chrome/browser/sync/glue/tab_node_pool.cc |
@@ -23,8 +23,8 @@ static const char kNoSessionsFolderError[] = |
TabNodePool::TabNodePool( |
ProfileSyncService* sync_service) |
: tab_pool_fp_(-1), |
- sync_service_(sync_service) { |
-} |
+ max_used_tab_node_id_(0), |
+ sync_service_(sync_service) {} |
TabNodePool::~TabNodePool() {} |
@@ -35,9 +35,14 @@ std::string TabNodePool::TabIdToTag( |
return base::StringPrintf("%s %" PRIuS "", machine_tag.c_str(), tab_node_id); |
} |
-void TabNodePool::AddTabNode(int64 sync_id) { |
+void TabNodePool::AddOldTabNode(int64 sync_id, size_t tab_node_id) { |
+ DCHECK_GT(sync_id, 0); |
+ DCHECK(old_node_syncids_.find(sync_id) == old_node_syncids_.end()); |
+ if (max_used_tab_node_id_ < tab_node_id) |
+ max_used_tab_node_id_ = tab_node_id; |
+ // Grow the tab node pool by 1, to ensure tab pool is of correct size. |
tab_syncid_pool_.resize(tab_syncid_pool_.size() + 1); |
- tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; |
+ old_node_syncids_.insert(sync_id); |
Nicolas Zea
2013/06/06 21:27:39
I'm not sure we really need to have the notion of
shashi
2013/06/07 01:44:08
In case of Android we have two requirements:
1. Ol
Nicolas Zea
2013/06/07 14:42:28
Right, and I agree with that approach. My point is
shashi
2013/06/07 19:08:35
Got it, I am going to cleanup the API as per the s
|
} |
int64 TabNodePool::GetFreeTabNode() { |
@@ -51,7 +56,7 @@ int64 TabNodePool::GetFreeTabNode() { |
LOG(ERROR) << kNoSessionsFolderError; |
return syncer::kInvalidId; |
} |
- size_t tab_node_id = tab_syncid_pool_.size(); |
+ size_t tab_node_id = ++max_used_tab_node_id_; |
std::string tab_node_tag = TabIdToTag(machine_tag_, tab_node_id); |
syncer::WriteNode tab_node(&trans); |
syncer::WriteNode::InitUniqueByCreationResult result = |
@@ -72,9 +77,9 @@ int64 TabNodePool::GetFreeTabNode() { |
// Grow the pool by 1 since we created a new node. We don't actually need |
// to put the node's id in the pool now, since the pool is still empty. |
// The id will be added when that tab is closed and the node is freed. |
- tab_syncid_pool_.resize(tab_node_id + 1); |
- DVLOG(1) << "Adding sync node " |
- << tab_node.GetId() << " to tab syncid pool"; |
+ tab_syncid_pool_.resize(tab_syncid_pool_.size() + 1); |
+ DVLOG(1) << "Adding sync node " << tab_node.GetId() |
+ << " to tab syncid pool"; |
return tab_node.GetId(); |
} else { |
// There are nodes available, grab next free and decrement free pointer. |
@@ -88,4 +93,26 @@ void TabNodePool::FreeTabNode(int64 sync_id) { |
tab_syncid_pool_[static_cast<size_t>(++tab_pool_fp_)] = sync_id; |
} |
+bool TabNodePool::RemoveIfOldSyncNodeExists(int64 sync_id) { |
+ std::set<int64>::iterator position = old_node_syncids_.find(sync_id); |
+ if (position != old_node_syncids_.end()) { |
+ // If sync_id exists remove it and return. |
+ old_node_syncids_.erase(position); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void TabNodePool::FreeUnusedOldSyncNodes(const std::set<int64>& used_sync_ids) { |
+ for (std::set<int64>::iterator it = old_node_syncids_.begin(); |
+ it != old_node_syncids_.end();) { |
+ if (used_sync_ids.find(*it) == used_sync_ids.end()) { |
+ FreeTabNode(*it); |
+ old_node_syncids_.erase(it++); |
+ } else { |
+ ++it; |
+ } |
+ } |
+} |
+ |
} // namespace browser_sync |