Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: chrome/browser/crash_upload_list/crash_upload_list_android.cc

Issue 2324983002: [Android] Wire up manual crash uploads. (Closed)
Patch Set: Write tests, and show forced uploads in chrome://crashes UI Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/android/context_utils.h"
8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h"
7 #include "base/files/file.h" 10 #include "base/files/file.h"
8 #include "base/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
9 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
10 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "jni/MinidumpUploadService_jni.h"
11 15
12 CrashUploadListAndroid::CrashUploadListAndroid( 16 CrashUploadListAndroid::CrashUploadListAndroid(
13 Delegate* delegate, 17 Delegate* delegate,
14 const base::FilePath& upload_log_path, 18 const base::FilePath& upload_log_path,
15 const scoped_refptr<base::SequencedWorkerPool>& worker_pool) 19 const scoped_refptr<base::SequencedWorkerPool>& worker_pool)
16 : CrashUploadList(delegate, upload_log_path, worker_pool) {} 20 : CrashUploadList(delegate, upload_log_path, worker_pool) {}
17 21
18 CrashUploadListAndroid::~CrashUploadListAndroid() {} 22 CrashUploadListAndroid::~CrashUploadListAndroid() {}
19 23
20 void CrashUploadListAndroid::LoadUploadList( 24 void CrashUploadListAndroid::LoadUploadList(
21 std::vector<UploadList::UploadInfo>* uploads) { 25 std::vector<UploadList::UploadInfo>* uploads) {
22 // This will load the list of successfully uploaded logs. 26 // This will load the list of successfully uploaded logs.
23 CrashUploadList::LoadUploadList(uploads); 27 CrashUploadList::LoadUploadList(uploads);
24 28
25 LoadUnsuccessfulUploadList(uploads); 29 LoadUnsuccessfulUploadList(uploads);
26 } 30 }
27 31
32 void CrashUploadListAndroid::RequestSingleCrashUpload(
33 const std::string& local_id) {
34 JNIEnv* env = base::android::AttachCurrentThread();
35 const base::android::JavaRef<jobject>& context =
36 base::android::GetApplicationContext();
37 base::android::ScopedJavaLocalRef<jstring> j_local_id =
38 base::android::ConvertUTF8ToJavaString(env, local_id);
39 Java_MinidumpUploadService_tryUploadCrashDumpWithLocalId(env, context,
40 j_local_id);
41 }
42
28 void CrashUploadListAndroid::LoadUnsuccessfulUploadList( 43 void CrashUploadListAndroid::LoadUnsuccessfulUploadList(
29 std::vector<UploadInfo>* uploads) { 44 std::vector<UploadInfo>* uploads) {
30 const char unsuccessful_uploads[] = ".dmp"; 45 const char unsuccessful_uploads[] = ".dmp";
31 const char skipped_uploads[] = ".skipped"; 46 const char skipped_uploads[] = ".skipped";
47 const char manually_forced_uploads[] = ".forced";
32 48
33 base::FileEnumerator files(upload_log_path().DirName(), false, 49 base::FileEnumerator files(upload_log_path().DirName(), false,
34 base::FileEnumerator::FILES); 50 base::FileEnumerator::FILES);
35 for (base::FilePath file = files.Next(); !file.empty(); file = files.Next()) { 51 for (base::FilePath file = files.Next(); !file.empty(); file = files.Next()) {
36 if (file.value().find(unsuccessful_uploads) == std::string::npos && 52 bool is_forced;
37 file.value().find(skipped_uploads) == std::string::npos) 53 if (file.value().find(manually_forced_uploads) != std::string::npos) {
Mark Mentovai 2016/09/15 00:02:30 base::EndsWith() from base/strings/string_util.h?
Ilya Sherman 2016/09/21 22:50:02 Acknowledged.
54 is_forced = true;
55 } else if (file.value().find(unsuccessful_uploads) != std::string::npos ||
56 file.value().find(skipped_uploads) != std::string::npos) {
57 is_forced = false;
58 } else {
38 continue; 59 continue;
Mark Mentovai 2016/09/15 00:02:29 What are these, no upload attempted yet? I guess t
Ilya Sherman 2016/09/21 22:50:02 There's various other junk in the directory, such
60 }
39 61
40 base::File::Info info; 62 base::File::Info info;
41 if (!base::GetFileInfo(file, &info)) 63 if (!base::GetFileInfo(file, &info))
42 continue; 64 continue;
43 65
44 // Crash reports can have multiple extensions (e.g. foo.dmp, foo.dmp.try1, 66 // Crash reports can have multiple extensions (e.g. foo.dmp, foo.dmp.try1,
45 // foo.skipped.try0). 67 // foo.skipped.try0).
46 file = file.BaseName(); 68 file = file.BaseName();
47 while (file != file.RemoveExtension()) 69 while (file != file.RemoveExtension())
48 file = file.RemoveExtension(); 70 file = file.RemoveExtension();
49 71
50 // ID is the last part of the file name. e.g. 72 // ID is the last part of the file name. e.g.
51 // chromium-renderer-minidump-f297dbcba7a2d0bb. 73 // chromium-renderer-minidump-f297dbcba7a2d0bb.
52 std::string id = file.value(); 74 std::string id = file.value();
53 std::size_t pos = id.find_last_of("-"); 75 std::size_t pos = id.find_last_of("-");
54 if (pos == std::string::npos) 76 if (pos == std::string::npos)
55 continue; 77 continue;
56 78
57 id = id.substr(pos + 1); 79 id = id.substr(pos + 1);
80 UploadList::UploadInfo::State upload_state =
81 is_forced ? UploadList::UploadInfo::State::Pending_UserRequested
82 : UploadList::UploadInfo::State::NotUploaded;
58 UploadList::UploadInfo upload(std::string(), base::Time(), id, 83 UploadList::UploadInfo upload(std::string(), base::Time(), id,
59 info.creation_time, 84 info.creation_time, upload_state);
60 UploadList::UploadInfo::State::NotUploaded);
61 uploads->push_back(upload); 85 uploads->push_back(upload);
62 } 86 }
63 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698