OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/base/ui_base_paths.h" | 5 #include "ui/base/ui_base_paths.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.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" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 | 12 |
| 13 #if defined(OS_ANDROID) |
| 14 #include "base/android/path_utils.h" |
| 15 #endif |
| 16 |
13 namespace ui { | 17 namespace ui { |
14 | 18 |
15 bool PathProvider(int key, FilePath* result) { | 19 bool PathProvider(int key, FilePath* result) { |
16 // Assume that we will not need to create the directory if it does not exist. | 20 // Assume that we will not need to create the directory if it does not exist. |
17 // This flag can be set to true for the cases where we want to create it. | 21 // This flag can be set to true for the cases where we want to create it. |
18 bool create_dir = false; | 22 bool create_dir = false; |
19 | 23 |
20 FilePath cur; | 24 FilePath cur; |
21 switch (key) { | 25 switch (key) { |
22 case ui::DIR_LOCALES: | 26 case ui::DIR_LOCALES: |
23 if (!PathService::Get(base::DIR_MODULE, &cur)) | 27 if (!PathService::Get(base::DIR_MODULE, &cur)) |
24 return false; | 28 return false; |
25 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
26 // On Mac, locale files are in Contents/Resources, a sibling of the | 30 // On Mac, locale files are in Contents/Resources, a sibling of the |
27 // App dir. | 31 // App dir. |
28 cur = cur.DirName(); | 32 cur = cur.DirName(); |
29 cur = cur.Append(FILE_PATH_LITERAL("Resources")); | 33 cur = cur.Append(FILE_PATH_LITERAL("Resources")); |
| 34 #elif defined(OS_ANDROID) |
| 35 if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur)) |
| 36 return false; |
30 #else | 37 #else |
31 cur = cur.Append(FILE_PATH_LITERAL("locales")); | 38 cur = cur.Append(FILE_PATH_LITERAL("locales")); |
32 #endif | 39 #endif |
33 create_dir = true; | 40 create_dir = true; |
34 break; | 41 break; |
35 // The following are only valid in the development environment, and | 42 // The following are only valid in the development environment, and |
36 // will fail if executed from an installed executable (because the | 43 // will fail if executed from an installed executable (because the |
37 // generated path won't exist). | 44 // generated path won't exist). |
38 case ui::DIR_TEST_DATA: | 45 case ui::DIR_TEST_DATA: |
39 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) | 46 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) |
40 return false; | 47 return false; |
41 cur = cur.Append(FILE_PATH_LITERAL("app")); | 48 cur = cur.Append(FILE_PATH_LITERAL("app")); |
42 cur = cur.Append(FILE_PATH_LITERAL("test")); | 49 cur = cur.Append(FILE_PATH_LITERAL("test")); |
43 cur = cur.Append(FILE_PATH_LITERAL("data")); | 50 cur = cur.Append(FILE_PATH_LITERAL("data")); |
44 if (!file_util::PathExists(cur)) // we don't want to create this | 51 if (!file_util::PathExists(cur)) // we don't want to create this |
45 return false; | 52 return false; |
46 break; | 53 break; |
| 54 #if defined(OS_ANDROID) |
| 55 case ui::DIR_RESOURCE_PAKS_ANDROID: |
| 56 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur)) |
| 57 return false; |
| 58 cur = cur.Append(FILE_PATH_LITERAL("paks")); |
| 59 break; |
| 60 #endif |
47 default: | 61 default: |
48 return false; | 62 return false; |
49 } | 63 } |
50 | 64 |
51 if (create_dir && !file_util::PathExists(cur) && | 65 if (create_dir && !file_util::PathExists(cur) && |
52 !file_util::CreateDirectory(cur)) | 66 !file_util::CreateDirectory(cur)) |
53 return false; | 67 return false; |
54 | 68 |
55 *result = cur; | 69 *result = cur; |
56 return true; | 70 return true; |
57 } | 71 } |
58 | 72 |
59 // This cannot be done as a static initializer sadly since Visual Studio will | 73 // This cannot be done as a static initializer sadly since Visual Studio will |
60 // eliminate this object file if there is no direct entry point into it. | 74 // eliminate this object file if there is no direct entry point into it. |
61 void RegisterPathProvider() { | 75 void RegisterPathProvider() { |
62 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 76 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
63 } | 77 } |
64 | 78 |
65 } // namespace ui | 79 } // namespace ui |
OLD | NEW |