Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: chrome/common/instant_restricted_id_cache.h

Issue 14660022: Move most visited item state info from InstantController to InstantService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/instant_restricted_id_cache.h
diff --git a/chrome/common/instant_restricted_id_cache.h b/chrome/common/instant_restricted_id_cache.h
index b0c2b3ba05e44eb294577ccdb18d3ad7222274b4..5935ea29c09eb250d2892bab60dec4fc58f0b538 100644
--- a/chrome/common/instant_restricted_id_cache.h
+++ b/chrome/common/instant_restricted_id_cache.h
@@ -69,6 +69,8 @@ class InstantRestrictedIDCache {
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, ManualIDGeneration);
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, MixIDGeneration);
FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest, AddEmptySet);
+ FRIEND_TEST_ALL_PREFIXES(InstantRestrictedIDCacheTest,
+ AddItemsWithRestrictedID);
typedef base::MRUCache<InstantRestrictedID, T> CacheImpl;
@@ -126,10 +128,15 @@ void InstantRestrictedIDCache<T>::AddItemsWithRestrictedID(
ids_added.insert(item_id.first);
cache_.Put(item_id.first, item_id.second);
- if (i == 0)
- last_add_start_ = --cache_.rend();
last_restricted_id_ = std::max(item_id.first, last_restricted_id_);
}
+
+ // cache_.Put() can invalidate the iterator |last_add_start_| is pointing to.
+ // Therefore, update |last_add_start_| after adding all the items to the
+ // |cache_|.
+ last_add_start_ = cache_.rend();
+ for (size_t i = 0; i < items.size(); ++i)
+ --last_add_start_;
}
template <typename T>
« no previous file with comments | « chrome/browser/ui/search/instant_page_unittest.cc ('k') | chrome/common/instant_restricted_id_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698