summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authordroger <droger@chromium.org>2015-10-30 06:24:40 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-30 13:25:17 +0000
commitaa1ab978559ed5b637d97955637e7f3b68109804 (patch)
tree29f93b9ff332530b8a0a97b0892f302a489bc93d /ios
parent186d6bfe41254d6e453a82bed9c8714b70b2af67 (diff)
downloadchromium_src-aa1ab978559ed5b637d97955637e7f3b68109804.zip
chromium_src-aa1ab978559ed5b637d97955637e7f3b68109804.tar.gz
chromium_src-aa1ab978559ed5b637d97955637e7f3b68109804.tar.bz2
[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}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/browser_state/browser_state_info_cache.cc44
-rw-r--r--ios/chrome/browser/browser_state/browser_state_info_cache.h6
-rw-r--r--ios/chrome/browser/browser_state/browser_state_info_cache_observer.h3
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);