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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 10700136: Prettify output from chrome.fileSystem.getDisplayPath for POSIX profile directories (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Includes specific fix for Mac OS X, which was excluded from the posix code specifically 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace { 44 namespace {
45 45
46 struct RewritePair { 46 struct RewritePair {
47 int path_key; 47 int path_key;
48 const char* output; 48 const char* output;
49 }; 49 };
50 50
51 const RewritePair g_rewrite_pairs[] = { 51 const RewritePair g_rewrite_pairs[] = {
52 #if defined(OS_WIN) 52 #if defined(OS_WIN)
53 {base::DIR_PROFILE, "~"}, 53 {base::DIR_PROFILE, "~"},
54 #elif defined(OS_POSIX)
55 {base::DIR_HOME, "~"},
54 #endif 56 #endif
55 }; 57 };
56 58
57 FilePath PrettifyPath(const FilePath& file_path) { 59 FilePath PrettifyPath(const FilePath& file_path) {
58 // Note that when g_rewrite_pairs includes at least one value on all 60 #if defined(OS_WIN) || defined(OS_POSIX)
59 // platforms, this code can be cleaned up. 61 for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) {
60 #if defined(OS_WIN)
61 size_t size = arraysize(g_rewrite_pairs);
62 #else
63 size_t size = 0;
64 #endif
65
66 for (size_t i = 0; i < size; ++i) {
67 FilePath candidate_path; 62 FilePath candidate_path;
68 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) 63 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path))
69 continue; // We don't DCHECK this value, as Get will return false even 64 continue; // We don't DCHECK this value, as Get will return false even
70 // if the path_key gives a blank string as a result. 65 // if the path_key gives a blank string as a result.
71 66
72 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); 67 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output);
73 if (candidate_path.AppendRelativePath(file_path, &output)) { 68 if (candidate_path.AppendRelativePath(file_path, &output)) {
74 // The output path must not be absolute, as it might collide with the 69 // The output path must not be absolute, as it might collide with the
75 // real filesystem. 70 // real filesystem.
76 DCHECK(!output.IsAbsolute()); 71 DCHECK(!output.IsAbsolute());
77 return output; 72 return output;
78 } 73 }
79 } 74 }
75 #endif
80 76
81 return file_path; 77 return file_path;
82 } 78 }
83 79
84 bool g_skip_picker_for_test = false; 80 bool g_skip_picker_for_test = false;
85 FilePath* g_path_to_be_picked_for_test; 81 FilePath* g_path_to_be_picked_for_test;
86 82
87 bool GetFilePathOfFileEntry(const std::string& filesystem_name, 83 bool GetFilePathOfFileEntry(const std::string& filesystem_name,
88 const std::string& filesystem_path, 84 const std::string& filesystem_path,
89 const content::RenderViewHost* render_view_host, 85 const content::RenderViewHost* render_view_host,
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 427
432 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { 428 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) {
433 error_ = kRequiresFileSystemWriteError; 429 error_ = kRequiresFileSystemWriteError;
434 return false; 430 return false;
435 } 431 }
436 432
437 return ShowPicker(suggested_name, picker_type, entry_type); 433 return ShowPicker(suggested_name, picker_type, entry_type);
438 } 434 }
439 435
440 } // namespace extensions 436 } // namespace extensions
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | chrome/browser/extensions/api/file_system/file_system_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698