Chromium Code Reviews| Index: chromecast/crash/linux/crash_util.cc |
| diff --git a/chromecast/crash/linux/crash_util.cc b/chromecast/crash/linux/crash_util.cc |
| index e80b179c16e35d8f2292fd0892a9303563ac97a9..1ae8915e977f6b56b1d8b799ff4030acab617b87 100644 |
| --- a/chromecast/crash/linux/crash_util.cc |
| +++ b/chromecast/crash/linux/crash_util.cc |
| @@ -4,10 +4,10 @@ |
| #include "chromecast/crash/linux/crash_util.h" |
| -#include <stdlib.h> |
| - |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/threading/thread_restrictions.h" |
| #include "base/time/time.h" |
| #include "chromecast/base/path_utils.h" |
| #include "chromecast/base/version.h" |
| @@ -37,12 +37,13 @@ bool CrashUtil::RequestUploadCrashDump( |
| const std::string& existing_minidump_path, |
| const std::string& crashed_process_name, |
| uint64_t crashed_process_start_time_ms) { |
| + // Remove IO restrictions from this thread. Chromium IO functions must be used |
| + // to access the file system and upload information to the crash server. |
| + bool io_allowed = base::ThreadRestrictions::SetIOAllowed(true); |
|
wzhong
2015/07/16 21:08:20
const bool
slan
2015/07/16 22:39:18
Done.
|
| + |
| LOG(INFO) << "Request to upload crash dump " << existing_minidump_path |
| << " for process " << crashed_process_name; |
| - // Note: Do not use Chromium IO methods in this function. When cast_shell |
| - // crashes, this function can be called by any thread, which may not allow IO. |
| - // Use stdlib system calls for IO instead. |
| uint64_t uptime_ms = GetCurrentTimeMs() - crashed_process_start_time_ms; |
| MinidumpParams params(crashed_process_name, |
| uptime_ms, |
| @@ -68,10 +69,11 @@ bool CrashUtil::RequestUploadCrashDump( |
| writer->set_non_blocking(false); |
| success = (0 == writer->Write()); // error already logged. |
| - // In case the file is still in $TEMP, remove it. |
| - if (remove(existing_minidump_path.c_str()) < 0 && errno != ENOENT) { |
| + // In case the file is still in $TEMP, remove it. Note that DeleteFile() will |
| + // return true if |existing_minidump_path| has already been moved. |
| + if (!base::DeleteFile(base::FilePath(existing_minidump_path), false)) { |
| LOG(ERROR) << "Unable to delete temp minidump file " |
| - << existing_minidump_path << ": " << strerror(errno); |
| + << existing_minidump_path; |
| success = false; |
| } |
| @@ -79,6 +81,9 @@ bool CrashUtil::RequestUploadCrashDump( |
| LOG(INFO) << "Request to upload crash dump finished. " |
| << "Exit now if it is main process that crashed." << std::endl; |
| + // Restore the original IO restrictions on the thread, if there were any. |
| + base::ThreadRestrictions::SetIOAllowed(io_allowed); |
| + |
| return success; |
| } |