1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/component_updater/component_updater_paths.h"
7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
11 namespace component_updater {
15 // This key gives the root directory of all the component installations.
16 static int g_components_preinstalled_root_key = -1;
17 static int g_components_preinstalled_root_key_alt = -1;
18 static int g_components_user_root_key = -1;
22 bool PathProvider(int key, base::FilePath* result) {
23 DCHECK_GT(g_components_user_root_key, 0);
24 DCHECK_GT(g_components_preinstalled_root_key, 0);
26 // Early exit here to prevent a potential infinite loop when we retrieve
27 // the path for g_components_*_root_key.
28 if (key < PATH_START || key > PATH_END)
32 case DIR_COMPONENT_PREINSTALLED:
33 return base::PathService::Get(g_components_preinstalled_root_key, result);
34 case DIR_COMPONENT_PREINSTALLED_ALT:
35 return base::PathService::Get(g_components_preinstalled_root_key_alt,
37 case DIR_COMPONENT_USER:
38 return base::PathService::Get(g_components_user_root_key, result);
42 if (!base::PathService::Get(g_components_user_root_key, &cur))
46 case DIR_COMPONENT_CLD2:
47 cur = cur.Append(FILE_PATH_LITERAL("CLD"));
49 case DIR_RECOVERY_BASE:
50 cur = cur.Append(FILE_PATH_LITERAL("recovery"));
52 case DIR_SWIFT_SHADER:
53 cur = cur.Append(FILE_PATH_LITERAL("SwiftShader"));
63 // This cannot be done as a static initializer sadly since Visual Studio will
64 // eliminate this object file if there is no direct entry point into it.
65 void RegisterPathProvider(int components_preinstalled_root_key,
66 int components_preinstalled_root_key_alt,
67 int components_user_root_key) {
68 DCHECK_EQ(g_components_preinstalled_root_key, -1);
69 DCHECK_EQ(g_components_preinstalled_root_key_alt, -1);
70 DCHECK_EQ(g_components_user_root_key, -1);
71 DCHECK_GT(components_preinstalled_root_key, 0);
72 DCHECK_GT(components_preinstalled_root_key_alt, 0);
73 DCHECK_GT(components_user_root_key, 0);
74 DCHECK(components_preinstalled_root_key < PATH_START ||
75 components_preinstalled_root_key > PATH_END);
76 DCHECK(components_preinstalled_root_key_alt < PATH_START ||
77 components_preinstalled_root_key_alt > PATH_END);
78 DCHECK(components_user_root_key < PATH_START ||
79 components_user_root_key > PATH_END);
81 g_components_preinstalled_root_key = components_preinstalled_root_key;
82 g_components_preinstalled_root_key_alt = components_preinstalled_root_key_alt;
83 g_components_user_root_key = components_user_root_key;
84 base::PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
87 } // namespace component_updater