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 c6fc2ec98af12f1abcba331b9f16f27e1f3431fc..13588ee7664da7d327d07ccbb9c8a5febda1230d 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/chrome_select_file_policy.h" |
@@ -38,6 +40,34 @@ namespace ChooseFile = file_system::ChooseFile; |
namespace { |
+struct RewritePair { |
+ int path_key; |
+ const char* output; |
+}; |
+ |
+RewritePair g_rewrite_pairs[] = { |
+#if defined(OS_WIN) |
+ {base::DIR_PROFILE, "~"}, |
+#endif |
+ {-1, NULL} |
+}; |
+ |
+void PrettifyPath(FilePath& file_path) { |
not at google - send to devlin
2012/07/09 02:07:38
Except in special circumstances, only pass const-r
thorogood
2012/07/09 05:12:45
I've made it return the new FilePath (by value). I
not at google - send to devlin
2012/07/09 05:44:58
The reason for these const-reference vs non-const-
thorogood
2012/07/09 05:58:35
Great, thanks for the write-up.
|
+ for (int i = 0; g_rewrite_pairs[i].output; ++i) { |
not at google - send to devlin
2012/07/09 02:07:38
Use arraysize(g_rewrite_pairs) rather than a senti
thorogood
2012/07/09 05:12:45
Hilariously, I can't use arraysize() on an empty a
|
+ FilePath candidate_path; |
+ if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) { |
+ continue; |
+ } |
not at google - send to devlin
2012/07/09 02:07:38
nit: no {}
thorogood
2012/07/09 05:12:45
Done.
|
+ |
+ FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); |
+ if (candidate_path.AppendRelativePath(file_path, &output)) { |
+ DCHECK(!output.IsAbsolute()); |
not at google - send to devlin
2012/07/09 02:07:38
This check could be done at construction time of P
thorogood
2012/07/09 05:12:45
I've added a comment. Basically I'm trying to say
|
+ file_path = output; |
+ return; // Only prettify the first hit. |
not at google - send to devlin
2012/07/09 02:07:38
nit: 2 spaces between ; and //
thorogood
2012/07/09 05:12:45
Done.
|
+ } |
+ } |
+} |
not at google - send to devlin
2012/07/09 02:07:38
TBH I think this would be more nicely factored as
benwells
2012/07/09 03:42:45
FWIW I have no strong preference but prefer it lik
thorogood
2012/07/09 05:12:45
I've taken benwells@' comment and left this as-is,
|
+ |
bool g_skip_picker_for_test = false; |
FilePath* g_path_to_be_picked_for_test; |
@@ -107,6 +137,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; |
} |