Allow setting a new MinidumpDescriptor on ExceptionHandler, also expose directory from MinidumpDescriptor

R=digit at https://breakpad.appspot.com/452003/

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1037 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
ted.mielczarek@gmail.com 2012-09-17 14:01:10 +00:00
parent a8e7e18656
commit 54ede03227
4 changed files with 29 additions and 3 deletions

View file

@ -138,6 +138,10 @@ class ExceptionHandler {
return minidump_descriptor_;
}
void set_minidump_descriptor(const MinidumpDescriptor& descriptor) {
minidump_descriptor_ = descriptor;
}
void set_crash_handler(HandlerCallback callback) {
crash_handler_ = callback;
}

View file

@ -125,6 +125,10 @@ TEST(ExceptionHandlerTest, SimpleWithPath) {
AutoTempDir temp_dir;
ExceptionHandler handler(
MinidumpDescriptor(temp_dir.path()), NULL, NULL, NULL, true, -1);
EXPECT_EQ(temp_dir.path(), handler.minidump_descriptor().directory());
string temp_subdir = temp_dir.path() + "/subdir";
handler.set_minidump_descriptor(MinidumpDescriptor(temp_subdir));
EXPECT_EQ(temp_subdir, handler.minidump_descriptor().directory());
}
TEST(ExceptionHandlerTest, SimpleWithFD) {

View file

@ -45,6 +45,21 @@ MinidumpDescriptor::MinidumpDescriptor(const MinidumpDescriptor& descriptor)
assert(descriptor.path_.empty());
}
MinidumpDescriptor& MinidumpDescriptor::operator=(
const MinidumpDescriptor& descriptor) {
assert(descriptor.path_.empty());
fd_ = descriptor.fd_;
directory_ = descriptor.directory_;
path_.clear();
if (c_path_) {
// This descriptor already had a path set, so generate a new one.
c_path_ = NULL;
UpdatePath();
}
return *this;
}
void MinidumpDescriptor::UpdatePath() {
assert(fd_ == -1 && !directory_.empty());

View file

@ -45,7 +45,7 @@ class MinidumpDescriptor {
public:
MinidumpDescriptor() : fd_(-1) {}
explicit MinidumpDescriptor(const std::string& directory)
explicit MinidumpDescriptor(const string& directory)
: fd_(-1),
directory_(directory),
c_path_(NULL) {
@ -57,11 +57,14 @@ class MinidumpDescriptor {
}
explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor);
MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor);
bool IsFD() const { return fd_ != -1; }
int fd() const { return fd_; }
string directory() const { return directory_; }
const char* path() const { return c_path_; }
// Updates the path so it is unique.
@ -70,10 +73,10 @@ class MinidumpDescriptor {
private:
// The file descriptor where the minidump is generated.
const int fd_;
int fd_;
// The directory where the minidump should be generated.
const string directory_;
string directory_;
// The full path to the generated minidump.
string path_;
// The C string of |path_|. Precomputed so it can be access from a compromised