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 <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <sys/file.h> | 13 #include <sys/file.h> |
14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <time.h> | 16 #include <time.h> |
17 #include <unistd.h> | 17 #include <unistd.h> |
| 18 |
18 #include <utility> | 19 #include <utility> |
19 | 20 |
20 #include "base/files/dir_reader_posix.h" | 21 #include "base/files/dir_reader_posix.h" |
21 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
22 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/memory/ptr_util.h" |
23 #include "base/strings/string_split.h" | 25 #include "base/strings/string_split.h" |
24 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
25 #include "chromecast/base/path_utils.h" | 27 #include "chromecast/base/path_utils.h" |
26 #include "chromecast/base/serializers.h" | 28 #include "chromecast/base/serializers.h" |
27 #include "chromecast/crash/linux/dump_info.h" | 29 #include "chromecast/crash/linux/dump_info.h" |
28 | 30 |
29 // if |cond| is false, returns |retval|. | 31 // if |cond| is false, returns |retval|. |
30 #define RCHECK(cond, retval) \ | 32 #define RCHECK(cond, retval) \ |
31 do { \ | 33 do { \ |
32 if (!(cond)) { \ | 34 if (!(cond)) { \ |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 DCHECK_GE(lockfile_fd_, 0); | 257 DCHECK_GE(lockfile_fd_, 0); |
256 DCHECK(!dumps_); | 258 DCHECK(!dumps_); |
257 DCHECK(!metadata_); | 259 DCHECK(!metadata_); |
258 | 260 |
259 std::string lockfile; | 261 std::string lockfile; |
260 RCHECK(ReadFileToString(base::FilePath(lockfile_path_), &lockfile), -1); | 262 RCHECK(ReadFileToString(base::FilePath(lockfile_path_), &lockfile), -1); |
261 | 263 |
262 std::vector<std::string> lines = base::SplitString( | 264 std::vector<std::string> lines = base::SplitString( |
263 lockfile, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 265 lockfile, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
264 | 266 |
265 scoped_ptr<base::ListValue> dumps = make_scoped_ptr(new base::ListValue()); | 267 std::unique_ptr<base::ListValue> dumps = |
| 268 base::WrapUnique(new base::ListValue()); |
266 | 269 |
267 // Validate dumps | 270 // Validate dumps |
268 for (const std::string& line : lines) { | 271 for (const std::string& line : lines) { |
269 if (line.size() == 0) | 272 if (line.size() == 0) |
270 continue; | 273 continue; |
271 scoped_ptr<base::Value> dump_info = DeserializeFromJson(line); | 274 std::unique_ptr<base::Value> dump_info = DeserializeFromJson(line); |
272 DumpInfo info(dump_info.get()); | 275 DumpInfo info(dump_info.get()); |
273 RCHECK(info.valid(), -1); | 276 RCHECK(info.valid(), -1); |
274 dumps->Append(std::move(dump_info)); | 277 dumps->Append(std::move(dump_info)); |
275 } | 278 } |
276 | 279 |
277 scoped_ptr<base::Value> metadata = | 280 std::unique_ptr<base::Value> metadata = |
278 DeserializeJsonFromFile(base::FilePath(metadata_path_)); | 281 DeserializeJsonFromFile(base::FilePath(metadata_path_)); |
279 RCHECK(ValidateMetadata(metadata.get()), -1); | 282 RCHECK(ValidateMetadata(metadata.get()), -1); |
280 | 283 |
281 dumps_ = std::move(dumps); | 284 dumps_ = std::move(dumps); |
282 metadata_ = std::move(metadata); | 285 metadata_ = std::move(metadata); |
283 return 0; | 286 return 0; |
284 } | 287 } |
285 | 288 |
286 int SynchronizedMinidumpManager::WriteFiles(const base::ListValue* dumps, | 289 int SynchronizedMinidumpManager::WriteFiles(const base::ListValue* dumps, |
287 const base::Value* metadata) { | 290 const base::Value* metadata) { |
288 DCHECK(dumps); | 291 DCHECK(dumps); |
289 DCHECK(metadata); | 292 DCHECK(metadata); |
290 std::string lockfile; | 293 std::string lockfile; |
291 | 294 |
292 for (const base::Value* elem : *dumps) { | 295 for (const base::Value* elem : *dumps) { |
293 scoped_ptr<std::string> dump_info = SerializeToJson(*elem); | 296 std::unique_ptr<std::string> dump_info = SerializeToJson(*elem); |
294 RCHECK(dump_info, -1); | 297 RCHECK(dump_info, -1); |
295 lockfile += *dump_info; | 298 lockfile += *dump_info; |
296 lockfile += "\n"; // Add line seperatators | 299 lockfile += "\n"; // Add line seperatators |
297 } | 300 } |
298 | 301 |
299 if (WriteFile(base::FilePath(lockfile_path_), | 302 if (WriteFile(base::FilePath(lockfile_path_), |
300 lockfile.c_str(), | 303 lockfile.c_str(), |
301 lockfile.size()) < 0) { | 304 lockfile.size()) < 0) { |
302 return -1; | 305 return -1; |
303 } | 306 } |
304 | 307 |
305 return SerializeJsonToFile(base::FilePath(metadata_path_), *metadata) ? 0 | 308 return SerializeJsonToFile(base::FilePath(metadata_path_), *metadata) ? 0 |
306 : -1; | 309 : -1; |
307 } | 310 } |
308 | 311 |
309 int SynchronizedMinidumpManager::InitializeFiles() { | 312 int SynchronizedMinidumpManager::InitializeFiles() { |
310 scoped_ptr<base::DictionaryValue> metadata = | 313 std::unique_ptr<base::DictionaryValue> metadata = |
311 make_scoped_ptr(new base::DictionaryValue()); | 314 base::WrapUnique(new base::DictionaryValue()); |
312 | 315 |
313 base::DictionaryValue* ratelimit_fields = new base::DictionaryValue(); | 316 base::DictionaryValue* ratelimit_fields = new base::DictionaryValue(); |
314 metadata->Set(kLockfileRatelimitKey, make_scoped_ptr(ratelimit_fields)); | 317 metadata->Set(kLockfileRatelimitKey, base::WrapUnique(ratelimit_fields)); |
315 ratelimit_fields->SetString(kLockfileRatelimitPeriodStartKey, "0"); | 318 ratelimit_fields->SetString(kLockfileRatelimitPeriodStartKey, "0"); |
316 ratelimit_fields->SetInteger(kLockfileRatelimitPeriodDumpsKey, 0); | 319 ratelimit_fields->SetInteger(kLockfileRatelimitPeriodDumpsKey, 0); |
317 | 320 |
318 scoped_ptr<base::ListValue> dumps = make_scoped_ptr(new base::ListValue()); | 321 std::unique_ptr<base::ListValue> dumps = |
| 322 base::WrapUnique(new base::ListValue()); |
319 | 323 |
320 return WriteFiles(dumps.get(), metadata.get()); | 324 return WriteFiles(dumps.get(), metadata.get()); |
321 } | 325 } |
322 | 326 |
323 int SynchronizedMinidumpManager::AddEntryToLockFile(const DumpInfo& dump_info) { | 327 int SynchronizedMinidumpManager::AddEntryToLockFile(const DumpInfo& dump_info) { |
324 DCHECK_LE(0, lockfile_fd_); | 328 DCHECK_LE(0, lockfile_fd_); |
325 DCHECK(dumps_); | 329 DCHECK(dumps_); |
326 | 330 |
327 // Make sure dump_info is valid. | 331 // Make sure dump_info is valid. |
328 if (!dump_info.valid()) { | 332 if (!dump_info.valid()) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 430 |
427 const std::string file_path = dump_path_.Append(reader.name()).value(); | 431 const std::string file_path = dump_path_.Append(reader.name()).value(); |
428 if (file_path != lockfile_path_ && file_path != metadata_path_) | 432 if (file_path != lockfile_path_ && file_path != metadata_path_) |
429 return true; | 433 return true; |
430 } | 434 } |
431 | 435 |
432 return false; | 436 return false; |
433 } | 437 } |
434 | 438 |
435 } // namespace chromecast | 439 } // namespace chromecast |
OLD | NEW |