Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: chromecast/crash/linux/crash_testing_utils.cc

Issue 1254113004: [Chromecast] Consolidate duplicated crash test functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fixed namespace footer comment Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromecast/crash/linux/crash_testing_utils.h"
6
7 #include "base/files/file_util.h"
8 #include "base/values.h"
9 #include "chromecast/base/serializers.h"
10 #include "chromecast/crash/linux/dump_info.h"
11
12 namespace chromecast {
13 namespace {
14
15 const char kDumpsKey[] = "dumps";
16
17 // Gets the list of deserialized DumpInfo given a deserialized |lockfile|.
18 base::ListValue* GetDumpList(base::Value* lockfile) {
19 base::DictionaryValue* dict;
20 base::ListValue* dump_list;
21 if (!lockfile || !lockfile->GetAsDictionary(&dict) ||
22 !dict->GetList(kDumpsKey, &dump_list)) {
23 return nullptr;
24 }
25
26 return dump_list;
27 }
28
29 } // namespcae
30
31 scoped_ptr<DumpInfo> CreateDumpInfo(const std::string& json_string) {
32 scoped_ptr<base::Value> value(DeserializeFromJson(json_string));
33 return make_scoped_ptr(new DumpInfo(value.get()));
34 }
35
36 bool FetchDumps(const std::string& lockfile_path,
37 ScopedVector<DumpInfo>* dumps) {
38 if (!dumps) {
39 return false;
40 }
41 dumps->clear();
42
43 base::FilePath path(lockfile_path);
44 scoped_ptr<base::Value> contents(DeserializeJsonFromFile(path));
45 base::ListValue* dump_list = GetDumpList(contents.get());
46 if (!dump_list) {
47 return false;
48 }
49
50 for (base::Value* elem : *dump_list) {
51 scoped_ptr<DumpInfo> dump = make_scoped_ptr(new DumpInfo(elem));
52 if (!dump->valid()) {
53 return false;
54 }
55 dumps->push_back(dump.Pass());
56 }
57
58 return true;
59 }
60
61 bool CreateLockFile(const std::string& lockfile_path) {
62 scoped_ptr<base::DictionaryValue> output =
63 make_scoped_ptr(new base::DictionaryValue());
64 output->Set(kDumpsKey, make_scoped_ptr(new base::ListValue()));
65
66 base::FilePath path(lockfile_path);
67
68 const base::Value* val = output.get();
69 return SerializeJsonToFile(path, *val);
70 }
71
72 bool AppendLockFile(const std::string& lockfile_path, const DumpInfo& dump) {
73 base::FilePath path(lockfile_path);
74
75 scoped_ptr<base::Value> contents(DeserializeJsonFromFile(path));
76 if (!contents) {
77 CreateLockFile(lockfile_path);
78 if (!(contents = DeserializeJsonFromFile(path))) {
79 return false;
80 }
81 }
82
83 base::ListValue* dump_list = GetDumpList(contents.get());
84 if (!dump_list) {
85 return false;
86 }
87
88 dump_list->Append(dump.GetAsValue());
89
90 return SerializeJsonToFile(path, *contents);
91 }
92
93 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/crash/linux/crash_testing_utils.h ('k') | chromecast/crash/linux/dump_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698