| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/crash/linux/crash_testing_utils.h" | 5 #include "chromecast/crash/linux/crash_testing_utils.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::unique_ptr<base::Value> ParseMetadataFile(const std::string& path) { | 58 std::unique_ptr<base::Value> ParseMetadataFile(const std::string& path) { |
| 59 return DeserializeJsonFromFile(base::FilePath(path)); | 59 return DeserializeJsonFromFile(base::FilePath(path)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 int WriteLockFile(const std::string& path, base::ListValue* contents) { | 62 int WriteLockFile(const std::string& path, base::ListValue* contents) { |
| 63 DCHECK(contents); | 63 DCHECK(contents); |
| 64 std::string lockfile; | 64 std::string lockfile; |
| 65 | 65 |
| 66 for (const base::Value* elem : *contents) { | 66 for (const auto& elem : *contents) { |
| 67 std::unique_ptr<std::string> dump_info = SerializeToJson(*elem); | 67 std::unique_ptr<std::string> dump_info = SerializeToJson(*elem); |
| 68 RCHECK(dump_info, -1, "Failed to serialize DumpInfo"); | 68 RCHECK(dump_info, -1, "Failed to serialize DumpInfo"); |
| 69 lockfile += *dump_info; | 69 lockfile += *dump_info; |
| 70 lockfile += "\n"; // Add line seperatators | 70 lockfile += "\n"; // Add line seperatators |
| 71 } | 71 } |
| 72 | 72 |
| 73 return WriteFile(base::FilePath(path), lockfile.c_str(), lockfile.size()) >= 0 | 73 return WriteFile(base::FilePath(path), lockfile.c_str(), lockfile.size()) >= 0 |
| 74 ? 0 | 74 ? 0 |
| 75 : -1; | 75 : -1; |
| 76 } | 76 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool FetchDumps(const std::string& lockfile_path, | 90 bool FetchDumps(const std::string& lockfile_path, |
| 91 ScopedVector<DumpInfo>* dumps) { | 91 ScopedVector<DumpInfo>* dumps) { |
| 92 DCHECK(dumps); | 92 DCHECK(dumps); |
| 93 std::unique_ptr<base::ListValue> dump_list = ParseLockFile(lockfile_path); | 93 std::unique_ptr<base::ListValue> dump_list = ParseLockFile(lockfile_path); |
| 94 RCHECK(dump_list, false, "Failed to parse lockfile"); | 94 RCHECK(dump_list, false, "Failed to parse lockfile"); |
| 95 | 95 |
| 96 dumps->clear(); | 96 dumps->clear(); |
| 97 | 97 |
| 98 for (base::Value* elem : *dump_list) { | 98 for (const auto& elem : *dump_list) { |
| 99 std::unique_ptr<DumpInfo> dump = base::WrapUnique(new DumpInfo(elem)); | 99 std::unique_ptr<DumpInfo> dump(new DumpInfo(elem.get())); |
| 100 RCHECK(dump->valid(), false, "Invalid DumpInfo"); | 100 RCHECK(dump->valid(), false, "Invalid DumpInfo"); |
| 101 dumps->push_back(std::move(dump)); | 101 dumps->push_back(std::move(dump)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool ClearDumps(const std::string& lockfile_path) { | 107 bool ClearDumps(const std::string& lockfile_path) { |
| 108 std::unique_ptr<base::ListValue> dump_list = | 108 std::unique_ptr<base::ListValue> dump_list = |
| 109 base::WrapUnique(new base::ListValue()); | 109 base::WrapUnique(new base::ListValue()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 std::string period_start_str = | 156 std::string period_start_str = |
| 157 base::StringPrintf("%lld", static_cast<long long>(start)); | 157 base::StringPrintf("%lld", static_cast<long long>(start)); |
| 158 ratelimit_params->SetString(kRatelimitPeriodStartKey, period_start_str); | 158 ratelimit_params->SetString(kRatelimitPeriodStartKey, period_start_str); |
| 159 | 159 |
| 160 return WriteMetadataFile(metadata_path, contents.get()) == 0; | 160 return WriteMetadataFile(metadata_path, contents.get()) == 0; |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace chromecast | 163 } // namespace chromecast |
| OLD | NEW |