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

Issue 1582353006: CountryNames: Separate data creation from usage (Closed)

Created:
4 years, 11 months ago by vabr (Chromium)
Modified:
4 years, 11 months ago
Reviewers:
Ilya Sherman, pavely
CC:
chromium-reviews, tim+watch_chromium.org, zea+watch_chromium.org, rouslan+autofill_chromium.org, maxbogue+watch_chromium.org, browser-components-watch_chromium.org, jdonnelly+autofillwatch_chromium.org, bondd+autofillwatch_chromium.org, plaree+watch_chromium.org, vabr+watchlistautofill_chromium.org, estade+watch_chromium.org, sdefresne+watch_chromium.org, Mathieu
Base URL:
https://chromium.googlesource.com/chromium/src.git@571610_exposeCountryNamesToTesting
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

CountryNames: Separate data creation from usage ==Goal== Fix a race condition in CountryNames-related code without complicating it significantly. ==Non-goal== Any deeper refactoring not necessary to fix the above race condition. A discussion is needed to see whether once could avoid the Singleton business and use some more common ways to store the country names data (a database?), as well as whether it is necessary to compute it in run-time. But that is explicitly out of scope of this CL. ==Content== This CL makes CountryNames create its data (mappings from country names to country codes and the appropriate collators for hashing the country names) on construction, rather than on demand. The main purpose of this change is to eliminate race conditions. Before this CL, multiple threads could have trigger the data creation, and it is believed to have caused data corruption and crashes. Because the CountryNames creation is guaranteed by Singleton to only happen once, it solves the threading issues. However, there are caveats: (Caveat A) CountryNames cannot get constructor arguments, being created through Singleton's get(). But it needs to know which locale Chrome is using. To circumvent this, it gets the information from a global static string, and relies on the callsites of CountryNames to ensure initialisation of this string. To make that happen, every instance of AutofillManager ensures on its construction, that said string is initialised. This is a bit clumsy (there is an AutofillManager for each tab, but this pointer only needs to be initialised once per Chrome's execution), but works -- CountryNames are never used earlier than the first AutofillManager is constructed. Also, while initialising the string is not guarded by any mutex, it is safe -- AutofillManager gets constructed on the UI thread, so there are not more concurrent constructions. And once the string is set, it is never set again, so a constructed CountryNames can read it safely on any thread. (Caveat B) Before this CL, the code was capable of generating more data for a newly added locale on the fly. After this CL, it will only work for the locale of the program during the CountryNames creation (and en_US as a fallback). Note that Chrome does not seem to be able to change the language without restart, so this should be no concern. The only unknown for me is CrOS -- I'm not sure whether a new CountryNames instance is created for each user session. But my suggestion is to wait with making the code more flexible until the more systematic fix to the way it generates and stores the CountryNames data. Finally, this CL adds a way to construct CountryNames with an explicit locale in tests, and uses it in the appropriate unit tests. BUG=571610 Committed: https://crrev.com/f39cbace358fe626f0f07e32f4e66b78ca589038 Cr-Commit-Position: refs/heads/master@{#371226}

Patch Set 1 #

Patch Set 2 : Fix comments #

Patch Set 3 : Fix branch dependency #

Patch Set 4 : Add implementation in AwAutofillClient to fix Android compilation #

Patch Set 5 : Just rebased #

Patch Set 6 : Fix Android #

Patch Set 7 : Fix a glitch in rebase #

Patch Set 8 : More Android fixes #

Total comments: 29

Patch Set 9 : Just rebased #

Patch Set 10 : Comments addressed #

Patch Set 11 : Fix tests #

Patch Set 12 : One more comment addressed + checking equality of locales, not locale strings in SetLocaleString #

Patch Set 13 : Also set locale in the test constructor #

Patch Set 14 : Format #

Patch Set 15 : Revert the addition to AutofillClient #

Patch Set 16 : Yet more tests fixed #

Patch Set 17 : Fix compile #

