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

Side by Side Diff: third_party/crashpad/crashpad/minidump/minidump_file_writer.cc

Issue 1911823002: Convert //third_party from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cacheinvalidation Created 4 years, 8 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
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_file_writer.h"
16
17 #include <utility> 15 #include <utility>
18 16
19 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/ptr_util.h"
20 #include "minidump/minidump_crashpad_info_writer.h" 19 #include "minidump/minidump_crashpad_info_writer.h"
21 #include "minidump/minidump_exception_writer.h" 20 #include "minidump/minidump_exception_writer.h"
21 #include "minidump/minidump_file_writer.h"
22 #include "minidump/minidump_handle_writer.h" 22 #include "minidump/minidump_handle_writer.h"
23 #include "minidump/minidump_memory_info_writer.h" 23 #include "minidump/minidump_memory_info_writer.h"
24 #include "minidump/minidump_memory_writer.h" 24 #include "minidump/minidump_memory_writer.h"
25 #include "minidump/minidump_misc_info_writer.h" 25 #include "minidump/minidump_misc_info_writer.h"
26 #include "minidump/minidump_module_writer.h" 26 #include "minidump/minidump_module_writer.h"
27 #include "minidump/minidump_system_info_writer.h" 27 #include "minidump/minidump_system_info_writer.h"
28 #include "minidump/minidump_thread_id_map.h" 28 #include "minidump/minidump_thread_id_map.h"
29 #include "minidump/minidump_thread_writer.h" 29 #include "minidump/minidump_thread_writer.h"
30 #include "minidump/minidump_unloaded_module_writer.h" 30 #include "minidump/minidump_unloaded_module_writer.h"
31 #include "minidump/minidump_user_stream_writer.h" 31 #include "minidump/minidump_user_stream_writer.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // This time is truncated to an integer number of seconds, not rounded, for 64 // This time is truncated to an integer number of seconds, not rounded, for
65 // compatibility with the truncation of process_snapshot->ProcessStartTime() 65 // compatibility with the truncation of process_snapshot->ProcessStartTime()
66 // done by MinidumpMiscInfoWriter::InitializeFromSnapshot(). Handling both 66 // done by MinidumpMiscInfoWriter::InitializeFromSnapshot(). Handling both
67 // timestamps in the same way allows the highest-fidelity computation of 67 // timestamps in the same way allows the highest-fidelity computation of
68 // process uptime as the difference between the two values. 68 // process uptime as the difference between the two values.
69 timeval snapshot_time; 69 timeval snapshot_time;
70 process_snapshot->SnapshotTime(&snapshot_time); 70 process_snapshot->SnapshotTime(&snapshot_time);
71 SetTimestamp(snapshot_time.tv_sec); 71 SetTimestamp(snapshot_time.tv_sec);
72 72
73 const SystemSnapshot* system_snapshot = process_snapshot->System(); 73 const SystemSnapshot* system_snapshot = process_snapshot->System();
74 auto system_info = make_scoped_ptr(new MinidumpSystemInfoWriter()); 74 auto system_info = base::WrapUnique(new MinidumpSystemInfoWriter());
75 system_info->InitializeFromSnapshot(system_snapshot); 75 system_info->InitializeFromSnapshot(system_snapshot);
76 AddStream(std::move(system_info)); 76 AddStream(std::move(system_info));
77 77
78 auto misc_info = make_scoped_ptr(new MinidumpMiscInfoWriter()); 78 auto misc_info = base::WrapUnique(new MinidumpMiscInfoWriter());
79 misc_info->InitializeFromSnapshot(process_snapshot); 79 misc_info->InitializeFromSnapshot(process_snapshot);
80 AddStream(std::move(misc_info)); 80 AddStream(std::move(misc_info));
81 81
82 auto memory_list = make_scoped_ptr(new MinidumpMemoryListWriter()); 82 auto memory_list = base::WrapUnique(new MinidumpMemoryListWriter());
83 auto thread_list = make_scoped_ptr(new MinidumpThreadListWriter()); 83 auto thread_list = base::WrapUnique(new MinidumpThreadListWriter());
84 thread_list->SetMemoryListWriter(memory_list.get()); 84 thread_list->SetMemoryListWriter(memory_list.get());
85 MinidumpThreadIDMap thread_id_map; 85 MinidumpThreadIDMap thread_id_map;
86 thread_list->InitializeFromSnapshot(process_snapshot->Threads(), 86 thread_list->InitializeFromSnapshot(process_snapshot->Threads(),
87 &thread_id_map); 87 &thread_id_map);
88 AddStream(std::move(thread_list)); 88 AddStream(std::move(thread_list));
89 89
90 const ExceptionSnapshot* exception_snapshot = process_snapshot->Exception(); 90 const ExceptionSnapshot* exception_snapshot = process_snapshot->Exception();
91 if (exception_snapshot) { 91 if (exception_snapshot) {
92 auto exception = make_scoped_ptr(new MinidumpExceptionWriter()); 92 auto exception = base::WrapUnique(new MinidumpExceptionWriter());
93 exception->InitializeFromSnapshot(exception_snapshot, thread_id_map); 93 exception->InitializeFromSnapshot(exception_snapshot, thread_id_map);
94 AddStream(std::move(exception)); 94 AddStream(std::move(exception));
95 } 95 }
96 96
97 auto module_list = make_scoped_ptr(new MinidumpModuleListWriter()); 97 auto module_list = base::WrapUnique(new MinidumpModuleListWriter());
98 module_list->InitializeFromSnapshot(process_snapshot->Modules()); 98 module_list->InitializeFromSnapshot(process_snapshot->Modules());
99 AddStream(std::move(module_list)); 99 AddStream(std::move(module_list));
100 100
101 for (const auto& module : process_snapshot->Modules()) { 101 for (const auto& module : process_snapshot->Modules()) {
102 for (const UserMinidumpStream* stream : module->CustomMinidumpStreams()) { 102 for (const UserMinidumpStream* stream : module->CustomMinidumpStreams()) {
103 auto user_stream = make_scoped_ptr(new MinidumpUserStreamWriter()); 103 auto user_stream = base::WrapUnique(new MinidumpUserStreamWriter());
104 user_stream->InitializeFromSnapshot(stream); 104 user_stream->InitializeFromSnapshot(stream);
105 AddStream(std::move(user_stream)); 105 AddStream(std::move(user_stream));
106 } 106 }
107 } 107 }
108 108
109 auto unloaded_modules = process_snapshot->UnloadedModules(); 109 auto unloaded_modules = process_snapshot->UnloadedModules();
110 if (!unloaded_modules.empty()) { 110 if (!unloaded_modules.empty()) {
111 auto unloaded_module_list = 111 auto unloaded_module_list =
112 make_scoped_ptr(new MinidumpUnloadedModuleListWriter()); 112 base::WrapUnique(new MinidumpUnloadedModuleListWriter());
113 unloaded_module_list->InitializeFromSnapshot(unloaded_modules); 113 unloaded_module_list->InitializeFromSnapshot(unloaded_modules);
114 AddStream(std::move(unloaded_module_list)); 114 AddStream(std::move(unloaded_module_list));
115 } 115 }
116 116
117 auto crashpad_info = make_scoped_ptr(new MinidumpCrashpadInfoWriter()); 117 auto crashpad_info = base::WrapUnique(new MinidumpCrashpadInfoWriter());
118 crashpad_info->InitializeFromSnapshot(process_snapshot); 118 crashpad_info->InitializeFromSnapshot(process_snapshot);
119 119
120 // Since the MinidumpCrashpadInfo stream is an extension, it’s safe to not add 120 // Since the MinidumpCrashpadInfo stream is an extension, it’s safe to not add
121 // it to the minidump file if it wouldn’t carry any useful information. 121 // it to the minidump file if it wouldn’t carry any useful information.
122 if (crashpad_info->IsUseful()) { 122 if (crashpad_info->IsUseful()) {
123 AddStream(std::move(crashpad_info)); 123 AddStream(std::move(crashpad_info));
124 } 124 }
125 125
126 std::vector<const MemoryMapRegionSnapshot*> memory_map_snapshot = 126 std::vector<const MemoryMapRegionSnapshot*> memory_map_snapshot =
127 process_snapshot->MemoryMap(); 127 process_snapshot->MemoryMap();
128 if (!memory_map_snapshot.empty()) { 128 if (!memory_map_snapshot.empty()) {
129 auto memory_info_list = make_scoped_ptr(new MinidumpMemoryInfoListWriter()); 129 auto memory_info_list =
130 base::WrapUnique(new MinidumpMemoryInfoListWriter());
130 memory_info_list->InitializeFromSnapshot(memory_map_snapshot); 131 memory_info_list->InitializeFromSnapshot(memory_map_snapshot);
131 AddStream(std::move(memory_info_list)); 132 AddStream(std::move(memory_info_list));
132 } 133 }
133 134
134 std::vector<HandleSnapshot> handles_snapshot = process_snapshot->Handles(); 135 std::vector<HandleSnapshot> handles_snapshot = process_snapshot->Handles();
135 if (!handles_snapshot.empty()) { 136 if (!handles_snapshot.empty()) {
136 auto handle_data_writer = make_scoped_ptr(new MinidumpHandleDataWriter()); 137 auto handle_data_writer = base::WrapUnique(new MinidumpHandleDataWriter());
137 handle_data_writer->InitializeFromSnapshot(handles_snapshot); 138 handle_data_writer->InitializeFromSnapshot(handles_snapshot);
138 AddStream(std::move(handle_data_writer)); 139 AddStream(std::move(handle_data_writer));
139 } 140 }
140 141
141 memory_list->AddFromSnapshot(process_snapshot->ExtraMemory()); 142 memory_list->AddFromSnapshot(process_snapshot->ExtraMemory());
142 if (exception_snapshot) 143 if (exception_snapshot)
143 memory_list->AddFromSnapshot(exception_snapshot->ExtraMemory()); 144 memory_list->AddFromSnapshot(exception_snapshot->ExtraMemory());
144 145
145 AddStream(std::move(memory_list)); 146 AddStream(std::move(memory_list));
146 } 147 }
147 148
148 void MinidumpFileWriter::SetTimestamp(time_t timestamp) { 149 void MinidumpFileWriter::SetTimestamp(time_t timestamp) {
149 DCHECK_EQ(state(), kStateMutable); 150 DCHECK_EQ(state(), kStateMutable);
150 151
151 internal::MinidumpWriterUtil::AssignTimeT(&header_.TimeDateStamp, timestamp); 152 internal::MinidumpWriterUtil::AssignTimeT(&header_.TimeDateStamp, timestamp);
152 } 153 }
153 154
154 void MinidumpFileWriter::AddStream( 155 void MinidumpFileWriter::AddStream(
155 scoped_ptr<internal::MinidumpStreamWriter> stream) { 156 std::unique_ptr<internal::MinidumpStreamWriter> stream) {
156 DCHECK_EQ(state(), kStateMutable); 157 DCHECK_EQ(state(), kStateMutable);
157 158
158 MinidumpStreamType stream_type = stream->StreamType(); 159 MinidumpStreamType stream_type = stream->StreamType();
159 160
160 auto rv = stream_types_.insert(stream_type); 161 auto rv = stream_types_.insert(stream_type);
161 CHECK(rv.second) << "stream_type " << stream_type << " already present"; 162 CHECK(rv.second) << "stream_type " << stream_type << " already present";
162 163
163 streams_.push_back(stream.release()); 164 streams_.push_back(stream.release());
164 165
165 DCHECK_EQ(streams_.size(), stream_types_.size()); 166 DCHECK_EQ(streams_.size(), stream_types_.size());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 for (internal::MinidumpStreamWriter* stream : streams_) { 264 for (internal::MinidumpStreamWriter* stream : streams_) {
264 iov.iov_base = stream->DirectoryListEntry(); 265 iov.iov_base = stream->DirectoryListEntry();
265 iov.iov_len = sizeof(MINIDUMP_DIRECTORY); 266 iov.iov_len = sizeof(MINIDUMP_DIRECTORY);
266 iovecs.push_back(iov); 267 iovecs.push_back(iov);
267 } 268 }
268 269
269 return file_writer->WriteIoVec(&iovecs); 270 return file_writer->WriteIoVec(&iovecs);
270 } 271 }
271 272
272 } // namespace crashpad 273 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698