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

Unified Diff: chrome/browser/autofill/autofill_country.cc

Issue 8355025: Fix an Autofill crash caused by accessing the g_browser_process on the DB thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix more tests? Created 9 years, 2 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
« no previous file with comments | « chrome/browser/autofill/autofill_country.h ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/autofill_country.cc
diff --git a/chrome/browser/autofill/autofill_country.cc b/chrome/browser/autofill/autofill_country.cc
index a6860a03d6f4c923fdd1e2256ac54044b7c85356..951e8bfc0590db8f4823bf678d27f5d785e7309b 100644
--- a/chrome/browser/autofill/autofill_country.cc
+++ b/chrome/browser/autofill/autofill_country.cc
@@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "content/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "unicode/coll.h"
@@ -355,6 +356,9 @@ class CountryNames {
public:
static CountryNames* GetInstance();
+ // Returns the application locale.
+ const std::string ApplicationLocale();
+
// Returns the country code corresponding to |country|, which should be a
// country code or country name localized to |locale|.
const std::string GetCountryCode(const string16& country,
@@ -404,6 +408,9 @@ class CountryNames {
// Maps ICU locale names to their corresponding collators.
std::map<std::string, icu::Collator*> collators_;
+ // Caches the application locale, for thread-safe access.
+ std::string application_locale_;
+
DISALLOW_COPY_AND_ASSIGN(CountryNames);
};
@@ -412,6 +419,15 @@ CountryNames* CountryNames::GetInstance() {
return Singleton<CountryNames>::get();
}
+const std::string CountryNames::ApplicationLocale() {
+ if (application_locale_.empty()) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ application_locale_ = g_browser_process->GetApplicationLocale();
+ }
+
+ return application_locale_;
+}
+
CountryNames::CountryNames() {
// Add 2- and 3-letter ISO country codes.
for (CountryDataMap::Iterator it = CountryDataMap::Begin();
@@ -628,7 +644,7 @@ const std::string AutofillCountry::GetCountryCode(const string16& country,
// static
const std::string AutofillCountry::ApplicationLocale() {
- return g_browser_process->GetApplicationLocale();
+ return CountryNames::GetInstance()->ApplicationLocale();
}
AutofillCountry::AutofillCountry(const std::string& country_code,
« no previous file with comments | « chrome/browser/autofill/autofill_country.h ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698