Patch Set 18 : One more test fixed #

Patch Set 19 : Set CountryNames locale also from PersonalDataManager #

Total comments: 4

Patch Set 20 : No const + no double init #

Patch Set 21 : Remove #include added by accident #

Patch Set 22 : Just rebased #

Unified diffs Side-by-side diffs Delta from patch set Stats (+282 lines, -207 lines) Patch
M chrome/browser/autofill/android/personal_data_manager_android.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 chunk +1 line, -2 lines 0 comments Download
M chrome/browser/sync/profile_sync_service_autofill_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 4 chunks +6 lines, -3 lines 0 comments Download
M chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc View 1 2 3 4 6 chunks +11 lines, -12 lines 0 comments Download
M chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 chunks +4 lines, -1 line 0 comments Download
M components/autofill/core/browser/address.cc View 1 2 3 4 2 chunks +2 lines, -4 lines 0 comments Download
M components/autofill/core/browser/address_unittest.cc View 1 2 3 4 5 6 7 8 9 10 10 chunks +16 lines, -10 lines 0 comments Download
M components/autofill/core/browser/autofill_field.cc View 1 2 3 4 3 chunks +4 lines, -8 lines 0 comments Download
M components/autofill/core/browser/autofill_field_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 30 chunks +35 lines, -29 lines 0 comments Download
M components/autofill/core/browser/autofill_manager.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 3 chunks +3 lines, -0 lines 0 comments Download
M components/autofill/core/browser/autofill_merge_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 2 chunks +2 lines, -0 lines 0 comments Download
M components/autofill/core/browser/country_names.h View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +40 lines, -23 lines 0 comments Download
M components/autofill/core/browser/country_names.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 6 chunks +96 lines, -67 lines 0 comments Download
M components/autofill/core/browser/country_names_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +48 lines, -38 lines 0 comments Download
M components/autofill/core/browser/personal_data_manager.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 chunks +3 lines, -0 lines 0 comments Download
M components/autofill/core/browser/webdata/autofill_profile_syncable_service.h View 1 chunk +1 line, -2 lines 0 comments Download
M components/autofill/core/browser/webdata/autofill_profile_syncable_service.cc View 1 2 3 4 4 chunks +6 lines, -7 lines 0 comments Download
M components/autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2 chunks +4 lines, -1 line 0 comments Download

Messages

