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/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
13 #if defined(OS_ANDROID)
14 #include "base/android/path_utils.h"
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;
27 if (!PathService::Get(base::DIR_MODULE, &cur))
29 #if defined(OS_MACOSX)
30 // On Mac, locale files are in Contents/Resources, a sibling of the
33 cur = cur.Append(FILE_PATH_LITERAL("Resources"));
34 #elif defined(OS_ANDROID)
35 if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
38 cur = cur.Append(FILE_PATH_LITERAL("locales"));
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))
48 cur = cur.Append(FILE_PATH_LITERAL("app"));
49 cur = cur.Append(FILE_PATH_LITERAL("test"));
50 cur = cur.Append(FILE_PATH_LITERAL("data"));
51 if (!base::PathExists(cur)) // we don't want to create this
54 #if defined(OS_ANDROID)
55 case ui::DIR_RESOURCE_PAKS_ANDROID:
56 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur))
58 cur = cur.Append(FILE_PATH_LITERAL("paks"));
65 if (create_dir && !base::PathExists(cur) &&
66 !file_util::CreateDirectory(cur))
73 // This cannot be done as a static initializer sadly since Visual Studio will
74 // eliminate this object file if there is no direct entry point into it.
75 void RegisterPathProvider() {
76 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);