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

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: guard code with OS_WIN || OS_POSIX, plus FilePath fix 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/path_service.h" 10 #include "base/path_service.h"
(...skipping 30 matching lines...) Expand all
41 namespace { 41 namespace {
42 42
43 struct RewritePair { 43 struct RewritePair {
44 int path_key; 44 int path_key;
45 const char* output; 45 const char* output;
46 }; 46 };
47 47
48 const RewritePair g_rewrite_pairs[] = { 48 const RewritePair g_rewrite_pairs[] = {
49 #if defined(OS_WIN) 49 #if defined(OS_WIN)
50 {base::DIR_PROFILE, "~"}, 50 {base::DIR_PROFILE, "~"},
51 #elif defined(OS_POSIX)
52 {base::DIR_HOME, "~"},
51 #endif 53 #endif
52 }; 54 };
53 55
54 FilePath PrettifyPath(const FilePath& file_path) { 56 FilePath PrettifyPath(const FilePath& file_path) {
55 // Note that when g_rewrite_pairs includes at least one value on all 57 #if defined(OS_WIN) || defined(OS_POSIX)
56 // platforms, this code can be cleaned up. 58 for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) {
57 #if defined(OS_WIN)
58 size_t size = arraysize(g_rewrite_pairs);
59 #else
60 size_t size = 0;
61 #endif
62
63 for (size_t i = 0; i < size; ++i) {
64 FilePath candidate_path; 59 FilePath candidate_path;
65 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) 60 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path))
66 continue; // We don't DCHECK this value, as Get will return false even 61 continue; // We don't DCHECK this value, as Get will return false even
67 // if the path_key gives a blank string as a result. 62 // if the path_key gives a blank string as a result.
68 63
69 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); 64 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output);
70 if (candidate_path.AppendRelativePath(file_path, &output)) { 65 if (candidate_path.AppendRelativePath(file_path, &output)) {
71 // The output path must not be absolute, as it might collide with the 66 // The output path must not be absolute, as it might collide with the
72 // real filesystem. 67 // real filesystem.
73 DCHECK(!output.IsAbsolute()); 68 DCHECK(!output.IsAbsolute());
74 return output; 69 return output;
75 } 70 }
76 } 71 }
72 #endif
77 73
78 return file_path; 74 return file_path;
79 } 75 }
80 76
81 bool g_skip_picker_for_test = false; 77 bool g_skip_picker_for_test = false;
82 FilePath* g_path_to_be_picked_for_test; 78 FilePath* g_path_to_be_picked_for_test;
83 79
84 bool GetFilePathOfFileEntry(const std::string& filesystem_name, 80 bool GetFilePathOfFileEntry(const std::string& filesystem_name,
85 const std::string& filesystem_path, 81 const std::string& filesystem_path,
86 const content::RenderViewHost* render_view_host, 82 const content::RenderViewHost* render_view_host,
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 385
390 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { 386 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) {
391 error_ = kRequiresFileSystemWriteError; 387 error_ = kRequiresFileSystemWriteError;
392 return false; 388 return false;
393 } 389 }
394 390
395 return ShowPicker(FilePath(), picker_type, entry_type); 391 return ShowPicker(FilePath(), picker_type, entry_type);
396 } 392 }
397 393
398 } // namespace extensions 394 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698