summaryrefslogtreecommitdiffstats
path: root/chromecast/base/path_utils.cc
blob: 4f5b27b7e02fc7411cd80c4408246dd162d0c599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromecast/base/path_utils.h"

#include "base/logging.h"
#include "base/path_service.h"

namespace chromecast {

namespace {

base::FilePath GetPath(base::BasePathKey default_dir_key,
                       const base::FilePath& path) {
  if (path.IsAbsolute())
    return path;

  base::FilePath default_dir;
  if (!PathService::Get(default_dir_key, &default_dir))
    LOG(DFATAL) << "Cannot get default dir: " << default_dir_key;

  base::FilePath adjusted_path(default_dir.Append(path));
  VLOG(1) << "Path adjusted from " << path.value() << " to "
          << adjusted_path.value();
  return adjusted_path;
}

}  // namespace

base::FilePath GetHomePath(const base::FilePath& path) {
  return GetPath(base::DIR_HOME, path);
}

base::FilePath GetHomePathASCII(const std::string& path) {
  return GetHomePath(base::FilePath(path));
}

base::FilePath GetBinPath(const base::FilePath& path) {
  return GetPath(base::DIR_EXE, path);
}

base::FilePath GetBinPathASCII(const std::string& path) {
  return GetBinPath(base::FilePath(path));
}

base::FilePath GetTmpPath(const base::FilePath& path) {
  return GetPath(base::DIR_TEMP, path);
}

base::FilePath GetTmpPathASCII(const std::string& path) {
  return GetTmpPath(base::FilePath(path));
}

}  // namespace chromecast