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

Unified Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 10693089: Prettify output from chrome.fileSystem.getDisplayPath for Windows profile directory (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/extensions/api/file_system/file_system_api.cc
diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc
index dc0742ad315d53a19c59f223ce5d94daefd276b1..e7d7af2a1e41b5d912efed705c68fde6b20fede3 100644
--- a/chrome/browser/extensions/api/file_system/file_system_api.cc
+++ b/chrome/browser/extensions/api/file_system/file_system_api.cc
@@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/extensions/shell_window.h"
@@ -37,6 +39,37 @@ namespace ChooseFile = file_system::ChooseFile;
namespace {
+/*struct RewritePair {
benwells 2012/07/06 00:34:36 We should uncomment this and use to simplify g_rew
thorogood 2012/07/06 06:34:16 Done. Although this was mostly left over; I actual
+ int path_key;
+ const char* output;
+};*/
+
+const struct {
+ int path_key;
+ const char* output;
+} g_rewrite_pairs[] = {
+#if defined(OS_WIN)
+ {base::DIR_PROFILE, "HOME"},
benwells 2012/07/06 00:34:36 Can we make HOME a bit ... prettier? I'm open to
thorogood 2012/07/06 06:34:16 Probably - I'm not sure of a consistent way to get
+#endif
+ {-1, NULL}
+};
+
+void PrettifyPath(FilePath& file_path) {
+ for (int i = 0; g_rewrite_pairs[i].output; ++i) {
+ FilePath candidate_path;
+ if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) {
benwells 2012/07/06 00:34:36 Should failure here be an error?
thorogood 2012/07/06 06:34:16 Probably not. Get() returns false if it's just an
+ continue;
+ }
+
+ FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output);
+ if (candidate_path.AppendRelativePath(file_path, &output)) {
+ DCHECK(!output.IsAbsolute());
+ file_path = output;
+ return; // Only prettify the first hit.
+ }
+ }
+}
+
bool g_skip_picker_for_test = false;
FilePath* g_path_to_be_picked_for_test;
@@ -106,6 +139,7 @@ bool FileSystemGetDisplayPathFunction::RunImpl() {
render_view_host_, &file_path, &error_))
return false;
+ PrettifyPath(file_path);
result_.reset(base::Value::CreateStringValue(file_path.value()));
return true;
}

Powered by Google App Engine
This is Rietveld 408576698