Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_location_descriptor_list_writer.h" | 15 #include "minidump/minidump_location_descriptor_list_writer.h" |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "util/file/file_writer.h" | 18 #include "util/file/file_writer.h" |
| 19 #include "util/numeric/safe_assignment.h" | 19 #include "util/numeric/safe_assignment.h" |
| 20 | 20 |
| 21 namespace crashpad { | 21 namespace crashpad { |
| 22 namespace internal { | 22 namespace internal { |
| 23 | 23 |
| 24 MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter() | 24 MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter() |
| 25 : MinidumpWritable(), | 25 : MinidumpWritable(), |
| 26 location_descriptor_list_base_(), | 26 location_descriptor_list_base_(new MinidumpLocationDescriptorList()), |
| 27 children_(), | 27 children_(), |
| 28 child_location_descriptors_() { | 28 child_location_descriptors_() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 MinidumpLocationDescriptorListWriter::~MinidumpLocationDescriptorListWriter() { | 31 MinidumpLocationDescriptorListWriter::~MinidumpLocationDescriptorListWriter() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 void MinidumpLocationDescriptorListWriter::AddChild( | 34 void MinidumpLocationDescriptorListWriter::AddChild( |
| 35 scoped_ptr<MinidumpWritable> child) { | 35 scoped_ptr<MinidumpWritable> child) { |
| 36 DCHECK_EQ(state(), kStateMutable); | 36 DCHECK_EQ(state(), kStateMutable); |
| 37 | 37 |
| 38 children_.push_back(child.release()); | 38 children_.push_back(child.release()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool MinidumpLocationDescriptorListWriter::Freeze() { | 41 bool MinidumpLocationDescriptorListWriter::Freeze() { |
| 42 DCHECK_EQ(state(), kStateMutable); | 42 DCHECK_EQ(state(), kStateMutable); |
| 43 DCHECK(child_location_descriptors_.empty()); | 43 DCHECK(child_location_descriptors_.empty()); |
| 44 | 44 |
| 45 if (!MinidumpWritable::Freeze()) { | 45 if (!MinidumpWritable::Freeze()) { |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 size_t child_count = children_.size(); | 49 size_t child_count = children_.size(); |
| 50 if (!AssignIfInRange(&location_descriptor_list_base_.count, child_count)) { | 50 if (!AssignIfInRange(&location_descriptor_list_base_->count, |
| 51 child_count)) { | |
| 51 LOG(ERROR) << "child_count " << child_count << " out of range"; | 52 LOG(ERROR) << "child_count " << child_count << " out of range"; |
| 52 return false; | 53 return false; |
| 53 } | 54 } |
| 54 | 55 |
| 55 child_location_descriptors_.resize(child_count); | 56 child_location_descriptors_.resize(child_count); |
| 56 for (size_t index = 0; index < child_count; ++index) { | 57 for (size_t index = 0; index < child_count; ++index) { |
| 57 children_[index]->RegisterLocationDescriptor( | 58 children_[index]->RegisterLocationDescriptor( |
| 58 &child_location_descriptors_[index]); | 59 &child_location_descriptors_[index]); |
| 59 } | 60 } |
| 60 | 61 |
| 61 return true; | 62 return true; |
| 62 } | 63 } |
| 63 | 64 |
| 64 size_t MinidumpLocationDescriptorListWriter::SizeOfObject() { | 65 size_t MinidumpLocationDescriptorListWriter::SizeOfObject() { |
| 65 DCHECK_GE(state(), kStateFrozen); | 66 DCHECK_GE(state(), kStateFrozen); |
| 66 | 67 |
| 67 return sizeof(location_descriptor_list_base_) + | 68 return sizeof(*location_descriptor_list_base_) + |
| 68 children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | 69 children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::vector<MinidumpWritable*> | 72 std::vector<MinidumpWritable*> |
| 72 MinidumpLocationDescriptorListWriter::Children() { | 73 MinidumpLocationDescriptorListWriter::Children() { |
| 73 DCHECK_GE(state(), kStateFrozen); | 74 DCHECK_GE(state(), kStateFrozen); |
| 74 | 75 |
| 75 std::vector<MinidumpWritable*> children; | 76 std::vector<MinidumpWritable*> children; |
| 76 for (MinidumpWritable* child : children_) { | 77 for (MinidumpWritable* child : children_) { |
| 77 children.push_back(child); | 78 children.push_back(child); |
| 78 } | 79 } |
| 79 | 80 |
| 80 return children; | 81 return children; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool MinidumpLocationDescriptorListWriter::WriteObject( | 84 bool MinidumpLocationDescriptorListWriter::WriteObject( |
| 84 FileWriterInterface* file_writer) { | 85 FileWriterInterface* file_writer) { |
| 85 DCHECK_EQ(state(), kStateWritable); | 86 DCHECK_EQ(state(), kStateWritable); |
| 86 DCHECK_EQ(children_.size(), child_location_descriptors_.size()); | 87 DCHECK_EQ(children_.size(), child_location_descriptors_.size()); |
| 87 | 88 |
| 88 WritableIoVec iov; | 89 WritableIoVec iov; |
| 89 iov.iov_base = &location_descriptor_list_base_; | 90 iov.iov_base = location_descriptor_list_base_.get(); |
| 90 iov.iov_len = sizeof(location_descriptor_list_base_); | 91 iov.iov_len = sizeof(*location_descriptor_list_base_.get()); |
|
Mark Mentovai
2015/02/04 21:25:15
.get() wasn’t needed on line 68, is it really need
scottmg
2015/02/05 01:33:26
Done.
| |
| 91 std::vector<WritableIoVec> iovecs(1, iov); | 92 std::vector<WritableIoVec> iovecs(1, iov); |
| 92 | 93 |
| 93 if (!child_location_descriptors_.empty()) { | 94 if (!child_location_descriptors_.empty()) { |
| 94 iov.iov_base = &child_location_descriptors_[0]; | 95 iov.iov_base = &child_location_descriptors_[0]; |
| 95 iov.iov_len = child_location_descriptors_.size() * | 96 iov.iov_len = child_location_descriptors_.size() * |
| 96 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | 97 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); |
| 97 iovecs.push_back(iov); | 98 iovecs.push_back(iov); |
| 98 } | 99 } |
| 99 | 100 |
| 100 return file_writer->WriteIoVec(&iovecs); | 101 return file_writer->WriteIoVec(&iovecs); |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace internal | 104 } // namespace internal |
| 104 } // namespace crashpad | 105 } // namespace crashpad |
| OLD | NEW |