| 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/synchronized_minidump_manager.h" | 5 #include "chromecast/crash/linux/synchronized_minidump_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 DCHECK_GE(lockfile_fd_, 0); | 231 DCHECK_GE(lockfile_fd_, 0); |
| 232 DCHECK(!dumps_); | 232 DCHECK(!dumps_); |
| 233 DCHECK(!metadata_); | 233 DCHECK(!metadata_); |
| 234 | 234 |
| 235 std::string lockfile; | 235 std::string lockfile; |
| 236 RCHECK(ReadFileToString(lockfile_path_, &lockfile), false); | 236 RCHECK(ReadFileToString(lockfile_path_, &lockfile), false); |
| 237 | 237 |
| 238 std::vector<std::string> lines = base::SplitString( | 238 std::vector<std::string> lines = base::SplitString( |
| 239 lockfile, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 239 lockfile, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 240 | 240 |
| 241 std::unique_ptr<base::ListValue> dumps = | 241 std::unique_ptr<base::ListValue> dumps = base::MakeUnique<base::ListValue>(); |
| 242 base::WrapUnique(new base::ListValue()); | |
| 243 | 242 |
| 244 // Validate dumps | 243 // Validate dumps |
| 245 for (const std::string& line : lines) { | 244 for (const std::string& line : lines) { |
| 246 if (line.size() == 0) | 245 if (line.size() == 0) |
| 247 continue; | 246 continue; |
| 248 std::unique_ptr<base::Value> dump_info = DeserializeFromJson(line); | 247 std::unique_ptr<base::Value> dump_info = DeserializeFromJson(line); |
| 249 DumpInfo info(dump_info.get()); | 248 DumpInfo info(dump_info.get()); |
| 250 RCHECK(info.valid(), false); | 249 RCHECK(info.valid(), false); |
| 251 dumps->Append(std::move(dump_info)); | 250 dumps->Append(std::move(dump_info)); |
| 252 } | 251 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 275 | 274 |
| 276 if (WriteFile(lockfile_path_, lockfile.c_str(), lockfile.size()) < 0) { | 275 if (WriteFile(lockfile_path_, lockfile.c_str(), lockfile.size()) < 0) { |
| 277 return false; | 276 return false; |
| 278 } | 277 } |
| 279 | 278 |
| 280 return SerializeJsonToFile(metadata_path_, *metadata); | 279 return SerializeJsonToFile(metadata_path_, *metadata); |
| 281 } | 280 } |
| 282 | 281 |
| 283 bool SynchronizedMinidumpManager::InitializeFiles() { | 282 bool SynchronizedMinidumpManager::InitializeFiles() { |
| 284 std::unique_ptr<base::DictionaryValue> metadata = | 283 std::unique_ptr<base::DictionaryValue> metadata = |
| 285 base::WrapUnique(new base::DictionaryValue()); | 284 base::MakeUnique<base::DictionaryValue>(); |
| 286 | 285 |
| 287 base::DictionaryValue* ratelimit_fields = new base::DictionaryValue(); | 286 base::DictionaryValue* ratelimit_fields = new base::DictionaryValue(); |
| 288 metadata->Set(kLockfileRatelimitKey, base::WrapUnique(ratelimit_fields)); | 287 metadata->Set(kLockfileRatelimitKey, base::WrapUnique(ratelimit_fields)); |
| 289 ratelimit_fields->SetDouble(kLockfileRatelimitPeriodStartKey, 0.0); | 288 ratelimit_fields->SetDouble(kLockfileRatelimitPeriodStartKey, 0.0); |
| 290 ratelimit_fields->SetInteger(kLockfileRatelimitPeriodDumpsKey, 0); | 289 ratelimit_fields->SetInteger(kLockfileRatelimitPeriodDumpsKey, 0); |
| 291 | 290 |
| 292 std::unique_ptr<base::ListValue> dumps = | 291 std::unique_ptr<base::ListValue> dumps = base::MakeUnique<base::ListValue>(); |
| 293 base::WrapUnique(new base::ListValue()); | |
| 294 | 292 |
| 295 return WriteFiles(dumps.get(), metadata.get()); | 293 return WriteFiles(dumps.get(), metadata.get()); |
| 296 } | 294 } |
| 297 | 295 |
| 298 bool SynchronizedMinidumpManager::AddEntryToLockFile( | 296 bool SynchronizedMinidumpManager::AddEntryToLockFile( |
| 299 const DumpInfo& dump_info) { | 297 const DumpInfo& dump_info) { |
| 300 DCHECK_GE(lockfile_fd_, 0); | 298 DCHECK_GE(lockfile_fd_, 0); |
| 301 DCHECK(dumps_); | 299 DCHECK(dumps_); |
| 302 | 300 |
| 303 // Make sure dump_info is valid. | 301 // Make sure dump_info is valid. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 397 |
| 400 const base::FilePath file_path = dump_path_.Append(reader.name()); | 398 const base::FilePath file_path = dump_path_.Append(reader.name()); |
| 401 if (file_path != lockfile_path_ && file_path != metadata_path_) | 399 if (file_path != lockfile_path_ && file_path != metadata_path_) |
| 402 return true; | 400 return true; |
| 403 } | 401 } |
| 404 | 402 |
| 405 return false; | 403 return false; |
| 406 } | 404 } |
| 407 | 405 |
| 408 } // namespace chromecast | 406 } // namespace chromecast |
| OLD | NEW |