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

Unified Diff: chrome/browser/ui/views/select_file_dialog_win.cc

Issue 9484003: Cleanup: Deprecate wstring version of file_util::CopyDirectory(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 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
« base/file_util.cc ('K') | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/select_file_dialog_win.cc
===================================================================
--- chrome/browser/ui/views/select_file_dialog_win.cc (revision 124466)
+++ chrome/browser/ui/views/select_file_dialog_win.cc (working copy)
@@ -29,6 +29,19 @@
using content::BrowserThread;
+namespace {
+
+// Given |extension|, if it's not empty, then remove the leading dot.
+std::wstring GetExtensionWithoutLeadingDot(const std::wstring& extension) {
+ size_t len = extension.length();
Peter Kasting 2012/03/02 18:11:58 Nit: Simpler: DCHECK(extension.empty() || exten
Lei Zhang 2012/03/02 22:54:32 Done.
+ if (!len)
+ return extension;
+ DCHECK_EQ(L'.', extension[0]);
+ return extension.substr(1, len - 1);
+}
+
+} // namespace
+
// This function takes the output of a SaveAs dialog: a filename, a filter and
// the extension originally suggested to the user (shown in the dialog box) and
// returns back the filename with the appropriate extension tacked on. If the
@@ -50,8 +63,10 @@
// Careful: Checking net::GetMimeTypeFromExtension() will only find
// extensions with a known MIME type, which many "known" extensions on Windows
// don't have. So we check directly for the "known extension" registry key.
- std::wstring file_extension(file_util::GetFileExtensionFromPath(filename));
- std::wstring key(L"." + file_extension);
+ std::wstring key(FilePath(filename).Extension());
+ if (key.empty())
Peter Kasting 2012/03/02 18:11:58 Nit: This can be omitted, GetExtensionWithoutLeadi
Lei Zhang 2012/03/02 22:54:32 Done.
+ key = L".";
+ std::wstring file_extension(GetExtensionWithoutLeadingDot(key));
if (!(filter_selected.empty() || filter_selected == L"*.*") &&
!base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() &&
file_extension != suggested_ext) {
@@ -244,7 +259,8 @@
// Having an empty filter makes for a bad user experience. We should always
// specify a filter when saving.
DCHECK(!filter.empty());
- std::wstring file_part = FilePath(suggested_name).BaseName().value();
+ const FilePath suggested_path(suggested_name);
+ std::wstring file_part = suggested_path.BaseName().value();
// If the suggested_name is a root directory, file_part will be '\', and the
// call to GetSaveFileName below will fail.
if (file_part.size() == 1 && file_part[0] == L'\\')
@@ -281,7 +297,7 @@
// Set up the initial directory for the dialog.
std::wstring directory;
if (!suggested_name.empty())
- directory = FilePath(suggested_name).DirName().value();
+ directory = suggested_path.DirName().value();
save_as.lpstrInitialDir = directory.c_str();
save_as.lpstrTitle = NULL;
@@ -332,7 +348,7 @@
// 'extension characters' in the title of the web page.
std::wstring suggested_ext;
if (!ignore_suggested_ext)
- suggested_ext = file_util::GetFileExtensionFromPath(suggested_name);
+ suggested_ext = GetExtensionWithoutLeadingDot(suggested_path.Extension());
// If we can't get the extension from the suggested_name, we use the default
// extension passed in. This is to cover cases like when saving a web page,
« base/file_util.cc ('K') | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698