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

Side by Side Diff: minidump/minidump_string_writer.cc

Issue 431363002: Introduce MinidumpStringWriter and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 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 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "minidump/minidump_string_writer.h"
16
17 #include "base/logging.h"
18 #include "minidump/minidump_writer_util.h"
19 #include "util/numeric/safe_assignment.h"
20
21 namespace crashpad {
22 namespace internal {
23
24 template <typename Traits>
25 MinidumpStringWriter<Traits>::MinidumpStringWriter()
26 : MinidumpWritable(), string_base_(), string_() {
27 }
28
29 template <typename Traits>
30 MinidumpStringWriter<Traits>::~MinidumpStringWriter() {
31 }
32
33 template <typename Traits>
34 bool MinidumpStringWriter<Traits>::Freeze() {
35 DCHECK_EQ(state(), kStateMutable);
36
37 if (!MinidumpWritable::Freeze()) {
Robert Sesek 2014/08/01 18:27:29 Not that it matters here, but I'd kind of expect t
Mark Mentovai 2014/08/01 18:33:58 rsesek wrote:
Robert Sesek 2014/08/01 18:41:52 Yeah, I figured it could go either way. I didn't k
38 return false;
39 }
40
41 size_t string_bytes = string_.size() * sizeof(string_[0]);
42 if (!AssignIfInRange(&string_base_.Length, string_bytes)) {
43 LOG(ERROR) << "string_bytes " << string_bytes << " out of range";
44 return false;
45 }
46
47 return true;
48 }
49
50 template <typename Traits>
51 size_t MinidumpStringWriter<Traits>::SizeOfObject() {
52 DCHECK_GE(state(), kStateFrozen);
53
54 // Include the NUL terminator.
55 return sizeof(string_base_) + (string_.size() + 1) * sizeof(string_[0]);
56 }
57
58 template <typename Traits>
59 bool MinidumpStringWriter<Traits>::WriteObject(
60 FileWriterInterface* file_writer) {
61 DCHECK_EQ(state(), kStateWritable);
62
63 WritableIoVec iov;
Robert Sesek 2014/08/01 18:27:29 I stared at this for a while and couldn't figure o
64 iov.iov_base = &string_base_;
65 iov.iov_len = sizeof(string_base_);
66 std::vector<WritableIoVec> iovecs(1, iov);
67
68 // Include the NUL terminator.
69 iov.iov_base = &string_[0];
70 iov.iov_len = (string_.size() + 1) * sizeof(string_[0]);
71 iovecs.push_back(iov);
72
73 return file_writer->WriteIoVec(&iovecs);
74 }
75
76 // Explicit template instantiation of the forms of MinidumpStringWriter<> used
77 // as base classes.
78 template class MinidumpStringWriter<MinidumpStringWriterUTF16Traits>;
79 template class MinidumpStringWriter<MinidumpStringWriterUTF8Traits>;
80
81 void MinidumpUTF16StringWriter::SetUTF8(const std::string& string_utf8) {
82 DCHECK_EQ(state(), kStateMutable);
83
84 set_string(MinidumpWriterUtil::ConvertUTF8ToUTF16(string_utf8));
85 }
86
87 } // namespace internal
88 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698