OLD | NEW |
1 // Copyright (c) 2010 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 "app/app_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 namespace app { | 13 namespace ui { |
14 | 14 |
15 bool PathProvider(int key, FilePath* result) { | 15 bool PathProvider(int key, FilePath* result) { |
16 // Assume that we will not need to create the directory if it does not exist. | 16 // 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. | 17 // This flag can be set to true for the cases where we want to create it. |
18 bool create_dir = false; | 18 bool create_dir = false; |
19 | 19 |
20 FilePath cur; | 20 FilePath cur; |
21 switch (key) { | 21 switch (key) { |
22 case app::DIR_LOCALES: | 22 case ui::DIR_LOCALES: |
23 if (!PathService::Get(base::DIR_MODULE, &cur)) | 23 if (!PathService::Get(base::DIR_MODULE, &cur)) |
24 return false; | 24 return false; |
25 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
26 // On Mac, locale files are in Contents/Resources, a sibling of the | 26 // On Mac, locale files are in Contents/Resources, a sibling of the |
27 // App dir. | 27 // App dir. |
28 cur = cur.DirName(); | 28 cur = cur.DirName(); |
29 cur = cur.Append(FILE_PATH_LITERAL("Resources")); | 29 cur = cur.Append(FILE_PATH_LITERAL("Resources")); |
30 #else | 30 #else |
31 cur = cur.Append(FILE_PATH_LITERAL("locales")); | 31 cur = cur.Append(FILE_PATH_LITERAL("locales")); |
32 #endif | 32 #endif |
33 create_dir = true; | 33 create_dir = true; |
34 break; | 34 break; |
35 case app::DIR_EXTERNAL_EXTENSIONS: | 35 case ui::FILE_RESOURCES_PAK: |
36 if (!PathService::Get(base::DIR_MODULE, &cur)) | |
37 return false; | |
38 #if defined(OS_MACOSX) | |
39 // On Mac, built-in extensions are in Contents/Extensions, a sibling of | |
40 // the App dir. If there are none, it may not exist. | |
41 cur = cur.DirName(); | |
42 cur = cur.Append(FILE_PATH_LITERAL("Extensions")); | |
43 create_dir = false; | |
44 #else | |
45 cur = cur.Append(FILE_PATH_LITERAL("extensions")); | |
46 create_dir = true; | |
47 #endif | |
48 break; | |
49 case app::FILE_RESOURCES_PAK: | |
50 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 36 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
51 if (!PathService::Get(base::DIR_EXE, &cur)) | 37 if (!PathService::Get(base::DIR_EXE, &cur)) |
52 return false; | 38 return false; |
53 // TODO(tony): We shouldn't be referencing chrome here. | 39 // TODO(tony): We shouldn't be referencing chrome here. |
54 cur = cur.AppendASCII("chrome.pak"); | 40 cur = cur.AppendASCII("chrome.pak"); |
55 #else | 41 #else |
56 NOTREACHED(); | 42 NOTREACHED(); |
57 #endif | 43 #endif |
58 break; | 44 break; |
59 // The following are only valid in the development environment, and | 45 // The following are only valid in the development environment, and |
60 // will fail if executed from an installed executable (because the | 46 // will fail if executed from an installed executable (because the |
61 // generated path won't exist). | 47 // generated path won't exist). |
62 case app::DIR_TEST_DATA: | 48 case ui::DIR_TEST_DATA: |
63 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) | 49 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) |
64 return false; | 50 return false; |
65 cur = cur.Append(FILE_PATH_LITERAL("app")); | 51 cur = cur.Append(FILE_PATH_LITERAL("app")); |
66 cur = cur.Append(FILE_PATH_LITERAL("test")); | 52 cur = cur.Append(FILE_PATH_LITERAL("test")); |
67 cur = cur.Append(FILE_PATH_LITERAL("data")); | 53 cur = cur.Append(FILE_PATH_LITERAL("data")); |
68 if (!file_util::PathExists(cur)) // we don't want to create this | 54 if (!file_util::PathExists(cur)) // we don't want to create this |
69 return false; | 55 return false; |
70 break; | 56 break; |
71 default: | 57 default: |
72 return false; | 58 return false; |
73 } | 59 } |
74 | 60 |
75 if (create_dir && !file_util::PathExists(cur) && | 61 if (create_dir && !file_util::PathExists(cur) && |
76 !file_util::CreateDirectory(cur)) | 62 !file_util::CreateDirectory(cur)) |
77 return false; | 63 return false; |
78 | 64 |
79 *result = cur; | 65 *result = cur; |
80 return true; | 66 return true; |
81 } | 67 } |
82 | 68 |
83 // This cannot be done as a static initializer sadly since Visual Studio will | 69 // This cannot be done as a static initializer sadly since Visual Studio will |
84 // eliminate this object file if there is no direct entry point into it. | 70 // eliminate this object file if there is no direct entry point into it. |
85 void RegisterPathProvider() { | 71 void RegisterPathProvider() { |
86 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 72 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
87 } | 73 } |
88 | 74 |
89 } // namespace app | 75 } // namespace ui |
OLD | NEW |