blob: 45af316ee03b8ca4c05102bb72ce61893cc8f465 [file] [log] [blame]
Ruben Rodriguez Buchillon5cd4a9c2017-04-26 13:03:04 -07001// Copyright 2017 The Chromium OS 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 "thd/source/file_source.h"
6
7#include <string>
8
Qijiang Fan713061e2021-03-08 15:45:12 +09009#include <base/check.h>
Ruben Rodriguez Buchillon5cd4a9c2017-04-26 13:03:04 -070010#include <base/files/file_util.h>
11#include <base/logging.h>
12#include <base/strings/string_number_conversions.h>
13
14namespace thd {
15
16FileSource::FileSource(const base::FilePath& file_path)
17 : file_path_(file_path) {}
18
19FileSource::~FileSource() {}
20
21bool FileSource::ReadValue(int64_t* value_out) {
22 DCHECK(value_out);
23 if (!base::PathExists(file_path_)) {
24 LOG(ERROR) << "Path " << file_path_.value() << " not found.";
25 return false;
26 }
27 std::string contents;
28 if (!base::ReadFileToString(file_path_, &contents)) {
29 PLOG(ERROR) << "Failed to read path " << file_path_.value() << ".";
30 return false;
31 }
32 return base::StringToInt64(contents, value_out);
33}
34
35} // namespace thd