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

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

Issue 144783002: Simplify directory initialization in Files app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 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
Index: chrome/browser/ui/views/select_file_dialog_extension.cc
diff --git a/chrome/browser/ui/views/select_file_dialog_extension.cc b/chrome/browser/ui/views/select_file_dialog_extension.cc
index 1a57202038aeee6fd227bc61479c8a378e03ed92..990fc5e1506a116050e41a213a23522069df6067 100644
--- a/chrome/browser/ui/views/select_file_dialog_extension.cc
+++ b/chrome/browser/ui/views/select_file_dialog_extension.cc
@@ -330,43 +330,79 @@ void SelectFileDialogExtension::SelectFileImpl(
return;
}
- base::FilePath default_dialog_path;
-
const PrefService* pref_service = profile_->GetPrefs();
-
- if (default_path.empty() && pref_service) {
- default_dialog_path =
- pref_service->GetFilePath(prefs::kDownloadDefaultDirectory);
- } else {
- default_dialog_path = default_path;
+ if (!pref_service) {
+ LOG(ERROR) << "Could not find the pref service.";
Peter Kasting 2014/01/24 19:17:25 In general, don't use logging statements. They bl
mtomasz 2014/01/27 02:38:44 Done.
+ return;
}
- base::FilePath virtual_path;
- base::FilePath fallback_path = profile_->last_selected_directory().Append(
- default_dialog_path.BaseName());
- // If an absolute path is specified as the default path, convert it to the
- // virtual path in the file browser extension. Due to the current design,
- // an invalid temporal cache file path may passed as |default_dialog_path|
- // (crbug.com/178013 #9-#11). In such a case, we use the last selected
- // directory as a workaround. Real fix is tracked at crbug.com/110119.
+ // All of the paths below are absolute.
+ base::FilePath download_default_path(
+ pref_service->GetFilePath(prefs::kDownloadDefaultDirectory));
+
+ base::FilePath selection_path = default_path.IsAbsolute() ?
+ default_path : download_default_path.Append(default_path.BaseName());
+ base::FilePath current_directory_path = selection_path.DirName();
+
+ base::FilePath current_directory_virtual_path;
+ base::FilePath selection_virtual_path;
Peter Kasting 2014/01/24 19:17:25 Nit: Declare these as close to their initializatio
mtomasz 2014/01/27 02:38:44 Done.
+
+ base::FilePath fallback_path = !profile_->last_selected_directory().empty() ?
Peter Kasting 2014/01/24 19:17:25 Nit: Remove "!" and reverse arms
mtomasz 2014/01/27 02:38:44 Done, but is it better? I usually do this: conditi
Peter Kasting 2014/01/28 03:22:04 I find it easier to read conditionals when they're
+ profile_->last_selected_directory() : download_default_path;
+
+ // Convert the above absolute paths to virtual paths.
+ // TODO(mtomasz): Use URLs instead of paths.
using file_manager::kFileManagerAppId;
Peter Kasting 2014/01/24 19:17:25 Nit: This using statement doesn't buy us much; all
mtomasz 2014/01/27 02:38:44 Done.
- if (default_dialog_path.IsAbsolute() &&
- (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
- profile_, kFileManagerAppId, default_dialog_path, &virtual_path) ||
- file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
- profile_, kFileManagerAppId, fallback_path, &virtual_path))) {
- virtual_path = base::FilePath("/").Append(virtual_path);
- } else {
- // If the path was relative, or failed to convert, just use the base name,
- virtual_path = default_dialog_path.BaseName();
+ if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
+ profile_,
Peter Kasting 2014/01/24 19:17:25 Nit: Indent 4, not 8 You're welcome to put more t
mtomasz 2014/01/27 02:38:44 Over and over again I receive contrasting comments
Peter Kasting 2014/01/28 03:22:04 The Google style guide is ambiguous. My memory of
+ kFileManagerAppId,
+ selection_path,
+ &selection_virtual_path)) {
+ // Due to the current design, an invalid temporal cache file path may passed
+ // as |default_path| (crbug.com/178013 #9-#11). In such a case, we use the
+ // last selected directory as a workaround. Real fix is tracked at
+ // crbug.com/110119.
Peter Kasting 2014/01/24 19:17:25 Nit: Normally I discourage bug references in comme
mtomasz 2014/01/27 02:38:44 I'm not sure if I understand. I think the context
Peter Kasting 2014/01/28 03:22:04 I mostly meant, if "an invalid temporal cache file
+ if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
+ profile_,
+ kFileManagerAppId,
+ fallback_path.Append(selection_path.BaseName()),
+ &selection_virtual_path)) {
+ LOG(ERROR) << "Unable to resolve the selection path.";
+ return;
+ }
+ }
+ selection_virtual_path = base::FilePath("/").Append(selection_virtual_path);
Peter Kasting 2014/01/24 19:17:25 I don't work with FilePaths enough to know the ans
mtomasz 2014/01/27 02:38:44 This works, because select_file_dialog_extension.c
+
+ if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
+ profile_,
+ kFileManagerAppId,
+ current_directory_path,
+ &current_directory_virtual_path)) {
+ // Fallback if necessary, see the comment above.
+ if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
+ profile_,
+ kFileManagerAppId,
+ fallback_path,
+ &current_directory_virtual_path)) {
+ LOG(ERROR) << "Unable to resolve the current directory path: "
+ << fallback_path.value();
+ return;
+ }
}
+ current_directory_virtual_path = base::FilePath("/").Append(
+ current_directory_virtual_path);
has_multiple_file_type_choices_ =
file_types ? file_types->extensions.size() > 1 : true;
Peter Kasting 2014/01/24 19:17:25 Nit: Slightly simpler: !file_types || (file
mtomasz 2014/01/27 02:38:44 Done.
GURL file_manager_url =
file_manager::util::GetFileManagerMainPageUrlWithParams(
- type, title, virtual_path, file_types, file_type_index,
+ type,
+ title,
+ current_directory_virtual_path,
+ selection_virtual_path,
+ file_types,
+ file_type_index,
default_extension);
ExtensionDialog* dialog = ExtensionDialog::Show(file_manager_url,

Powered by Google App Engine
This is Rietveld 408576698