Commit aa1ab978 authored by droger's avatar droger Committed by Commit bot

[iOS] Remove BrowserState names in BrowserStateInfoCache

On iOS, BrowserState do not have names. The code to support names can be
removed.

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

Cr-Commit-Position: refs/heads/master@{#357090}
parent 186d6bfe
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ios/chrome/browser/browser_state/browser_state_info_cache.h" #include "ios/chrome/browser/browser_state/browser_state_info_cache.h"
#include <algorithm>
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -16,7 +18,6 @@ ...@@ -16,7 +18,6 @@
namespace { namespace {
const char kGAIAIdKey[] = "gaia_id"; const char kGAIAIdKey[] = "gaia_id";
const char kIsAuthErrorKey[] = "is_auth_error"; const char kIsAuthErrorKey[] = "is_auth_error";
const char kNameKey[] = "name";
const char kUserNameKey[] = "user_name"; const char kUserNameKey[] = "user_name";
} }
...@@ -31,9 +32,7 @@ BrowserStateInfoCache::BrowserStateInfoCache( ...@@ -31,9 +32,7 @@ BrowserStateInfoCache::BrowserStateInfoCache(
it.Advance()) { it.Advance()) {
base::DictionaryValue* info = nullptr; base::DictionaryValue* info = nullptr;
cache->GetDictionaryWithoutPathExpansion(it.key(), &info); cache->GetDictionaryWithoutPathExpansion(it.key(), &info);
base::string16 name; AddBrowserStateCacheKey(it.key());
info->GetString(kNameKey, &name);
sorted_keys_.insert(FindPositionForBrowserState(it.key(), name), it.key());
} }
} }
...@@ -41,7 +40,6 @@ BrowserStateInfoCache::~BrowserStateInfoCache() {} ...@@ -41,7 +40,6 @@ BrowserStateInfoCache::~BrowserStateInfoCache() {}
void BrowserStateInfoCache::AddBrowserState( void BrowserStateInfoCache::AddBrowserState(
const base::FilePath& browser_state_path, const base::FilePath& browser_state_path,
const base::string16& name,
const std::string& gaia_id, const std::string& gaia_id,
const base::string16& user_name) { const base::string16& user_name) {
std::string key = CacheKeyFromBrowserStatePath(browser_state_path); std::string key = CacheKeyFromBrowserStatePath(browser_state_path);
...@@ -49,12 +47,10 @@ void BrowserStateInfoCache::AddBrowserState( ...@@ -49,12 +47,10 @@ void BrowserStateInfoCache::AddBrowserState(
base::DictionaryValue* cache = update.Get(); base::DictionaryValue* cache = update.Get();
scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue); scoped_ptr<base::DictionaryValue> info(new base::DictionaryValue);
info->SetString(kNameKey, name);
info->SetString(kGAIAIdKey, gaia_id); info->SetString(kGAIAIdKey, gaia_id);
info->SetString(kUserNameKey, user_name); info->SetString(kUserNameKey, user_name);
cache->SetWithoutPathExpansion(key, info.release()); cache->SetWithoutPathExpansion(key, info.release());
AddBrowserStateCacheKey(key);
sorted_keys_.insert(FindPositionForBrowserState(key, name), key);
FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_,
OnBrowserStateAdded(browser_state_path)); OnBrowserStateAdded(browser_state_path));
...@@ -78,8 +74,6 @@ void BrowserStateInfoCache::RemoveBrowserState( ...@@ -78,8 +74,6 @@ void BrowserStateInfoCache::RemoveBrowserState(
NOTREACHED(); NOTREACHED();
return; return;
} }
base::string16 name = GetNameOfBrowserStateAtIndex(browser_state_index);
DictionaryPrefUpdate update(prefs_, ios::prefs::kBrowserStateInfoCache); DictionaryPrefUpdate update(prefs_, ios::prefs::kBrowserStateInfoCache);
base::DictionaryValue* cache = update.Get(); base::DictionaryValue* cache = update.Get();
std::string key = CacheKeyFromBrowserStatePath(browser_state_path); std::string key = CacheKeyFromBrowserStatePath(browser_state_path);
...@@ -87,7 +81,7 @@ void BrowserStateInfoCache::RemoveBrowserState( ...@@ -87,7 +81,7 @@ void BrowserStateInfoCache::RemoveBrowserState(
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_, FOR_EACH_OBSERVER(BrowserStateInfoCacheObserver, observer_list_,
OnBrowserStateWasRemoved(browser_state_path, name)); OnBrowserStateWasRemoved(browser_state_path));
} }
size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const { size_t BrowserStateInfoCache::GetNumberOfBrowserStates() const {
...@@ -106,13 +100,6 @@ size_t BrowserStateInfoCache::GetIndexOfBrowserStateWithPath( ...@@ -106,13 +100,6 @@ size_t BrowserStateInfoCache::GetIndexOfBrowserStateWithPath(
return std::string::npos; 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( base::string16 BrowserStateInfoCache::GetUserNameOfBrowserStateAtIndex(
size_t index) const { size_t index) const {
base::string16 user_name; base::string16 user_name;
...@@ -214,22 +201,7 @@ std::string BrowserStateInfoCache::CacheKeyFromBrowserStatePath( ...@@ -214,22 +201,7 @@ std::string BrowserStateInfoCache::CacheKeyFromBrowserStatePath(
return base_name.MaybeAsASCII(); return base_name.MaybeAsASCII();
} }
std::vector<std::string>::iterator void BrowserStateInfoCache::AddBrowserStateCacheKey(const std::string& key) {
BrowserStateInfoCache::FindPositionForBrowserState( sorted_keys_.insert(
const std::string& search_key, std::upper_bound(sorted_keys_.begin(), sorted_keys_.end(), key), 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();
} }
...@@ -30,7 +30,6 @@ class BrowserStateInfoCache { ...@@ -30,7 +30,6 @@ class BrowserStateInfoCache {
virtual ~BrowserStateInfoCache(); virtual ~BrowserStateInfoCache();
void AddBrowserState(const base::FilePath& browser_state_path, void AddBrowserState(const base::FilePath& browser_state_path,
const base::string16& name,
const std::string& gaia_id, const std::string& gaia_id,
const base::string16& user_name); const base::string16& user_name);
void RemoveBrowserState(const base::FilePath& browser_state_path); void RemoveBrowserState(const base::FilePath& browser_state_path);
...@@ -45,7 +44,6 @@ class BrowserStateInfoCache { ...@@ -45,7 +44,6 @@ class BrowserStateInfoCache {
// Gets and sets information related to browser states. // Gets and sets information related to browser states.
size_t GetIndexOfBrowserStateWithPath( size_t GetIndexOfBrowserStateWithPath(
const base::FilePath& browser_state_path) const; const base::FilePath& browser_state_path) const;
base::string16 GetNameOfBrowserStateAtIndex(size_t index) const;
base::string16 GetUserNameOfBrowserStateAtIndex(size_t index) const; base::string16 GetUserNameOfBrowserStateAtIndex(size_t index) const;
base::FilePath GetPathOfBrowserStateAtIndex(size_t index) const; base::FilePath GetPathOfBrowserStateAtIndex(size_t index) const;
std::string GetGAIAIdOfBrowserStateAtIndex(size_t index) const; std::string GetGAIAIdOfBrowserStateAtIndex(size_t index) const;
...@@ -69,9 +67,7 @@ class BrowserStateInfoCache { ...@@ -69,9 +67,7 @@ class BrowserStateInfoCache {
std::string CacheKeyFromBrowserStatePath( std::string CacheKeyFromBrowserStatePath(
const base::FilePath& browser_state_path) const; const base::FilePath& browser_state_path) const;
std::vector<std::string>::iterator FindPositionForBrowserState( void AddBrowserStateCacheKey(const std::string& key);
const std::string& search_key,
const base::string16& search_name);
PrefService* prefs_; PrefService* prefs_;
std::vector<std::string> sorted_keys_; std::vector<std::string> sorted_keys_;
......
...@@ -22,8 +22,7 @@ class BrowserStateInfoCacheObserver { ...@@ -22,8 +22,7 @@ class BrowserStateInfoCacheObserver {
virtual void OnBrowserStateAdded(const base::FilePath& path) = 0; virtual void OnBrowserStateAdded(const base::FilePath& path) = 0;
// Called when a BrowserState has been removed. // Called when a BrowserState has been removed.
virtual void OnBrowserStateWasRemoved(const base::FilePath& path, virtual void OnBrowserStateWasRemoved(const base::FilePath& path) = 0;
const base::string16& name) = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(BrowserStateInfoCacheObserver); DISALLOW_COPY_AND_ASSIGN(BrowserStateInfoCacheObserver);
......
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