Add ICU message format support
[chromium-blink-merge.git] / ui / base / ui_base_paths.cc
blobc0246f8b2b3351aec9a8abfc20a2534dd4ed6d9f
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
3 // found in the LICENSE file.
5 #include "ui/base/ui_base_paths.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
13 #if defined(OS_ANDROID)
14 #include "base/android/path_utils.h"
15 #endif
17 namespace ui {
19 bool PathProvider(int key, base::FilePath* result) {
20 // Assume that we will not need to create the directory if it does not exist.
21 // This flag can be set to true for the cases where we want to create it.
22 bool create_dir = false;
24 base::FilePath cur;
25 switch (key) {
26 case DIR_LOCALES:
27 if (!PathService::Get(base::DIR_MODULE, &cur))
28 return false;
29 #if defined(OS_MACOSX)
30 // On Mac, locale files are in Contents/Resources, a sibling of the
31 // App dir.
32 cur = cur.DirName();
33 cur = cur.Append(FILE_PATH_LITERAL("Resources"));
34 #elif defined(OS_ANDROID)
35 if (!PathService::Get(DIR_RESOURCE_PAKS_ANDROID, &cur))
36 return false;
37 #else
38 cur = cur.Append(FILE_PATH_LITERAL("locales"));
39 #endif
40 create_dir = true;
41 break;
42 // The following are only valid in the development environment, and
43 // will fail if executed from an installed executable (because the
44 // generated path won't exist).
45 case UI_DIR_TEST_DATA:
46 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
47 return false;
48 cur = cur.Append(FILE_PATH_LITERAL("ui"));
49 cur = cur.Append(FILE_PATH_LITERAL("base"));
50 cur = cur.Append(FILE_PATH_LITERAL("test"));
51 cur = cur.Append(FILE_PATH_LITERAL("data"));
52 if (!base::PathExists(cur)) // we don't want to create this
53 return false;
54 break;
55 #if defined(OS_ANDROID)
56 case DIR_RESOURCE_PAKS_ANDROID:
57 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur))
58 return false;
59 cur = cur.Append(FILE_PATH_LITERAL("paks"));
60 break;
61 #endif
62 case UI_TEST_PAK:
63 #if defined(OS_ANDROID)
64 if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
65 return false;
66 #else
67 if (!PathService::Get(base::DIR_MODULE, &cur))
68 return false;
69 #endif
70 cur = cur.AppendASCII("ui_test.pak");
71 break;
72 default:
73 return false;
76 if (create_dir && !base::PathExists(cur) &&
77 !base::CreateDirectory(cur))
78 return false;
80 *result = cur;
81 return true;
84 // This cannot be done as a static initializer sadly since Visual Studio will
85 // eliminate this object file if there is no direct entry point into it.
86 void RegisterPathProvider() {
87 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
90 } // namespace ui