1 // Copyright 2017 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/viz/test/paths.h"
6 
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/path_service.h"
10 
11 namespace viz {
12 
PathProvider(int key,base::FilePath * result)13 bool PathProvider(int key, base::FilePath* result) {
14   base::FilePath cur;
15   switch (key) {
16     // The following are only valid in the development environment, and
17     // will fail if executed from an installed executable (because the
18     // generated path won't exist).
19     case Paths::DIR_TEST_DATA:
20       if (!base::PathService::Get(base::DIR_SOURCE_ROOT, &cur))
21         return false;
22       cur = cur.Append(FILE_PATH_LITERAL("components"));
23       cur = cur.Append(FILE_PATH_LITERAL("viz"));
24       cur = cur.Append(FILE_PATH_LITERAL("test"));
25       cur = cur.Append(FILE_PATH_LITERAL("data"));
26       if (!base::PathExists(cur))  // we don't want to create this
27         return false;
28       break;
29     default:
30       return false;
31   }
32 
33   *result = cur;
34   return true;
35 }
36 
37 // This cannot be done as a static initializer sadly since Visual Studio will
38 // eliminate this object file if there is no direct entry point into it.
RegisterPathProvider()39 void Paths::RegisterPathProvider() {
40   base::PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
41 }
42 
43 }  // namespace viz
44