OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/component_updater/component_updater_paths.h" | 5 #include "components/component_updater/component_updater_paths.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 | 9 |
10 namespace component_updater { | 10 namespace component_updater { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // This key gives the root directory of all the component installations. | 14 // This key gives the root directory of all the component installations. |
15 static int g_components_root_key = -1; | 15 static int g_components_system_root_key = -1; |
16 static int g_components_user_root_key = -1; | |
16 | 17 |
17 } // namespace | 18 } // namespace |
18 | 19 |
19 bool PathProvider(int key, base::FilePath* result) { | 20 bool PathProvider(int key, base::FilePath* result) { |
20 DCHECK_GT(g_components_root_key, 0); | 21 DCHECK_GT(g_components_user_root_key, 0); |
22 DCHECK_GT(g_components_system_root_key, 0); | |
21 | 23 |
22 // Early exit here to prevent a potential infinite loop when we retrieve | 24 // Early exit here to prevent a potential infinite loop when we retrieve |
23 // the path for g_components_root_key. | 25 // the path for g_components_*_root_key. |
24 if (key < PATH_START || key > PATH_END) | 26 if (key < PATH_START || key > PATH_END) |
25 return false; | 27 return false; |
26 | 28 |
29 switch (key) { | |
30 case DIR_COMPONENT_SYSTEM: | |
31 return PathService::Get(g_components_system_root_key, result); | |
32 case DIR_COMPONENT_USER: | |
33 return PathService::Get(g_components_user_root_key, result); | |
34 } | |
35 | |
27 base::FilePath cur; | 36 base::FilePath cur; |
28 if (!PathService::Get(g_components_root_key, &cur)) | 37 if (!PathService::Get(g_components_user_root_key, &cur)) |
29 return false; | 38 return false; |
30 | 39 |
31 switch (key) { | 40 switch (key) { |
32 case DIR_COMPONENT_CLD2: | 41 case DIR_COMPONENT_CLD2: |
33 cur = cur.Append(FILE_PATH_LITERAL("CLD")); | 42 cur = cur.Append(FILE_PATH_LITERAL("CLD")); |
34 break; | 43 break; |
35 case DIR_RECOVERY_BASE: | 44 case DIR_RECOVERY_BASE: |
36 cur = cur.Append(FILE_PATH_LITERAL("recovery")); | 45 cur = cur.Append(FILE_PATH_LITERAL("recovery")); |
37 break; | 46 break; |
38 case DIR_SWIFT_SHADER: | 47 case DIR_SWIFT_SHADER: |
39 cur = cur.Append(FILE_PATH_LITERAL("SwiftShader")); | 48 cur = cur.Append(FILE_PATH_LITERAL("SwiftShader")); |
40 break; | 49 break; |
41 case DIR_SW_REPORTER: | |
42 cur = cur.Append(FILE_PATH_LITERAL("SwReporter")); | |
43 break; | |
44 case DIR_COMPONENT_EV_WHITELIST: | |
45 cur = cur.Append(FILE_PATH_LITERAL("EVWhitelist")); | |
46 break; | |
47 case DIR_SUPERVISED_USER_WHITELISTS: | 50 case DIR_SUPERVISED_USER_WHITELISTS: |
Bernhard Bauer
2016/05/04 08:57:37
We should probably remove this value now.
waffles
2016/05/10 18:15:53
Yeah, I wasn't sure about this, because it require
Bernhard Bauer
2016/05/12 08:37:22
D'oh! I overlooked that occurrence. Hm, as it is r
waffles
2016/05/12 17:06:07
We can't depend directly on chrome_constants from
Bernhard Bauer
2016/05/12 17:28:58
In practice, probably not a big risk (this code is
waffles
2016/05/13 18:19:13
Added it in component_updater_paths; not sure this
| |
48 cur = cur.Append(FILE_PATH_LITERAL("SupervisedUserWhitelists")); | 51 cur = cur.Append(FILE_PATH_LITERAL("SupervisedUserWhitelists")); |
49 break; | 52 break; |
50 case DIR_CERT_TRANS_TREE_STATES: | |
51 cur = cur.Append(FILE_PATH_LITERAL("CertificateTransparency")); | |
52 break; | |
53 case DIR_ORIGIN_TRIAL_KEYS: | |
54 cur = cur.Append(FILE_PATH_LITERAL("OriginTrials")); | |
55 break; | |
56 default: | 53 default: |
57 return false; | 54 return false; |
58 } | 55 } |
59 | 56 |
60 *result = cur; | 57 *result = cur; |
61 return true; | 58 return true; |
62 } | 59 } |
63 | 60 |
64 // This cannot be done as a static initializer sadly since Visual Studio will | 61 // This cannot be done as a static initializer sadly since Visual Studio will |
65 // eliminate this object file if there is no direct entry point into it. | 62 // eliminate this object file if there is no direct entry point into it. |
66 void RegisterPathProvider(int components_root_key) { | 63 void RegisterPathProvider(int components_system_root_key, |
67 DCHECK_EQ(g_components_root_key, -1); | 64 int components_user_root_key) { |
68 DCHECK_GT(components_root_key, 0); | 65 DCHECK_EQ(g_components_system_root_key, -1); |
69 DCHECK(components_root_key < PATH_START || components_root_key > PATH_END); | 66 DCHECK_EQ(g_components_user_root_key, -1); |
67 DCHECK_GT(components_system_root_key, 0); | |
68 DCHECK_GT(components_user_root_key, 0); | |
69 DCHECK(components_system_root_key < PATH_START || | |
70 components_system_root_key > PATH_END); | |
71 DCHECK(components_user_root_key < PATH_START || | |
72 components_user_root_key > PATH_END); | |
70 | 73 |
71 g_components_root_key = components_root_key; | 74 g_components_system_root_key = components_system_root_key; |
75 g_components_user_root_key = components_user_root_key; | |
72 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 76 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
73 } | 77 } |
74 | 78 |
75 } // namespace component_updater | 79 } // namespace component_updater |
OLD | NEW |