OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/crash_upload_list/crash_upload_list_android.h" | 5 #include "chrome/browser/crash_upload_list/crash_upload_list_android.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
| 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" |
| 11 #include "base/android/jni_string.h" |
9 #include "base/files/file.h" | 12 #include "base/files/file.h" |
10 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
11 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
12 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "jni/MinidumpUploadService_jni.h" |
13 #include "ui/base/text/bytes_formatting.h" | 17 #include "ui/base/text/bytes_formatting.h" |
14 | 18 |
15 CrashUploadListAndroid::CrashUploadListAndroid( | 19 CrashUploadListAndroid::CrashUploadListAndroid( |
16 Delegate* delegate, | 20 Delegate* delegate, |
17 const base::FilePath& upload_log_path, | 21 const base::FilePath& upload_log_path, |
18 scoped_refptr<base::TaskRunner> task_runner) | 22 scoped_refptr<base::TaskRunner> task_runner) |
19 : CrashUploadList(delegate, upload_log_path, std::move(task_runner)) {} | 23 : CrashUploadList(delegate, upload_log_path, std::move(task_runner)) {} |
20 | 24 |
21 CrashUploadListAndroid::~CrashUploadListAndroid() {} | 25 CrashUploadListAndroid::~CrashUploadListAndroid() {} |
22 | 26 |
23 void CrashUploadListAndroid::LoadUploadList( | 27 void CrashUploadListAndroid::LoadUploadList( |
24 std::vector<UploadList::UploadInfo>* uploads) { | 28 std::vector<UploadList::UploadInfo>* uploads) { |
25 // This will load the list of successfully uploaded logs. | 29 // This will load the list of successfully uploaded logs. |
26 CrashUploadList::LoadUploadList(uploads); | 30 CrashUploadList::LoadUploadList(uploads); |
27 | 31 |
28 LoadUnsuccessfulUploadList(uploads); | 32 LoadUnsuccessfulUploadList(uploads); |
29 } | 33 } |
30 | 34 |
| 35 void CrashUploadListAndroid::RequestSingleCrashUpload( |
| 36 const std::string& local_id) { |
| 37 JNIEnv* env = base::android::AttachCurrentThread(); |
| 38 const base::android::JavaRef<jobject>& context = |
| 39 base::android::GetApplicationContext(); |
| 40 base::android::ScopedJavaLocalRef<jstring> j_local_id = |
| 41 base::android::ConvertUTF8ToJavaString(env, local_id); |
| 42 Java_MinidumpUploadService_tryUploadCrashDumpWithLocalId(env, context, |
| 43 j_local_id); |
| 44 } |
| 45 |
31 void CrashUploadListAndroid::LoadUnsuccessfulUploadList( | 46 void CrashUploadListAndroid::LoadUnsuccessfulUploadList( |
32 std::vector<UploadInfo>* uploads) { | 47 std::vector<UploadInfo>* uploads) { |
33 const char unsuccessful_uploads[] = ".dmp"; | 48 const char pending_uploads[] = ".dmp"; |
34 const char skipped_uploads[] = ".skipped"; | 49 const char skipped_uploads[] = ".skipped"; |
| 50 const char manually_forced_uploads[] = ".forced"; |
35 | 51 |
36 base::FileEnumerator files(upload_log_path().DirName(), false, | 52 base::FileEnumerator files(upload_log_path().DirName(), false, |
37 base::FileEnumerator::FILES); | 53 base::FileEnumerator::FILES); |
38 for (base::FilePath file = files.Next(); !file.empty(); file = files.Next()) { | 54 for (base::FilePath file = files.Next(); !file.empty(); file = files.Next()) { |
39 if (file.value().find(unsuccessful_uploads) == std::string::npos && | 55 UploadList::UploadInfo::State upload_state; |
40 file.value().find(skipped_uploads) == std::string::npos) | 56 if (file.value().find(manually_forced_uploads) != std::string::npos) { |
| 57 upload_state = UploadList::UploadInfo::State::Pending_UserRequested; |
| 58 } else if (file.value().find(pending_uploads) != std::string::npos) { |
| 59 upload_state = UploadList::UploadInfo::State::Pending; |
| 60 } else if (file.value().find(skipped_uploads) != std::string::npos) { |
| 61 upload_state = UploadList::UploadInfo::State::NotUploaded; |
| 62 } else { |
| 63 // The |file| is something other than a minidump file, e.g. a logcat file. |
41 continue; | 64 continue; |
| 65 } |
42 | 66 |
43 base::File::Info info; | 67 base::File::Info info; |
44 if (!base::GetFileInfo(file, &info)) | 68 if (!base::GetFileInfo(file, &info)) |
45 continue; | 69 continue; |
46 | 70 |
47 int64_t file_size = 0; | 71 int64_t file_size = 0; |
48 if (!base::GetFileSize(file, &file_size)) | 72 if (!base::GetFileSize(file, &file_size)) |
49 continue; | 73 continue; |
50 | 74 |
51 // Crash reports can have multiple extensions (e.g. foo.dmp, foo.dmp.try1, | 75 // Crash reports can have multiple extensions (e.g. foo.dmp, foo.dmp.try1, |
52 // foo.skipped.try0). | 76 // foo.skipped.try0). |
53 file = file.BaseName(); | 77 file = file.BaseName(); |
54 while (file != file.RemoveExtension()) | 78 while (file != file.RemoveExtension()) |
55 file = file.RemoveExtension(); | 79 file = file.RemoveExtension(); |
56 | 80 |
57 // ID is the last part of the file name. e.g. | 81 // ID is the last part of the file name. e.g. |
58 // chromium-renderer-minidump-f297dbcba7a2d0bb. | 82 // chromium-renderer-minidump-f297dbcba7a2d0bb. |
59 std::string id = file.value(); | 83 std::string id = file.value(); |
60 std::size_t pos = id.find_last_of("-"); | 84 std::size_t pos = id.find_last_of("-"); |
61 if (pos == std::string::npos) | 85 if (pos == std::string::npos) |
62 continue; | 86 continue; |
63 | 87 |
64 id = id.substr(pos + 1); | 88 id = id.substr(pos + 1); |
65 UploadList::UploadInfo upload(id, info.creation_time, | 89 UploadList::UploadInfo upload(id, info.creation_time, upload_state, |
66 UploadList::UploadInfo::State::NotUploaded, | |
67 ui::FormatBytes(file_size)); | 90 ui::FormatBytes(file_size)); |
68 uploads->push_back(upload); | 91 uploads->push_back(upload); |
69 } | 92 } |
70 } | 93 } |
OLD | NEW |