Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / component_updater / component_updater_paths.cc
blob7a3fbbf49bad9b17851d3df46a75d0bae71d7f7b
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.
5 #include "components/component_updater/component_updater_paths.h"
7 #include "base/lazy_instance.h"
8 #include "base/path_service.h"
10 namespace component_updater {
12 namespace {
14 // This key gives the root directory of all the component installations.
15 static int g_components_root_key = -1;
17 } // namespace
19 bool PathProvider(int key, base::FilePath* result) {
20 DCHECK_GT(g_components_root_key, 0);
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;
27 base::FilePath cur;
28 if (!PathService::Get(g_components_root_key, &cur))
29 return false;
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;
51 *result = cur;
52 return true;
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.
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);
62 g_components_root_key = components_root_key;
63 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
66 } // namespace component_updater