Total messages: 26 (10 generated)
vabr (Chromium)
Hello reviewers! boliu@ -- please review android_webview/native/aw_autofill_client.* pavely@ -- please review chrome/browser/sync/profile_sync_service_autofill_unittest.cc jdonnelly@ -- please ...
4 years, 11 months ago (2016-01-15 19:43:27 UTC) #3
vabr (Chromium)
Small correction: On 2016/01/15 19:43:27, vabr (Chromium) wrote: > jdonnelly@ -- please review ios/chrome/browser/ui/autofill/autofill_client_ios.h Actually ...
4 years, 11 months ago (2016-01-15 19:48:05 UTC) #4
pavely
chrome/browser/sync/profile_sync_service_autofill_unittest.cc: lgtm
4 years, 11 months ago (2016-01-15 23:13:39 UTC) #5
boliu
There are android compile errors. Also kinda waiting for actual reviewer to approve before stamping.
4 years, 11 months ago (2016-01-19 19:44:48 UTC) #6
Ilya Sherman
Did you consider ensuring that the method is only called from a single thread or ...
4 years, 11 months ago (2016-01-20 01:31:54 UTC) #7
vabr (Chromium)
@boliu: the Android failures are now fixed. @isherman: On 2016/01/20 01:31:54, Ilya Sherman wrote: > ...
4 years, 11 months ago (2016-01-20 16:43:11 UTC) #8
Ilya Sherman
Okay, I think I see your point about the timing not really changing. In that ...
4 years, 11 months ago (2016-01-21 02:07:57 UTC) #9
vabr (Chromium)
Status update: Still fixing failing tests, but after pruning the change, there are no longer ...
4 years, 11 months ago (2016-01-22 15:50:29 UTC) #11
vabr (Chromium)
Thanks for your review comments, Ilya. I addressed some of them, and pushed back on ...
4 years, 11 months ago (2016-01-22 17:36:42 UTC) #13
Ilya Sherman
LGTM % a couple more nits: https://codereview.chromium.org/1582353006/diff/140001/components/autofill/core/browser/country_names.h File components/autofill/core/browser/country_names.h (right): https://codereview.chromium.org/1582353006/diff/140001/components/autofill/core/browser/country_names.h#newcode28 components/autofill/core/browser/country_names.h:28: void SetLocaleString(std::string locale); ...
4 years, 11 months ago (2016-01-23 01:41:04 UTC) #14
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1582353006/380001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1582353006/380001
4 years, 11 months ago (2016-01-25 10:30:51 UTC) #16
vabr (Chromium)
Thanks, Ilya! I will send this to the CQ, and e-mail chromium-dev as discussed below ...
4 years, 11 months ago (2016-01-25 10:36:44 UTC) #18
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1582353006/420001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1582353006/420001
4 years, 11 months ago (2016-01-25 10:38:01 UTC) #21
commit-bot: I haz the power
Committed patchset #22 (id:420001)
4 years, 11 months ago (2016-01-25 11:34:15 UTC) #23
commit-bot: I haz the power
Patchset 22 (id:??) landed as https://crrev.com/f39cbace358fe626f0f07e32f4e66b78ca589038 Cr-Commit-Position: refs/heads/master@{#371226}
4 years, 11 months ago (2016-01-25 11:35:13 UTC) #25
vabr (Chromium)
4 years, 11 months ago (2016-01-26 09:13:11 UTC) #26
Message was sent while issue was closed.
https://codereview.chromium.org/1582353006/diff/140001/components/autofill/co...
File components/autofill/core/browser/country_names.h (right):

https://codereview.chromium.org/1582353006/diff/140001/components/autofill/co...
components/autofill/core/browser/country_names.h:28: void
SetLocaleString(std::string locale);
On 2016/01/25 10:36:44, vabr (Chromium) wrote:
> On 2016/01/23 01:41:04, Ilya Sherman wrote:
> > On 2016/01/22 17:36:42, vabr (Chromium) wrote:
> > > On 2016/01/21 02:07:57, Ilya Sherman wrote:
> > > > nit: Pass by reference.
> > > 
> > > This is by value on purpose. Looking in the SetLocaleString definition,
you
> > will
> > > see that |locale| is moved. So if the argument to this method is a
> temporary,
> > > there will be no copy. If it is not a temporary (including when it is a
> > > refererence), the copy will happen on calling, but that's the same as if
it
> > > happened by assigining a const ref in the function body.
> > > 
> > > So in summary, this is in some cases as expensive, and in other cheaper
than
> > > using a const ref.
> > > 
> > > (This technique was one of the main takeaways of the C++11 course for me.)
> > 
> > Boy, this seems like a super duper micro-optimization.  I'd recommend
emailing
> > chromium-dev@ to ask whether this style is preferred -- it certainly
surprised
> > me to see std::move() being used to move strings of ~5 characters in length.

> > But maybe I'm just behind the times =)
> 
> E-mailing chromium-dev seems like a good idea, I'll do that. I will still
> proceed with landing the current code, because the crasher needs fixing, and
> this is just a nit. If there is a conclusive feedback against pass by value +
> move, I am happy to make a follow-up CL.
> 
> Back to the issue itself -- IMO this is not an optimization, it is a safe
> default practice. It was not done before because there was no moving in C++,
not
> because it has any disadvantages. The point is that one can write this and not
> think about how long the strings actually are.

Follow-up filed in https://codereview.chromium.org/1635813003/.

Powered by Google App Engine
This is Rietveld 408576698