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

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

Issue 11826011: [Autofill] Loosen thread-safety DCHECK in AutofillCountry so that tests will pass when run in isola… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | « no previous file | no next file » | 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 7f9f342f63f5ad8ddbaee092f2099bddcf4bbf0f..26474934d85508aac5fb11d312302ab49d39cc83 100644
--- a/chrome/browser/autofill/autofill_country.cc
+++ b/chrome/browser/autofill/autofill_country.cc
@@ -14,6 +14,7 @@
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/string_util.h"
+#include "base/threading/thread_checker.h"
#include "base/utf_string_conversions.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@@ -635,7 +636,6 @@ class CountryNames {
scoped_array<uint8_t>* buffer,
int32_t* buffer_size) const;
-
// Maps from common country names, including 2- and 3-letter country codes,
// to the corresponding 2-letter country codes. The keys are uppercase ASCII
// strings.
@@ -651,6 +651,9 @@ class CountryNames {
// Maps ICU locale names to their corresponding collators.
std::map<std::string, icu::Collator*> collators_;
+ // Verifies thread-safety of accesses to the application locale.
+ base::ThreadChecker thread_checker_;
+
// Caches the application locale, for thread-safe access.
std::string application_locale_;
@@ -664,7 +667,13 @@ CountryNames* CountryNames::GetInstance() {
const std::string CountryNames::ApplicationLocale() {
if (application_locale_.empty()) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // In production code, this class is always constructed on the UI thread, so
+ // the two conditions in the below DCHECK are identical. In test code,
+ // sometimes there is a UI thread, and sometimes there is just the unnamed
+ // main thread. Since this class is a singleton, it needs to support both
+ // cases. Hence, the somewhat strange looking DCHECK below.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
+ thread_checker_.CalledOnValidThread());
application_locale_ =
content::GetContentClient()->browser()->GetApplicationLocale();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698