File: crash_upload_list_android.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (93 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/crash_upload_list/crash_upload_list_android.h"

#include <utility>

#include "base/android/context_utils.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/task_runner.h"
#include "jni/MinidumpUploadService_jni.h"
#include "ui/base/text/bytes_formatting.h"

CrashUploadListAndroid::CrashUploadListAndroid(
    Delegate* delegate,
    const base::FilePath& upload_log_path,
    scoped_refptr<base::TaskRunner> task_runner)
    : CrashUploadList(delegate, upload_log_path, std::move(task_runner)) {}

CrashUploadListAndroid::~CrashUploadListAndroid() {}

void CrashUploadListAndroid::LoadUploadList(
    std::vector<UploadList::UploadInfo>* uploads) {
  // This will load the list of successfully uploaded logs.
  CrashUploadList::LoadUploadList(uploads);

  LoadUnsuccessfulUploadList(uploads);
}

void CrashUploadListAndroid::RequestSingleCrashUpload(
    const std::string& local_id) {
  JNIEnv* env = base::android::AttachCurrentThread();
  const base::android::JavaRef<jobject>& context =
      base::android::GetApplicationContext();
  base::android::ScopedJavaLocalRef<jstring> j_local_id =
      base::android::ConvertUTF8ToJavaString(env, local_id);
  Java_MinidumpUploadService_tryUploadCrashDumpWithLocalId(env, context,
                                                           j_local_id);
}

void CrashUploadListAndroid::LoadUnsuccessfulUploadList(
    std::vector<UploadInfo>* uploads) {
  const char pending_uploads[] = ".dmp";
  const char skipped_uploads[] = ".skipped";
  const char manually_forced_uploads[] = ".forced";

  base::FileEnumerator files(upload_log_path().DirName(), false,
                             base::FileEnumerator::FILES);
  for (base::FilePath file = files.Next(); !file.empty(); file = files.Next()) {
    UploadList::UploadInfo::State upload_state;
    if (file.value().find(manually_forced_uploads) != std::string::npos) {
      upload_state = UploadList::UploadInfo::State::Pending_UserRequested;
    } else if (file.value().find(pending_uploads) != std::string::npos) {
      upload_state = UploadList::UploadInfo::State::Pending;
    } else if (file.value().find(skipped_uploads) != std::string::npos) {
      upload_state = UploadList::UploadInfo::State::NotUploaded;
    } else {
      // The |file| is something other than a minidump file, e.g. a logcat file.
      continue;
    }

    base::File::Info info;
    if (!base::GetFileInfo(file, &info))
      continue;

    int64_t file_size = 0;
    if (!base::GetFileSize(file, &file_size))
      continue;

    // Crash reports can have multiple extensions (e.g. foo.dmp, foo.dmp.try1,
    // foo.skipped.try0).
    file = file.BaseName();
    while (file != file.RemoveExtension())
      file = file.RemoveExtension();

    // ID is the last part of the file name. e.g.
    // chromium-renderer-minidump-f297dbcba7a2d0bb.
    std::string id = file.value();
    std::size_t pos = id.find_last_of("-");
    if (pos == std::string::npos)
      continue;

    id = id.substr(pos + 1);
    UploadList::UploadInfo upload(id, info.creation_time, upload_state,
                                  ui::FormatBytes(file_size));
    uploads->push_back(upload);
  }
}