cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / metrics / ios_stability_metrics_provider.mm
blobcc1af0be6c364d41ee19695630f379f62a5b78ab
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.
5 #include "ios/chrome/browser/metrics/ios_stability_metrics_provider.h"
7 #include <Foundation/Foundation.h>
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"
16 namespace {
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);
24 }  // namespace
26 IOSStabilityMetricsProvider::IOSStabilityMetricsProvider(
27     metrics::MetricsService* metrics_service)
28     : metrics_service_(metrics_service) {
29   DCHECK(metrics_service_);
32 IOSStabilityMetricsProvider::~IOSStabilityMetricsProvider() {
35 bool IOSStabilityMetricsProvider::HasInitialStabilityMetrics() {
36   return true;
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   }
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   }
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);
76 bool IOSStabilityMetricsProvider::IsFirstLaunchAfterUpgrade() {
77   return [[PreviousSessionInfo sharedInstance] isFirstSessionAfterUpgrade];
80 bool IOSStabilityMetricsProvider::HasCrashLogs() {
81   return breakpad_helper::HasReportToUpload();
84 bool IOSStabilityMetricsProvider::HasUploadedCrashReportsInBackground() {
85   return [CrashReportBackgroundUploader hasUploadedCrashReportsInBackground];
88 bool IOSStabilityMetricsProvider::ReceivedMemoryWarningBeforeLastShutdown() {
89   return [[PreviousSessionInfo sharedInstance]
90       didSeeMemoryWarningShortlyBeforeTerminating];