minidump: Use the crashpad::internal namespace more appropriately.

MinidumpLocationDescriptorListWriter and MinidumpRVAListWriter are
implementation details and should be in the crashpad::internal
namespace.

MinidumpUTF16StringListWriter and MinidumpUTF8StringListWriter are
accessible to outside code and should not be in this namespace.

TEST=minidump_test
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/699313007
This commit is contained in:
Mark Mentovai 2014-11-07 11:45:44 -05:00
parent 4a22225fc0
commit 9386a054e2
12 changed files with 54 additions and 63 deletions

View File

@ -19,6 +19,7 @@
#include "util/numeric/safe_assignment.h" #include "util/numeric/safe_assignment.h"
namespace crashpad { namespace crashpad {
namespace internal {
MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter() MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter()
: MinidumpWritable(), : MinidumpWritable(),
@ -31,7 +32,7 @@ MinidumpLocationDescriptorListWriter::~MinidumpLocationDescriptorListWriter() {
} }
void MinidumpLocationDescriptorListWriter::AddChild( void MinidumpLocationDescriptorListWriter::AddChild(
scoped_ptr<internal::MinidumpWritable> child) { scoped_ptr<MinidumpWritable> child) {
DCHECK_EQ(state(), kStateMutable); DCHECK_EQ(state(), kStateMutable);
children_.push_back(child.release()); children_.push_back(child.release());
@ -67,7 +68,7 @@ size_t MinidumpLocationDescriptorListWriter::SizeOfObject() {
children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR);
} }
std::vector<internal::MinidumpWritable*> std::vector<MinidumpWritable*>
MinidumpLocationDescriptorListWriter::Children() { MinidumpLocationDescriptorListWriter::Children() {
DCHECK_GE(state(), kStateFrozen); DCHECK_GE(state(), kStateFrozen);
@ -99,4 +100,5 @@ bool MinidumpLocationDescriptorListWriter::WriteObject(
return file_writer->WriteIoVec(&iovecs); return file_writer->WriteIoVec(&iovecs);
} }
} // namespace internal
} // namespace crashpad } // namespace crashpad

View File

@ -27,24 +27,24 @@
#include "util/stdlib/pointer_container.h" #include "util/stdlib/pointer_container.h"
namespace crashpad { namespace crashpad {
namespace internal {
//! \brief The writer for a MinidumpLocationDescriptorList object in a minidump //! \brief The writer for a MinidumpLocationDescriptorList object in a minidump
//! file, containing a list of MINIDUMP_LOCATION_DESCRIPTOR objects. //! file, containing a list of MINIDUMP_LOCATION_DESCRIPTOR objects.
class MinidumpLocationDescriptorListWriter : public internal::MinidumpWritable { class MinidumpLocationDescriptorListWriter : public MinidumpWritable {
protected: protected:
MinidumpLocationDescriptorListWriter(); MinidumpLocationDescriptorListWriter();
~MinidumpLocationDescriptorListWriter() override; ~MinidumpLocationDescriptorListWriter() override;
//! \brief Adds a MINIDUMP_LOCATION_DESCRIPTOR referencing an //! \brief Adds a MINIDUMP_LOCATION_DESCRIPTOR referencing a MinidumpWritable
//! internal::MinidumpWritable to the MinidumpLocationDescriptorList. //! to the MinidumpLocationDescriptorList.
//! //!
//! This object takes ownership of \a child and becomes its parent in the //! This object takes ownership of \a child and becomes its parent in the
//! overall tree of internal::MinidumpWritable objects. //! overall tree of MinidumpWritable objects.
//! //!
//! To provide type-correctness, subclasses are expected to provide a public //! To provide type-correctness, subclasses are expected to provide a public
//! method that accepts a `scoped_ptr`-wrapped argument of the proper //! method that accepts a `scoped_ptr`-wrapped argument of the proper
//! internal::MinidumpWritable subclass, and call this method with that //! MinidumpWritable subclass, and call this method with that argument.
//! argument.
//! //!
//! \note Valid in #kStateMutable. //! \note Valid in #kStateMutable.
void AddChild(scoped_ptr<MinidumpWritable> child); void AddChild(scoped_ptr<MinidumpWritable> child);
@ -77,6 +77,7 @@ class MinidumpLocationDescriptorListWriter : public internal::MinidumpWritable {
DISALLOW_COPY_AND_ASSIGN(MinidumpLocationDescriptorListWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpLocationDescriptorListWriter);
}; };
} // namespace internal
} // namespace crashpad } // namespace crashpad
#endif // CRASHPAD_MINIDUMP_LOCATION_DESCRIPTOR_LIST_WRITER_H_ #endif // CRASHPAD_MINIDUMP_LOCATION_DESCRIPTOR_LIST_WRITER_H_

View File

@ -25,7 +25,7 @@ namespace test {
namespace { namespace {
class TestMinidumpLocationDescriptorListWriter final class TestMinidumpLocationDescriptorListWriter final
: public MinidumpLocationDescriptorListWriter { : public internal::MinidumpLocationDescriptorListWriter {
public: public:
TestMinidumpLocationDescriptorListWriter() TestMinidumpLocationDescriptorListWriter()
: MinidumpLocationDescriptorListWriter() { : MinidumpLocationDescriptorListWriter() {

View File

@ -48,8 +48,7 @@ void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot(
} }
SetMinidumpModuleListIndex(module_list_index_u32); SetMinidumpModuleListIndex(module_list_index_u32);
auto list_annotations = auto list_annotations = make_scoped_ptr(new MinidumpUTF8StringListWriter());
make_scoped_ptr(new internal::MinidumpUTF8StringListWriter());
list_annotations->InitializeFromVector(module_snapshot->AnnotationsVector()); list_annotations->InitializeFromVector(module_snapshot->AnnotationsVector());
if (list_annotations->IsUseful()) { if (list_annotations->IsUseful()) {
SetListAnnotations(list_annotations.Pass()); SetListAnnotations(list_annotations.Pass());
@ -65,7 +64,7 @@ void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot(
} }
void MinidumpModuleCrashpadInfoWriter::SetListAnnotations( void MinidumpModuleCrashpadInfoWriter::SetListAnnotations(
scoped_ptr<internal::MinidumpUTF8StringListWriter> list_annotations) { scoped_ptr<MinidumpUTF8StringListWriter> list_annotations) {
DCHECK_EQ(state(), kStateMutable); DCHECK_EQ(state(), kStateMutable);
list_annotations_ = list_annotations.Pass(); list_annotations_ = list_annotations.Pass();

View File

@ -72,7 +72,7 @@ class MinidumpModuleCrashpadInfoWriter final
//! //!
//! \note Valid in #kStateMutable. //! \note Valid in #kStateMutable.
void SetListAnnotations( void SetListAnnotations(
scoped_ptr<internal::MinidumpUTF8StringListWriter> list_annotations); scoped_ptr<MinidumpUTF8StringListWriter> list_annotations);
//! \brief Arranges for MinidumpModuleCrashpadInfo::simple_annotations to //! \brief Arranges for MinidumpModuleCrashpadInfo::simple_annotations to
//! point to the MinidumpSimpleStringDictionaryWriter object to be written //! point to the MinidumpSimpleStringDictionaryWriter object to be written
@ -103,7 +103,7 @@ class MinidumpModuleCrashpadInfoWriter final
private: private:
MinidumpModuleCrashpadInfo module_; MinidumpModuleCrashpadInfo module_;
scoped_ptr<internal::MinidumpUTF8StringListWriter> list_annotations_; scoped_ptr<MinidumpUTF8StringListWriter> list_annotations_;
scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations_; scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations_;
DISALLOW_COPY_AND_ASSIGN(MinidumpModuleCrashpadInfoWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpModuleCrashpadInfoWriter);
@ -112,7 +112,7 @@ class MinidumpModuleCrashpadInfoWriter final
//! \brief The writer for a MinidumpModuleCrashpadInfoList object in a minidump //! \brief The writer for a MinidumpModuleCrashpadInfoList object in a minidump
//! file, containing a list of MinidumpModuleCrashpadInfo objects. //! file, containing a list of MinidumpModuleCrashpadInfo objects.
class MinidumpModuleCrashpadInfoListWriter final class MinidumpModuleCrashpadInfoListWriter final
: public MinidumpLocationDescriptorListWriter { : public internal::MinidumpLocationDescriptorListWriter {
public: public:
MinidumpModuleCrashpadInfoListWriter(); MinidumpModuleCrashpadInfoListWriter();
~MinidumpModuleCrashpadInfoListWriter() override; ~MinidumpModuleCrashpadInfoListWriter() override;

View File

@ -93,8 +93,7 @@ TEST(MinidumpModuleCrashpadInfoWriter, FullModule) {
auto module_writer = auto module_writer =
make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
module_writer->SetMinidumpModuleListIndex(kMinidumpModuleListIndex); module_writer->SetMinidumpModuleListIndex(kMinidumpModuleListIndex);
auto string_list_writer = auto string_list_writer = make_scoped_ptr(new MinidumpUTF8StringListWriter());
make_scoped_ptr(new internal::MinidumpUTF8StringListWriter());
string_list_writer->InitializeFromVector(vector); string_list_writer->InitializeFromVector(vector);
module_writer->SetListAnnotations(string_list_writer.Pass()); module_writer->SetListAnnotations(string_list_writer.Pass());
auto simple_string_dictionary_writer = auto simple_string_dictionary_writer =

View File

@ -19,6 +19,7 @@
#include "util/numeric/safe_assignment.h" #include "util/numeric/safe_assignment.h"
namespace crashpad { namespace crashpad {
namespace internal {
MinidumpRVAListWriter::MinidumpRVAListWriter() MinidumpRVAListWriter::MinidumpRVAListWriter()
: MinidumpWritable(), : MinidumpWritable(),
@ -30,8 +31,7 @@ MinidumpRVAListWriter::MinidumpRVAListWriter()
MinidumpRVAListWriter::~MinidumpRVAListWriter() { MinidumpRVAListWriter::~MinidumpRVAListWriter() {
} }
void MinidumpRVAListWriter::AddChild( void MinidumpRVAListWriter::AddChild(scoped_ptr<MinidumpWritable> child) {
scoped_ptr<internal::MinidumpWritable> child) {
DCHECK_EQ(state(), kStateMutable); DCHECK_EQ(state(), kStateMutable);
children_.push_back(child.release()); children_.push_back(child.release());
@ -65,7 +65,7 @@ size_t MinidumpRVAListWriter::SizeOfObject() {
return sizeof(rva_list_base_) + children_.size() * sizeof(RVA); return sizeof(rva_list_base_) + children_.size() * sizeof(RVA);
} }
std::vector<internal::MinidumpWritable*> MinidumpRVAListWriter::Children() { std::vector<MinidumpWritable*> MinidumpRVAListWriter::Children() {
DCHECK_GE(state(), kStateFrozen); DCHECK_GE(state(), kStateFrozen);
std::vector<MinidumpWritable*> children; std::vector<MinidumpWritable*> children;
@ -94,4 +94,5 @@ bool MinidumpRVAListWriter::WriteObject(FileWriterInterface* file_writer) {
return file_writer->WriteIoVec(&iovecs); return file_writer->WriteIoVec(&iovecs);
} }
} // namespace internal
} // namespace crashpad } // namespace crashpad

View File

@ -27,24 +27,24 @@
#include "util/stdlib/pointer_container.h" #include "util/stdlib/pointer_container.h"
namespace crashpad { namespace crashpad {
namespace internal {
//! \brief The writer for a MinidumpRVAList object in a minidump file, //! \brief The writer for a MinidumpRVAList object in a minidump file,
//! containing a list of ::RVA pointers. //! containing a list of ::RVA pointers.
class MinidumpRVAListWriter : public internal::MinidumpWritable { class MinidumpRVAListWriter : public MinidumpWritable {
protected: protected:
MinidumpRVAListWriter(); MinidumpRVAListWriter();
~MinidumpRVAListWriter() override; ~MinidumpRVAListWriter() override;
//! \brief Adds an ::RVA referencing an internal::MinidumpWritable to the //! \brief Adds an ::RVA referencing an MinidumpWritable to the
//! MinidumpRVAList. //! MinidumpRVAList.
//! //!
//! This object takes ownership of \a child and becomes its parent in the //! This object takes ownership of \a child and becomes its parent in the
//! overall tree of internal::MinidumpWritable objects. //! overall tree of MinidumpWritable objects.
//! //!
//! To provide type-correctness, subclasses are expected to provide a public //! To provide type-correctness, subclasses are expected to provide a public
//! method that accepts a `scoped_ptr`-wrapped argument of the proper //! method that accepts a `scoped_ptr`-wrapped argument of the proper
//! internal::MinidumpWritable subclass, and call this method with that //! MinidumpWritable subclass, and call this method with that argument.
//! argument.
//! //!
//! \note Valid in #kStateMutable. //! \note Valid in #kStateMutable.
void AddChild(scoped_ptr<MinidumpWritable> child); void AddChild(scoped_ptr<MinidumpWritable> child);
@ -73,6 +73,7 @@ class MinidumpRVAListWriter : public internal::MinidumpWritable {
DISALLOW_COPY_AND_ASSIGN(MinidumpRVAListWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpRVAListWriter);
}; };
} // namespace internal
} // namespace crashpad } // namespace crashpad
#endif // CRASHPAD_MINIDUMP_RVA_LIST_WRITER_H_ #endif // CRASHPAD_MINIDUMP_RVA_LIST_WRITER_H_

View File

@ -24,7 +24,7 @@ namespace crashpad {
namespace test { namespace test {
namespace { namespace {
class TestMinidumpRVAListWriter final : public MinidumpRVAListWriter { class TestMinidumpRVAListWriter final : public internal::MinidumpRVAListWriter {
public: public:
TestMinidumpRVAListWriter() : MinidumpRVAListWriter() {} TestMinidumpRVAListWriter() : MinidumpRVAListWriter() {}
~TestMinidumpRVAListWriter() override {} ~TestMinidumpRVAListWriter() override {}

View File

@ -95,17 +95,18 @@ void MinidumpUTF16StringWriter::SetUTF8(const std::string& string_utf8) {
MinidumpUTF8StringWriter::~MinidumpUTF8StringWriter() { MinidumpUTF8StringWriter::~MinidumpUTF8StringWriter() {
} }
template <typename Traits> template <typename MinidumpStringWriterType>
MinidumpStringListWriter<Traits>::MinidumpStringListWriter() MinidumpStringListWriter<MinidumpStringWriterType>::MinidumpStringListWriter()
: MinidumpRVAListWriter() { : MinidumpRVAListWriter() {
} }
template <typename Traits> template <typename MinidumpStringWriterType>
MinidumpStringListWriter<Traits>::~MinidumpStringListWriter() { MinidumpStringListWriter<
MinidumpStringWriterType>::~MinidumpStringListWriter() {
} }
template <typename Traits> template <typename MinidumpStringWriterType>
void MinidumpStringListWriter<Traits>::InitializeFromVector( void MinidumpStringListWriter<MinidumpStringWriterType>::InitializeFromVector(
const std::vector<std::string>& vector) { const std::vector<std::string>& vector) {
DCHECK_EQ(state(), kStateMutable); DCHECK_EQ(state(), kStateMutable);
DCHECK(IsEmpty()); DCHECK(IsEmpty());
@ -115,23 +116,23 @@ void MinidumpStringListWriter<Traits>::InitializeFromVector(
} }
} }
template <typename Traits> template <typename MinidumpStringWriterType>
void MinidumpStringListWriter<Traits>::AddStringUTF8( void MinidumpStringListWriter<MinidumpStringWriterType>::AddStringUTF8(
const std::string& string_utf8) { const std::string& string_utf8) {
auto string_writer = make_scoped_ptr(new MinidumpStringWriterType()); auto string_writer = make_scoped_ptr(new MinidumpStringWriterType());
string_writer->SetUTF8(string_utf8); string_writer->SetUTF8(string_utf8);
AddChild(string_writer.Pass()); AddChild(string_writer.Pass());
} }
template <typename Traits> template <typename MinidumpStringWriterType>
bool MinidumpStringListWriter<Traits>::IsUseful() const { bool MinidumpStringListWriter<MinidumpStringWriterType>::IsUseful() const {
return !IsEmpty(); return !IsEmpty();
} }
// Explicit template instantiation of the forms of MinidumpStringListWriter<> // Explicit template instantiation of the forms of MinidumpStringListWriter<>
// used as type aliases. // used as type aliases.
template class MinidumpStringListWriter<MinidumpStringListWriterUTF16Traits>; template class MinidumpStringListWriter<MinidumpUTF16StringWriter>;
template class MinidumpStringListWriter<MinidumpStringListWriterUTF8Traits>; template class MinidumpStringListWriter<MinidumpUTF8StringWriter>;
} // namespace internal } // namespace internal
} // namespace crashpad } // namespace crashpad

View File

@ -126,25 +126,11 @@ class MinidumpUTF8StringWriter final
DISALLOW_COPY_AND_ASSIGN(MinidumpUTF8StringWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpUTF8StringWriter);
}; };
//! \cond
struct MinidumpStringListWriterUTF16Traits {
using MinidumpStringWriterType = MinidumpUTF16StringWriter;
};
struct MinidumpStringListWriterUTF8Traits {
using MinidumpStringWriterType = MinidumpUTF8StringWriter;
};
//! \endcond
//! \brief The writer for a MinidumpRVAList object in a minidump file, //! \brief The writer for a MinidumpRVAList object in a minidump file,
//! containing a list of \a Traits::MinidumpStringWriterType objects. //! containing a list of \a MinidumpStringWriterType objects.
template <typename Traits> template <typename MinidumpStringWriterType>
class MinidumpStringListWriter : public MinidumpRVAListWriter { class MinidumpStringListWriter final : public MinidumpRVAListWriter {
public: public:
using MinidumpStringWriterType = typename Traits::MinidumpStringWriterType;
MinidumpStringListWriter(); MinidumpStringListWriter();
~MinidumpStringListWriter() override; ~MinidumpStringListWriter() override;
@ -165,7 +151,7 @@ class MinidumpStringListWriter : public MinidumpRVAListWriter {
//! //!
//! This object creates a new string writer with string value \a string_utf8, //! This object creates a new string writer with string value \a string_utf8,
//! takes ownership of it, and becomes its parent in the overall tree of //! takes ownership of it, and becomes its parent in the overall tree of
//! internal::MinidumpWritable objects. //! MinidumpWritable objects.
//! //!
//! \note Valid in #kStateMutable. //! \note Valid in #kStateMutable.
void AddStringUTF8(const std::string& string_utf8); void AddStringUTF8(const std::string& string_utf8);
@ -183,12 +169,13 @@ class MinidumpStringListWriter : public MinidumpRVAListWriter {
DISALLOW_COPY_AND_ASSIGN(MinidumpStringListWriter); DISALLOW_COPY_AND_ASSIGN(MinidumpStringListWriter);
}; };
using MinidumpUTF16StringListWriter =
MinidumpStringListWriter<MinidumpStringListWriterUTF16Traits>;
using MinidumpUTF8StringListWriter =
MinidumpStringListWriter<MinidumpStringListWriterUTF8Traits>;
} // namespace internal } // namespace internal
using MinidumpUTF16StringListWriter = internal::MinidumpStringListWriter<
internal::MinidumpUTF16StringWriter>;
using MinidumpUTF8StringListWriter = internal::MinidumpStringListWriter<
internal::MinidumpUTF8StringWriter>;
} // namespace crashpad } // namespace crashpad
#endif // CRASHPAD_MINIDUMP_MINIDUMP_STRING_WRITER_H_ #endif // CRASHPAD_MINIDUMP_MINIDUMP_STRING_WRITER_H_

View File

@ -198,7 +198,7 @@ TEST(MinidumpStringWriter, MinidumpUTF8StringWriter) {
} }
struct MinidumpUTF16StringListWriterTraits { struct MinidumpUTF16StringListWriterTraits {
using MinidumpStringListWriterType = internal::MinidumpUTF16StringListWriter; using MinidumpStringListWriterType = MinidumpUTF16StringListWriter;
static string16 ExpectationForUTF8(const std::string& utf8) { static string16 ExpectationForUTF8(const std::string& utf8) {
return base::UTF8ToUTF16(utf8); return base::UTF8ToUTF16(utf8);
} }
@ -208,7 +208,7 @@ struct MinidumpUTF16StringListWriterTraits {
}; };
struct MinidumpUTF8StringListWriterTraits { struct MinidumpUTF8StringListWriterTraits {
using MinidumpStringListWriterType = internal::MinidumpUTF8StringListWriter; using MinidumpStringListWriterType = MinidumpUTF8StringListWriter;
static std::string ExpectationForUTF8(const std::string& utf8) { static std::string ExpectationForUTF8(const std::string& utf8) {
return utf8; return utf8;
} }