diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 23:06:12 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 23:06:12 +0000 |
commit | de29433580baeecc204edc9ca0c2aa47c51aa93a (patch) | |
tree | ec55f655f63f7e09fb373c1e7d784c2e721c6119 /chrome/browser/download/save_package.cc | |
parent | 2c1639589b5932b565c9d420cb79b56a4212a706 (diff) | |
download | chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.zip chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.gz chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.bz2 |
Do some cleanup of file path name handling.
This started trying to cleanup DownloadManager::GenerateFilename which asserts
if your system locale isn't UTF-8 (I ran into this when mine got messed up).
The solution is to have GetSuggestedFilename return a FilePath rather than
calling FromWStringHack.
The rest of the patch is a result of trying to write GetSuggestedFilename in a
reasonable way. I changed ReplaceIllegalCharacters to work on a
FilePath::StringType.
Some places in the code calling these functions got cleaner, some got messier.
I think overall the ones that got messier are the ones doing sketchy things
with paths and the ones that got cleaner are the ones doing things more
properly.
The only code here that gets called a nontrivial number of times is the
weburlloader, and I think the new code does about the same number of string
conversions overall (though on certain platforms the number will be higher or
lower).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/271056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/save_package.cc')
-rw-r--r-- | chrome/browser/download/save_package.cc | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index ac4a39e..97487c0 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -65,7 +65,7 @@ namespace { // Default name which will be used when we can not get proper name from // resource URL. -const wchar_t kDefaultSaveName[] = L"saved_resource"; +const char kDefaultSaveName[] = "saved_resource"; const FilePath::CharType kDefaultHtmlExtension[] = #if defined(OS_WIN) @@ -336,8 +336,8 @@ bool SavePackage::GenerateFilename(const std::string& disposition, FilePath::StringType* generated_name) { // TODO(jungshik): Figure out the referrer charset when having one // makes sense and pass it to GetSuggestedFilename. - FilePath file_path = FilePath::FromWStringHack( - net::GetSuggestedFilename(url, disposition, "", kDefaultSaveName)); + FilePath file_path = net::GetSuggestedFilename(url, disposition, "", + kDefaultSaveName); DCHECK(!file_path.empty()); FilePath::StringType pure_file_name = @@ -1033,13 +1033,9 @@ FilePath SavePackage::GetSuggestedNameForSaveAs(const FilePath& name, if (can_save_as_complete) name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext); - std::wstring file_name = name_with_proper_ext.ToWStringHack(); - // TODO(port): we need a version of ReplaceIllegalCharacters() that takes - // FilePaths. - file_util::ReplaceIllegalCharacters(&file_name, L' '); - TrimWhitespace(file_name, TRIM_ALL, &file_name); - - return FilePath::FromWStringHack(file_name); + FilePath::StringType file_name = name_with_proper_ext.value(); + file_util::ReplaceIllegalCharactersInPath(&file_name, ' '); + return FilePath(file_name); } FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) { |