• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "components/component_updater/component_updater_paths.h"
6 
7 #include "base/lazy_instance.h"
8 #include "base/path_service.h"
9 
10 namespace component_updater {
11 
12 namespace {
13 
14 // This key gives the root directory of all the component installations.
15 static int g_components_root_key = -1;
16 
17 }  // namespace
18 
PathProvider(int key,base::FilePath * result)19 bool PathProvider(int key, base::FilePath* result) {
20   DCHECK_GT(g_components_root_key, 0);
21 
22   // Early exit here to prevent a potential infinite loop when we retrieve
23   // the path for g_components_root_key.
24   if (key < PATH_START || key > PATH_END)
25     return false;
26 
27   base::FilePath cur;
28   if (!PathService::Get(g_components_root_key, &cur))
29     return false;
30 
31   switch (key) {
32     case DIR_COMPONENT_CLD2:
33       cur = cur.Append(FILE_PATH_LITERAL("CLD"));
34       break;
35     case DIR_RECOVERY_BASE:
36       cur = cur.Append(FILE_PATH_LITERAL("recovery"));
37       break;
38     case DIR_SWIFT_SHADER:
39       cur = cur.Append(FILE_PATH_LITERAL("SwiftShader"));
40       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     default:
48       return false;
49   }
50 
51   *result = cur;
52   return true;
53 }
54 
55 // This cannot be done as a static initializer sadly since Visual Studio will
56 // eliminate this object file if there is no direct entry point into it.
RegisterPathProvider(int components_root_key)57 void RegisterPathProvider(int components_root_key) {
58   DCHECK_EQ(g_components_root_key, -1);
59   DCHECK_GT(components_root_key, 0);
60   DCHECK(components_root_key < PATH_START || components_root_key > PATH_END);
61 
62   g_components_root_key = components_root_key;
63   PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
64 }
65 
66 }  // namespace component_updater
67