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

Issue 2788483005: Use GUID to generate unique temp file names and retire GetTempFileName (Closed)

Created:
3 years, 8 months ago by chengx
Modified:
3 years, 8 months ago
Reviewers:
gab, grt (UTC plus 2)
CC:
chromium-reviews, danakj+watch_chromium.org, vmpstr+watch_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Use GUID to generate unique temp file names and retire GetTempFileName We use GetTempFileName Windows API to generate an unique temp file name in some scenarios like downloading files. It is mentioned on MSDN for this API that "Due to the algorithm used to generate file names, GetTempFileName Windows API can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on GUIDs." The reasons why it's doing poorly include it takes a long time to find an unique name when a lot of names are already in use. This has been proved by the fact we found this API call takes minutes for some users who have lots of temp files in their default download directory. Note that the temp files in the default download directory can be generated by any software other than Chrome. This CL retires GetTempFileName and uses GUID to generate unique temp file names. With GUID, it is almost guaranteed that an unique temp file name can be generated with a single attempt. BUG=103737 Review-Url: https://codereview.chromium.org/2788483005 Cr-Commit-Position: refs/heads/master@{#462662} Committed: https://chromium.googlesource.com/chromium/src/+/170f1cf7d23ce3e3fb99085042bf68b8772825a1

Patch Set 1 #

Total comments: 12

Patch Set 2 : Address comments. #

Total comments: 8

Patch Set 3 : Address early comments from grt@ #

Total comments: 4

Patch Set 4 : Using GUID to generate new temp file names. #

Total comments: 11

Patch Set 5 : Address comments. #

Patch Set 6 : Revert some variable names. #

Total comments: 4

Patch Set 7 : Add comments to the code, fix nits. #

Total comments: 12

Patch Set 8 : Address comments from gab@ #

Total comments: 2

Patch Set 9 : Add a loop to make sure an unique name is generated. #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+29 lines, -5 lines) Patch
M base/files/file_util_win.cc View 1 2 3 4 5 6 7 8 2 chunks +29 lines, -5 lines 2 comments Download

Messages

