diff options
3 files changed, 10 insertions, 43 deletions
diff --git a/ios/chrome/browser/browser_state/browser_state_info_cache.cc b/ios/chrome/browser/browser_state/browser_state_info_cache.cc index ceac087..e242c31 100644 --- a/ios/chrome/browser/browser_state/browser_state_info_cache.cc +++ b/ios/chrome/browser/browser_state/browser_state_info_cache.cc @@ -4,6 +4,8 @@ #include "ios/chrome/browser/browser_state/browser_state_info_cache.h" +#include <algorithm> + #include "base/i18n/case_conversion.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -16,7 +18,6 @@ namespace { const char kGAIAIdKey[] = "gaia_id"; const char kIsAuthErrorKey[] = "is_auth_error"; -const char kNameKey[] = "name"; const char kUserNameKey[] = "user_name"; } @@ -31,9 +32,7 @@ BrowserStateInfoCache::BrowserStateInfoCache( it.Advance()) { base::DictionaryValue* info = nullptr; cache->GetDictionaryWithoutPathExpansion(it.key(), &info); - base::string16 name; - info->GetString(kNameKey, &name); - sorted_keys_.insert(FindPositionForBrowserState(it.key(), name), it.key()); + AddBrowserStateCacheKey(it.key()); } } @@ -41,7 +40,6 @@ BrowserStateInfoCache::~BrowserStateInfoCache() {} void BrowserStateInfoCache::AddBrowserState( const base::FilePath& browser_state_path, - const base::string16& name, const std::string& gaia_id, const base::string16& user_name) { std::string key = CacheKeyFromBrowserStatePath(browser_state_path); @@ -49,12 +47,10 @@ void BrowserStateInfoCache::AddBrowserState( base::DictionaryValue* cache = update.Get(); scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); - info->SetString(kNameKey, name); info->SetString(kGAIAIdKey, gaia_id); info->SetString(kUserNameKey, user_name); cache->SetWithoutPathExpansion(key, info.release()); - - sorted_keys_.insert(FindPositionForBrowserState(key, name), key); + AddBrowserStateCacheKey(key); FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, OnBrowserStateAdded(browser_state_path)); @@ -78,8 +74,6 @@ void BrowserStateInfoCache::RemoveBrowserState( NOTREACHED(); return; } - base::string16 name = GetNameOfBrowserStateAtIndex(browser_state_index); - DictionaryPrefUpdate update(prefs_, ios::prefs::kBrowserStateInfoCache); base::DictionaryValue* cache = update.Get(); std::string key = CacheKeyFromBrowserStatePath(browser_state_path); @@ -87,7 +81,7 @@ void BrowserStateInfoCache::RemoveBrowserState( sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, - OnBrowserStateWasRemoved(browser_state_path, name)); + OnBrowserStateWasRemoved(browser_state_path)); } size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const { @@ -106,13 +100,6 @@ size_t BrowserStateInfoCache::GetIndexOfBrowserStateWithPath( return std::string::npos; } -base::string16 BrowserStateInfoCache::GetNameOfBrowserStateAtIndex( - size_t index) const { - base::string16 name; - GetInfoForBrowserStateAtIndex(index)->GetString(kNameKey, &name); - return name; -} - base::string16 BrowserStateInfoCache::GetUserNameOfBrowserStateAtIndex( size_t index) const { base::string16 user_name; @@ -214,22 +201,7 @@ std::string BrowserStateInfoCache::CacheKeyFromBrowserStatePath( return base_name.MaybeAsASCII(); } -std::vector<std::string>::iterator -BrowserStateInfoCache::FindPositionForBrowserState( - const std::string& search_key, - const base::string16& search_name) { - base::string16 search_name_l = base::i18n::ToLower(search_name); - for (size_t i = 0; i < GetNumberOfBrowserStates(); ++i) { - base::string16 name_l = - base::i18n::ToLower(GetNameOfBrowserStateAtIndex(i)); - int name_compare = search_name_l.compare(name_l); - if (name_compare < 0) - return sorted_keys_.begin() + i; - if (name_compare == 0) { - int key_compare = search_key.compare(sorted_keys_[i]); - if (key_compare < 0) - return sorted_keys_.begin() + i; - } - } - return sorted_keys_.end(); +void BrowserStateInfoCache::AddBrowserStateCacheKey(const std::string& key) { + sorted_keys_.insert( + std::upper_bound(sorted_keys_.begin(), sorted_keys_.end(), key), key); } diff --git a/ios/chrome/browser/browser_state/browser_state_info_cache.h b/ios/chrome/browser/browser_state/browser_state_info_cache.h index 53fc47b..7622848 100644 --- a/ios/chrome/browser/browser_state/browser_state_info_cache.h +++ b/ios/chrome/browser/browser_state/browser_state_info_cache.h @@ -30,7 +30,6 @@ class BrowserStateInfoCache { virtual ~BrowserStateInfoCache(); void AddBrowserState(const base::FilePath& browser_state_path, - const base::string16& name, const std::string& gaia_id, const base::string16& user_name); void RemoveBrowserState(const base::FilePath& browser_state_path); @@ -45,7 +44,6 @@ class BrowserStateInfoCache { // Gets and sets information related to browser states. size_t GetIndexOfBrowserStateWithPath( const base::FilePath& browser_state_path) const; - base::string16 GetNameOfBrowserStateAtIndex(size_t index) const; base::string16 GetUserNameOfBrowserStateAtIndex(size_t index) const; base::FilePath GetPathOfBrowserStateAtIndex(size_t index) const; std::string GetGAIAIdOfBrowserStateAtIndex(size_t index) const; @@ -69,9 +67,7 @@ class BrowserStateInfoCache { std::string CacheKeyFromBrowserStatePath( const base::FilePath& browser_state_path) const; - std::vector<std::string>::iterator FindPositionForBrowserState( - const std::string& search_key, - const base::string16& search_name); + void AddBrowserStateCacheKey(const std::string& key); PrefService* prefs_; std::vector<std::string> sorted_keys_; diff --git a/ios/chrome/browser/browser_state/browser_state_info_cache_observer.h b/ios/chrome/browser/browser_state/browser_state_info_cache_observer.h index 9a77b85..2d8d91c 100644 --- a/ios/chrome/browser/browser_state/browser_state_info_cache_observer.h +++ b/ios/chrome/browser/browser_state/browser_state_info_cache_observer.h @@ -22,8 +22,7 @@ class BrowserStateInfoCacheObserver { virtual void OnBrowserStateAdded(const base::FilePath& path) = 0; // Called when a BrowserState has been removed. - virtual void OnBrowserStateWasRemoved(const base::FilePath& path, - const base::string16& name) = 0; + virtual void OnBrowserStateWasRemoved(const base::FilePath& path) = 0; private: DISALLOW_COPY_AND_ASSIGN(BrowserStateInfoCacheObserver); |