| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/breakpad/browser/crash_dump_manager_android.h" | 5 #include "components/breakpad/browser/crash_dump_manager_android.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 BrowserChildProcessObserver::Add(this); | 49 BrowserChildProcessObserver::Add(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 CrashDumpManager::~CrashDumpManager() { | 52 CrashDumpManager::~CrashDumpManager() { |
| 53 instance_ = NULL; | 53 instance_ = NULL; |
| 54 | 54 |
| 55 BrowserChildProcessObserver::Remove(this); | 55 BrowserChildProcessObserver::Remove(this); |
| 56 } | 56 } |
| 57 | 57 |
| 58 int CrashDumpManager::CreateMinidumpFile(int child_process_id) { | 58 base::File CrashDumpManager::CreateMinidumpFile(int child_process_id) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)); |
| 60 base::FilePath minidump_path; | 60 base::FilePath minidump_path; |
| 61 if (!base::CreateTemporaryFile(&minidump_path)) | 61 if (!base::CreateTemporaryFile(&minidump_path)) |
| 62 return base::kInvalidPlatformFileValue; | 62 return base::File(); |
| 63 | 63 |
| 64 base::PlatformFileError error; | |
| 65 // We need read permission as the minidump is generated in several phases | 64 // We need read permission as the minidump is generated in several phases |
| 66 // and needs to be read at some point. | 65 // and needs to be read at some point. |
| 67 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ | | 66 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | |
| 68 base::PLATFORM_FILE_WRITE; | 67 base::File::FLAG_WRITE; |
| 69 base::PlatformFile minidump_file = | 68 base::File minidump_file(minidump_path, flags); |
| 70 base::CreatePlatformFile(minidump_path, flags, NULL, &error); | 69 if (!minidump_file.IsValid()) { |
| 71 if (minidump_file == base::kInvalidPlatformFileValue) { | |
| 72 LOG(ERROR) << "Failed to create temporary file, crash won't be reported."; | 70 LOG(ERROR) << "Failed to create temporary file, crash won't be reported."; |
| 73 return base::kInvalidPlatformFileValue; | 71 return base::File(); |
| 74 } | 72 } |
| 75 | 73 |
| 76 { | 74 { |
| 77 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); | 75 base::AutoLock auto_lock(child_process_id_to_minidump_path_lock_); |
| 78 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); | 76 DCHECK(!ContainsKey(child_process_id_to_minidump_path_, child_process_id)); |
| 79 child_process_id_to_minidump_path_[child_process_id] = minidump_path; | 77 child_process_id_to_minidump_path_[child_process_id] = minidump_path; |
| 80 } | 78 } |
| 81 return minidump_file; | 79 return minidump_file.Pass(); |
| 82 } | 80 } |
| 83 | 81 |
| 84 // static | 82 // static |
| 85 void CrashDumpManager::ProcessMinidump(const base::FilePath& minidump_path, | 83 void CrashDumpManager::ProcessMinidump(const base::FilePath& minidump_path, |
| 86 base::ProcessHandle pid) { | 84 base::ProcessHandle pid) { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 88 int64 file_size = 0; | 86 int64 file_size = 0; |
| 89 int r = base::GetFileSize(minidump_path, &file_size); | 87 int r = base::GetFileSize(minidump_path, &file_size); |
| 90 DCHECK(r) << "Failed to retrieve size for minidump " | 88 DCHECK(r) << "Failed to retrieve size for minidump " |
| 91 << minidump_path.value(); | 89 << minidump_path.value(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 109 base::StringPrintf("chromium-renderer-minidump-%016" PRIx64 ".dmp%d", | 107 base::StringPrintf("chromium-renderer-minidump-%016" PRIx64 ".dmp%d", |
| 110 rand, pid); | 108 rand, pid); |
| 111 base::FilePath dest_path = instance_->crash_dump_dir_.Append(filename); | 109 base::FilePath dest_path = instance_->crash_dump_dir_.Append(filename); |
| 112 r = base::Move(minidump_path, dest_path); | 110 r = base::Move(minidump_path, dest_path); |
| 113 if (!r) { | 111 if (!r) { |
| 114 LOG(ERROR) << "Failed to move crash dump from " << minidump_path.value() | 112 LOG(ERROR) << "Failed to move crash dump from " << minidump_path.value() |
| 115 << " to " << dest_path.value(); | 113 << " to " << dest_path.value(); |
| 116 base::DeleteFile(minidump_path, false); | 114 base::DeleteFile(minidump_path, false); |
| 117 return; | 115 return; |
| 118 } | 116 } |
| 119 LOG(INFO) << "Crash minidump successfully generated: " << | 117 VLOG(1) << "Crash minidump successfully generated: " << |
| 120 instance_->crash_dump_dir_.Append(filename).value(); | 118 instance_->crash_dump_dir_.Append(filename).value(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 void CrashDumpManager::BrowserChildProcessHostDisconnected( | 121 void CrashDumpManager::BrowserChildProcessHostDisconnected( |
| 124 const content::ChildProcessData& data) { | 122 const content::ChildProcessData& data) { |
| 125 OnChildExit(data.id, data.handle); | 123 OnChildExit(data.id, data.handle); |
| 126 } | 124 } |
| 127 | 125 |
| 128 void CrashDumpManager::BrowserChildProcessCrashed( | 126 void CrashDumpManager::BrowserChildProcessCrashed( |
| 129 const content::ChildProcessData& data) { | 127 const content::ChildProcessData& data) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 162 } |
| 165 minidump_path = iter->second; | 163 minidump_path = iter->second; |
| 166 child_process_id_to_minidump_path_.erase(iter); | 164 child_process_id_to_minidump_path_.erase(iter); |
| 167 } | 165 } |
| 168 BrowserThread::PostTask( | 166 BrowserThread::PostTask( |
| 169 BrowserThread::FILE, FROM_HERE, | 167 BrowserThread::FILE, FROM_HERE, |
| 170 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); | 168 base::Bind(&CrashDumpManager::ProcessMinidump, minidump_path, pid)); |
| 171 } | 169 } |
| 172 | 170 |
| 173 } // namespace breakpad | 171 } // namespace breakpad |
| OLD | NEW |