Total messages: 99 (72 generated)
chengx
PTAL~
3 years, 8 months ago (2017-04-01 00:54:12 UTC) #14
gab
Meta-comment: it's kind of weird to seed a random-filename-generator with a random prefix and expect ...
3 years, 8 months ago (2017-04-03 16:40:50 UTC) #23
chengx
On 2017/04/03 16:40:50, gab wrote: > Meta-comment: > > it's kind of weird to seed ...
3 years, 8 months ago (2017-04-03 18:35:11 UTC) #26
grt (UTC plus 2)
a few early comments. i haven't thought about the overall strategy yet. https://codereview.chromium.org/2788483005/diff/60001/base/files/file_util_win.cc File base/files/file_util_win.cc ...
3 years, 8 months ago (2017-04-03 21:11:16 UTC) #29
chengx
On 2017/04/03 21:11:16, grt (UTC plus 2) wrote: > a few early comments. i haven't ...
3 years, 8 months ago (2017-04-04 01:25:54 UTC) #32
grt (UTC plus 2)
I think I'm about to repeat Gab: why generate three random chars and then ask ...
3 years, 8 months ago (2017-04-04 12:00:43 UTC) #35
chengx
On 2017/04/04 12:00:43, grt (UTC plus 2) wrote: > I think I'm about to repeat ...
3 years, 8 months ago (2017-04-05 05:39:51 UTC) #55
grt (UTC plus 2)
On 2017/04/05 05:39:51, chengx wrote: > On 2017/04/04 12:00:43, grt (UTC plus 2) wrote: > ...
3 years, 8 months ago (2017-04-05 11:26:21 UTC) #56
grt (UTC plus 2)
https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc#newcode344 base/files/file_util_win.cc:344: FilePath::StringType temp_name = UTF8ToUTF16(base::GenerateGUID() + ".tmp"); ASCIIToUTF16 since you ...
3 years, 8 months ago (2017-04-05 11:26:34 UTC) #57
chengx
On 2017/04/05 11:26:21, grt (UTC plus 2) wrote: > On 2017/04/05 05:39:51, chengx wrote: > ...
3 years, 8 months ago (2017-04-05 18:12:37 UTC) #60
chengx
PTAL~ https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc#newcode344 base/files/file_util_win.cc:344: FilePath::StringType temp_name = UTF8ToUTF16(base::GenerateGUID() + ".tmp"); On 2017/04/05 ...
3 years, 8 months ago (2017-04-05 18:22:34 UTC) #61
brucedawson
> We could make some guesses about the cost of the middle step there Is ...
3 years, 8 months ago (2017-04-05 21:34:25 UTC) #64
chengx
On 2017/04/05 21:34:25, brucedawson wrote: > > We could make some guesses about the cost ...
3 years, 8 months ago (2017-04-06 00:42:59 UTC) #65
grt (UTC plus 2)
https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc#newcode359 base/files/file_util_win.cc:359: GetLongPathName(temp_path_name.value().c_str(), full_path_name, MAX_PATH); On 2017/04/05 18:22:34, chengx wrote: > ...
3 years, 8 months ago (2017-04-06 10:35:02 UTC) #70
chengx
On 2017/04/06 10:35:02, grt (no reviews Apr 7-17) wrote: > https://codereview.chromium.org/2788483005/diff/160001/base/files/file_util_win.cc > File base/files/file_util_win.cc (right): ...
3 years, 8 months ago (2017-04-06 17:46:01 UTC) #73
gab
> I think I'm about to repeat Gab: why generate three random chars and then ...
3 years, 8 months ago (2017-04-06 19:03:40 UTC) #76
gab
lgtm w/ nits, thanks! https://codereview.chromium.org/2788483005/diff/220001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/220001/base/files/file_util_win.cc#newcode344 base/files/file_util_win.cc:344: // Use GUID instead of ...
3 years, 8 months ago (2017-04-06 19:09:37 UTC) #77
chengx
On 2017/04/06 19:03:40, gab (behind) wrote: > > I think I'm about to repeat Gab: ...
3 years, 8 months ago (2017-04-06 19:54:53 UTC) #80
gab
https://codereview.chromium.org/2788483005/diff/240001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/240001/base/files/file_util_win.cc#newcode350 base/files/file_util_win.cc:350: FilePath temp_name = dir.Append(ASCIIToUTF16(base::GenerateGUID()) + L".tmp"); Actually, we should ...
3 years, 8 months ago (2017-04-06 20:19:12 UTC) #81
chengx
On 2017/04/06 20:19:12, gab (behind) wrote: > https://codereview.chromium.org/2788483005/diff/240001/base/files/file_util_win.cc > File base/files/file_util_win.cc (right): > > https://codereview.chromium.org/2788483005/diff/240001/base/files/file_util_win.cc#newcode350 ...
3 years, 8 months ago (2017-04-06 20:27:49 UTC) #82
gab
On 2017/04/06 20:27:49, chengx wrote: > On 2017/04/06 20:19:12, gab (behind) wrote: > > > ...
3 years, 8 months ago (2017-04-06 20:35:58 UTC) #83
chengx
On 2017/04/06 20:35:58, gab (behind) wrote: > On 2017/04/06 20:27:49, chengx wrote: > > On ...
3 years, 8 months ago (2017-04-06 20:59:16 UTC) #88
chengx
Hi gab@, all comments addressed. Thanks! https://codereview.chromium.org/2788483005/diff/220001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/220001/base/files/file_util_win.cc#newcode344 base/files/file_util_win.cc:344: // Use GUID ...
3 years, 8 months ago (2017-04-06 21:00:31 UTC) #89
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2788483005/260001
3 years, 8 months ago (2017-04-06 22:17:53 UTC) #94
commit-bot: I haz the power
Committed patchset #9 (id:260001) as https://chromium.googlesource.com/chromium/src/+/170f1cf7d23ce3e3fb99085042bf68b8772825a1
3 years, 8 months ago (2017-04-06 22:48:00 UTC) #97
gab
Thanks, post-commit nit https://codereview.chromium.org/2788483005/diff/260001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2788483005/diff/260001/base/files/file_util_win.cc#newcode367 base/files/file_util_win.cc:367: // Exist early if we can't ...
3 years, 8 months ago (2017-04-07 17:27:15 UTC) #98
chengx
3 years, 8 months ago (2017-04-07 18:13:04 UTC) #99
Message was sent while issue was closed.
https://codereview.chromium.org/2788483005/diff/260001/base/files/file_util_w...
File base/files/file_util_win.cc (right):

https://codereview.chromium.org/2788483005/diff/260001/base/files/file_util_w...
base/files/file_util_win.cc:367: // Exist early if we can't create an unique
name.
On 2017/04/07 17:27:15, gab wrote:
> Remove this comment, it merely states what the self-documenting code below
does.

Sure, will remove it in another CL.

Powered by Google App Engine
This is Rietveld 408576698