Ensure low-memory renderers retry failed loads correctly.
[chromium-blink-merge.git] / components / component_updater / component_updater_paths.cc
blob834b1cf9d54b25e68717a2bf072c060236d59afb
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 case DIR_SUPERVISED_USER_WHITELISTS:
48 cur = cur.Append(FILE_PATH_LITERAL("SupervisedUserWhitelists"));
49 break;
50 default:
51 return false;
54 *result = cur;
55 return true;
58 // This cannot be done as a static initializer sadly since Visual Studio will
59 // eliminate this object file if there is no direct entry point into it.
60 void RegisterPathProvider(int components_root_key) {
61 DCHECK_EQ(g_components_root_key, -1);
62 DCHECK_GT(components_root_key, 0);
63 DCHECK(components_root_key < PATH_START || components_root_key > PATH_END);
65 g_components_root_key = components_root_key;
66 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
69 } // namespace component_updater