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

Side by Side Diff: ios/chrome/browser/metrics/ios_stability_metrics_provider.mm

Issue 1207353005: [iOS] Upstream some stability code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/metrics/ios_stability_metrics_provider.h"
6
7 #include <Foundation/Foundation.h>
8
9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "components/metrics/metrics_service.h"
12 #include "ios/chrome/browser/crash_report/breakpad_helper.h"
13 #import "ios/chrome/browser/crash_report/crash_report_background_uploader.h"
14 #import "ios/chrome/browser/metrics/previous_session_info.h"
15
16 namespace {
17
18 // Logs |type| in the shutdown type histogram.
19 void LogShutdownType(MobileSessionShutdownType type) {
20 UMA_STABILITY_HISTOGRAM_ENUMERATION("Stability.MobileSessionShutdownType",
21 type, MOBILE_SESSION_SHUTDOWN_TYPE_COUNT);
22 }
23
24 } // namespace
25
26 IOSStabilityMetricsProvider::IOSStabilityMetricsProvider(
27 metrics::MetricsService* metrics_service)
28 : metrics_service_(metrics_service) {
29 DCHECK(metrics_service_);
30 }
31
32 IOSStabilityMetricsProvider::~IOSStabilityMetricsProvider() {
33 }
34
35 bool IOSStabilityMetricsProvider::HasInitialStabilityMetrics() {
36 return true;
37 }
38
39 void IOSStabilityMetricsProvider::ProvideInitialStabilityMetrics(
40 metrics::SystemProfileProto* system_profile_proto) {
41 // If this is the first launch after an upgrade, existing crash reports
42 // may have been deleted before this code runs, so log this case in its
43 // own bucket.
44 if (IsFirstLaunchAfterUpgrade()) {
45 LogShutdownType(FIRST_LAUNCH_AFTER_UPGRADE);
46 return;
47 }
48
49 // If the last app lifetime did not end with a crash, then log it as a
50 // normal shutdown while in the background.
51 if (metrics_service_->WasLastShutdownClean()) {
52 LogShutdownType(SHUTDOWN_IN_BACKGROUND);
53 return;
54 }
55
56 // If the last app lifetime ended in a crash, log the type of crash.
57 MobileSessionShutdownType shutdown_type;
58 const bool with_crash_log =
59 HasUploadedCrashReportsInBackground() || HasCrashLogs();
60 if (ReceivedMemoryWarningBeforeLastShutdown()) {
61 if (with_crash_log) {
62 shutdown_type = SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_WITH_MEMORY_WARNING;
63 } else {
64 shutdown_type = SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_WITH_MEMORY_WARNING;
65 }
66 } else {
67 if (with_crash_log) {
68 shutdown_type = SHUTDOWN_IN_FOREGROUND_WITH_CRASH_LOG_NO_MEMORY_WARNING;
69 } else {
70 shutdown_type = SHUTDOWN_IN_FOREGROUND_NO_CRASH_LOG_NO_MEMORY_WARNING;
71 }
72 }
73 LogShutdownType(shutdown_type);
74 }
75
76 bool IOSStabilityMetricsProvider::IsFirstLaunchAfterUpgrade() {
77 return [[PreviousSessionInfo sharedInstance] isFirstSessionAfterUpgrade];
78 }
79
80 bool IOSStabilityMetricsProvider::HasCrashLogs() {
81 return breakpad_helper::HasReportToUpload();
82 }
83
84 bool IOSStabilityMetricsProvider::HasUploadedCrashReportsInBackground() {
85 return [CrashReportBackgroundUploader hasUploadedCrashReportsInBackground];
86 }
87
88 bool IOSStabilityMetricsProvider::ReceivedMemoryWarningBeforeLastShutdown() {
89 return [[PreviousSessionInfo
90 sharedInstance] didSeeMemoryWarningShortlyBeforeTerminating];
lpromero 2015/07/08 13:37:16 git cl format messed this one up.
91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698