OLD | NEW |
---|---|
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 Loading... | |
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 for (size_t i = 0; i < arraysize(g_rewrite_pairs); ++i) { |
benwells
2012/07/10 23:57:49
I don't like relying on the fact that OS_POSIX is
thorogood
2012/07/11 00:30:24
I've guarded the whole for loop by "#if defined(OS
benwells
2012/07/11 04:51:45
Yeah agreed, this is nicer.
| |
56 // platforms, this code can be cleaned up. | |
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; | 58 FilePath candidate_path; |
65 if (!PathService::Get(g_rewrite_pairs[i].path_key, &candidate_path)) | 59 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 | 60 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. | 61 // if the path_key gives a blank string as a result. |
68 | 62 |
69 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); | 63 FilePath output = FilePath::FromUTF8Unsafe(g_rewrite_pairs[i].output); |
70 if (candidate_path.AppendRelativePath(file_path, &output)) { | 64 if (candidate_path.AppendRelativePath(file_path, &output)) { |
71 // The output path must not be absolute, as it might collide with the | 65 // The output path must not be absolute, as it might collide with the |
72 // real filesystem. | 66 // real filesystem. |
73 DCHECK(!output.IsAbsolute()); | 67 DCHECK(!output.IsAbsolute()); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 | 383 |
390 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { | 384 if (entry_type == WRITABLE && !HasFileSystemWritePermission()) { |
391 error_ = kRequiresFileSystemWriteError; | 385 error_ = kRequiresFileSystemWriteError; |
392 return false; | 386 return false; |
393 } | 387 } |
394 | 388 |
395 return ShowPicker(FilePath(), picker_type, entry_type); | 389 return ShowPicker(FilePath(), picker_type, entry_type); |
396 } | 390 } |
397 | 391 |
398 } // namespace extensions | 392 } // namespace extensions |
OLD | NEW |