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 "base/path_service.h" | 5 #include "base/path_service.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.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/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #pragma comment(lib, "userenv.lib") | 21 #pragma comment(lib, "userenv.lib") |
22 #endif | 22 #endif |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Returns true if PathService::Get returns true and sets the path parameter | 26 // Returns true if PathService::Get returns true and sets the path parameter |
27 // to non-empty for the given PathService::DirType enumeration value. | 27 // to non-empty for the given PathService::DirType enumeration value. |
28 bool ReturnsValidPath(int dir_type) { | 28 bool ReturnsValidPath(int dir_type) { |
29 FilePath path; | 29 FilePath path; |
30 bool result = PathService::Get(dir_type, &path); | 30 bool result = PathService::Get(dir_type, &path); |
31 | |
31 // Some paths might not exist on some platforms in which case confirming | 32 // Some paths might not exist on some platforms in which case confirming |
32 // |result| is true and !path.empty() is the best we can do. | 33 // |result| is true and !path.empty() is the best we can do. |
33 bool check_path_exists = true; | 34 bool check_path_exists = true; |
34 #if defined(OS_POSIX) | 35 #if defined(OS_POSIX) |
35 // If chromium has never been started on this account, the cache path may not | 36 // If chromium has never been started on this account, the cache path may not |
36 // exist. | 37 // exist. |
37 if (dir_type == base::DIR_CACHE) | 38 if (dir_type == base::DIR_CACHE) |
38 check_path_exists = false; | 39 check_path_exists = false; |
39 #endif | 40 #endif |
40 #if defined(OS_LINUX) | 41 #if defined(OS_LINUX) |
(...skipping 13 matching lines...) Expand all Loading... | |
54 return (result && | 55 return (result && |
55 ::GetDefaultUserProfileDirectory(default_profile_path, &size) && | 56 ::GetDefaultUserProfileDirectory(default_profile_path, &size) && |
56 StartsWith(path.value(), default_profile_path, false)); | 57 StartsWith(path.value(), default_profile_path, false)); |
57 } | 58 } |
58 } else if (dir_type == base::DIR_TASKBAR_PINS) { | 59 } else if (dir_type == base::DIR_TASKBAR_PINS) { |
59 // There is no pinned-to-taskbar shortcuts prior to Win7. | 60 // There is no pinned-to-taskbar shortcuts prior to Win7. |
60 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 61 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
61 check_path_exists = false; | 62 check_path_exists = false; |
62 } | 63 } |
63 #endif | 64 #endif |
65 #if defined(OS_MAC) | |
Nico
2013/03/13 23:18:40
It's OS_MAXOSX (https://codereview.chromium.org/12
| |
66 if (dir_type != base::DIR_EXE && dir_type != base::DIR_MODULE && | |
67 dir_type != base::FILE_EXE && dir_type != base::FILE_MODULE) { | |
68 if (path.ReferencesParent()) | |
69 return false; | |
70 } | |
71 #else | |
72 if (path.ReferencesParent()) | |
73 return false; | |
74 #endif | |
64 return result && !path.empty() && (!check_path_exists || | 75 return result && !path.empty() && (!check_path_exists || |
65 file_util::PathExists(path)); | 76 file_util::PathExists(path)); |
66 } | 77 } |
67 | 78 |
68 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
69 // Function to test any directory keys that are not supported on some versions | 80 // Function to test any directory keys that are not supported on some versions |
70 // of Windows. Checks that the function fails and that the returned path is | 81 // of Windows. Checks that the function fails and that the returned path is |
71 // empty. | 82 // empty. |
72 bool ReturnsInvalidPath(int dir_type) { | 83 bool ReturnsInvalidPath(int dir_type) { |
73 FilePath path; | 84 FilePath path; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 207 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
197 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); | 208 EXPECT_TRUE(PathService::Override(base::DIR_TEMP, temp_dir.path())); |
198 FilePath new_user_data_dir; | 209 FilePath new_user_data_dir; |
199 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); | 210 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); |
200 EXPECT_NE(original_user_data_dir, new_user_data_dir); | 211 EXPECT_NE(original_user_data_dir, new_user_data_dir); |
201 | 212 |
202 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); | 213 EXPECT_TRUE(PathService::RemoveOverride(base::DIR_TEMP)); |
203 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); | 214 EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &new_user_data_dir)); |
204 EXPECT_EQ(original_user_data_dir, new_user_data_dir); | 215 EXPECT_EQ(original_user_data_dir, new_user_data_dir); |
205 } | 216 } |
OLD | NEW |