Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: ui/base/ui_base_paths.cc

Issue 288323003: ui: Fix the path of DIR_TEST_DATA key. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.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) 13 #if defined(OS_ANDROID)
14 #include "base/android/path_utils.h" 14 #include "base/android/path_utils.h"
15 #endif 15 #endif
16 16
17 namespace ui { 17 namespace ui {
18 18
19 bool PathProvider(int key, base::FilePath* result) { 19 bool PathProvider(int key, base::FilePath* result) {
20 // 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.
21 // 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.
22 bool create_dir = false; 22 bool create_dir = false;
23 23
24 base::FilePath cur; 24 base::FilePath cur;
25 switch (key) { 25 switch (key) {
26 case ui::DIR_LOCALES: 26 case DIR_LOCALES:
27 if (!PathService::Get(base::DIR_MODULE, &cur)) 27 if (!PathService::Get(base::DIR_MODULE, &cur))
28 return false; 28 return false;
29 #if defined(OS_MACOSX) 29 #if defined(OS_MACOSX)
30 // 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
31 // App dir. 31 // App dir.
32 cur = cur.DirName(); 32 cur = cur.DirName();
33 cur = cur.Append(FILE_PATH_LITERAL("Resources")); 33 cur = cur.Append(FILE_PATH_LITERAL("Resources"));
34 #elif defined(OS_ANDROID) 34 #elif defined(OS_ANDROID)
35 if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur)) 35 if (!PathService::Get(DIR_RESOURCE_PAKS_ANDROID, &cur))
36 return false; 36 return false;
37 #else 37 #else
38 cur = cur.Append(FILE_PATH_LITERAL("locales")); 38 cur = cur.Append(FILE_PATH_LITERAL("locales"));
39 #endif 39 #endif
40 create_dir = true; 40 create_dir = true;
41 break; 41 break;
42 // The following are only valid in the development environment, and 42 // The following are only valid in the development environment, and
43 // will fail if executed from an installed executable (because the 43 // will fail if executed from an installed executable (because the
44 // generated path won't exist). 44 // generated path won't exist).
45 case ui::DIR_TEST_DATA: 45 case DIR_TEST_DATA:
tony 2014/05/15 23:58:26 I would name this UI_DIR_TEST_DATA to make it clea
tfarina 2014/05/16 01:16:57 Done.
46 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur)) 46 if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
47 return false; 47 return false;
48 cur = cur.Append(FILE_PATH_LITERAL("app")); 48 cur = cur.Append(FILE_PATH_LITERAL("ui"));
49 cur = cur.Append(FILE_PATH_LITERAL("base"));
49 cur = cur.Append(FILE_PATH_LITERAL("test")); 50 cur = cur.Append(FILE_PATH_LITERAL("test"));
50 cur = cur.Append(FILE_PATH_LITERAL("data")); 51 cur = cur.Append(FILE_PATH_LITERAL("data"));
51 if (!base::PathExists(cur)) // we don't want to create this 52 if (!base::PathExists(cur)) // we don't want to create this
52 return false; 53 return false;
53 break; 54 break;
54 #if defined(OS_ANDROID) 55 #if defined(OS_ANDROID)
55 case ui::DIR_RESOURCE_PAKS_ANDROID: 56 case DIR_RESOURCE_PAKS_ANDROID:
56 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur)) 57 if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur))
57 return false; 58 return false;
58 cur = cur.Append(FILE_PATH_LITERAL("paks")); 59 cur = cur.Append(FILE_PATH_LITERAL("paks"));
59 break; 60 break;
60 #endif 61 #endif
61 case UI_TEST_PAK: 62 case UI_TEST_PAK:
62 if (!PathService::Get(base::DIR_MODULE, &cur)) 63 if (!PathService::Get(base::DIR_MODULE, &cur))
63 return false; 64 return false;
64 cur = cur.AppendASCII("ui_test.pak"); 65 cur = cur.AppendASCII("ui_test.pak");
65 break; 66 break;
66 default: 67 default:
67 return false; 68 return false;
68 } 69 }
69 70
70 if (create_dir && !base::PathExists(cur) && 71 if (create_dir && !base::PathExists(cur) &&
71 !base::CreateDirectory(cur)) 72 !base::CreateDirectory(cur))
72 return false; 73 return false;
73 74
74 *result = cur; 75 *result = cur;
75 return true; 76 return true;
76 } 77 }
77 78
78 // This cannot be done as a static initializer sadly since Visual Studio will 79 // This cannot be done as a static initializer sadly since Visual Studio will
79 // eliminate this object file if there is no direct entry point into it. 80 // eliminate this object file if there is no direct entry point into it.
80 void RegisterPathProvider() { 81 void RegisterPathProvider() {
81 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); 82 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
82 } 83 }
83 84
84 } // namespace ui 85 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698