| 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_preinstalled_root_key = -1; |
| 16 static int g_components_user_root_key = -1; |
| 16 | 17 |
| 17 } // namespace | 18 } // namespace |
| 18 | 19 |
| 20 const base::FilePath::CharType kSupervisedUserWhitelistDirName[] = |
| 21 FILE_PATH_LITERAL("SupervisedUserWhitelists"); |
| 22 |
| 19 bool PathProvider(int key, base::FilePath* result) { | 23 bool PathProvider(int key, base::FilePath* result) { |
| 20 DCHECK_GT(g_components_root_key, 0); | 24 DCHECK_GT(g_components_user_root_key, 0); |
| 25 DCHECK_GT(g_components_preinstalled_root_key, 0); |
| 21 | 26 |
| 22 // Early exit here to prevent a potential infinite loop when we retrieve | 27 // Early exit here to prevent a potential infinite loop when we retrieve |
| 23 // the path for g_components_root_key. | 28 // the path for g_components_*_root_key. |
| 24 if (key < PATH_START || key > PATH_END) | 29 if (key < PATH_START || key > PATH_END) |
| 25 return false; | 30 return false; |
| 26 | 31 |
| 32 switch (key) { |
| 33 case DIR_COMPONENT_PREINSTALLED: |
| 34 return PathService::Get(g_components_preinstalled_root_key, result); |
| 35 case DIR_COMPONENT_USER: |
| 36 return PathService::Get(g_components_user_root_key, result); |
| 37 } |
| 38 |
| 27 base::FilePath cur; | 39 base::FilePath cur; |
| 28 if (!PathService::Get(g_components_root_key, &cur)) | 40 if (!PathService::Get(g_components_user_root_key, &cur)) |
| 29 return false; | 41 return false; |
| 30 | 42 |
| 31 switch (key) { | 43 switch (key) { |
| 32 case DIR_COMPONENT_CLD2: | 44 case DIR_COMPONENT_CLD2: |
| 33 cur = cur.Append(FILE_PATH_LITERAL("CLD")); | 45 cur = cur.Append(FILE_PATH_LITERAL("CLD")); |
| 34 break; | 46 break; |
| 35 case DIR_RECOVERY_BASE: | 47 case DIR_RECOVERY_BASE: |
| 36 cur = cur.Append(FILE_PATH_LITERAL("recovery")); | 48 cur = cur.Append(FILE_PATH_LITERAL("recovery")); |
| 37 break; | 49 break; |
| 38 case DIR_SWIFT_SHADER: | 50 case DIR_SWIFT_SHADER: |
| 39 cur = cur.Append(FILE_PATH_LITERAL("SwiftShader")); | 51 cur = cur.Append(FILE_PATH_LITERAL("SwiftShader")); |
| 40 break; | 52 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: | 53 case DIR_SUPERVISED_USER_WHITELISTS: |
| 48 cur = cur.Append(FILE_PATH_LITERAL("SupervisedUserWhitelists")); | 54 cur = cur.Append(kSupervisedUserWhitelistDirName); |
| 49 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; | 55 break; |
| 56 default: | 56 default: |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 | 59 |
| 60 *result = cur; | 60 *result = cur; |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // This cannot be done as a static initializer sadly since Visual Studio will | 64 // 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. | 65 // eliminate this object file if there is no direct entry point into it. |
| 66 void RegisterPathProvider(int components_root_key) { | 66 void RegisterPathProvider(int components_preinstalled_root_key, |
| 67 DCHECK_EQ(g_components_root_key, -1); | 67 int components_user_root_key) { |
| 68 DCHECK_GT(components_root_key, 0); | 68 DCHECK_EQ(g_components_preinstalled_root_key, -1); |
| 69 DCHECK(components_root_key < PATH_START || components_root_key > PATH_END); | 69 DCHECK_EQ(g_components_user_root_key, -1); |
| 70 DCHECK_GT(components_preinstalled_root_key, 0); |
| 71 DCHECK_GT(components_user_root_key, 0); |
| 72 DCHECK(components_preinstalled_root_key < PATH_START || |
| 73 components_preinstalled_root_key > PATH_END); |
| 74 DCHECK(components_user_root_key < PATH_START || |
| 75 components_user_root_key > PATH_END); |
| 70 | 76 |
| 71 g_components_root_key = components_root_key; | 77 g_components_preinstalled_root_key = components_preinstalled_root_key; |
| 78 g_components_user_root_key = components_user_root_key; |
| 72 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 79 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
| 73 } | 80 } |
| 74 | 81 |
| 75 } // namespace component_updater | 82 } // namespace component_updater |
| OLD | NEW |