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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PREVIOUS_SESSION_INFO_PREVIOUS_SESSION_INFO_H_
#define COMPONENTS_PREVIOUS_SESSION_INFO_PREVIOUS_SESSION_INFO_H_
#import <UIKit/UIKit.h>
#include "base/functional/callback_helpers.h"
#include "url/gurl.h"
namespace base {
class TimeDelta;
}
namespace previous_session_info_constants {
// - The (Integer) representing UIApplicationState.
extern NSString* const kPreviousSessionInfoApplicationState;
// Key in the UserDefaults for a boolean value keeping track of memory warnings.
extern NSString* const kDidSeeMemoryWarningShortlyBeforeTerminating;
// Key in the UserDefaults for a double value which stores OS start time.
extern NSString* const kOSStartTime;
// Key in the UserDefaults for a boolean describing whether or not the session
// restoration is in progress.
extern NSString* const kPreviousSessionInfoRestoringSession;
// Prefix key in the UserDefaults for a dictionary with session info params.
extern NSString* const kPreviousSessionInfoParamsPrefix;
// Key in the UserDefaults for the memory footprint of the browser process.
extern NSString* const kPreviousSessionInfoMemoryFootprint;
// Key in the UserDefaults for the number of open tabs.
extern NSString* const kPreviousSessionInfoTabCount;
// Key in the UserDefaults for the number of open inactive tabs.
extern NSString* const kPreviousSessionInfoInactiveTabCount;
// Key in the UserDefaults for the number of open "off the record" tabs.
extern NSString* const kPreviousSessionInfoOTRTabCount;
// The values of this enum are persisted (both to NSUserDefaults and logs) and
// represent the state of the last session (which may have been running a
// different version of the application).
// Therefore, entries should not be renumbered and numeric values should never
// be reused.
enum class DeviceThermalState {
kUnknown = 0,
kNominal = 1,
kFair = 2,
kSerious = 3,
kCritical = 4,
kMaxValue = kCritical,
};
// The values of this enum are persisted (both to NSUserDefaults and logs) and
// represent the state of the last session (which may have been running a
// different version of the application).
// Therefore, entries should not be renumbered and numeric values should never
// be reused.
enum class DeviceBatteryState {
kUnknown = 0,
kUnplugged = 1,
kCharging = 2,
// Battery is plugged into power and the battery is 100% charged.
kFull = 3,
kMaxValue = kFull,
};
} // namespace previous_session_info_constants
// PreviousSessionInfo has two jobs:
// - Holding information about the last session, persisted across restart.
// These informations are accessible via the properties on the shared
// instance.
// - Persist information about the current session, for use in a next session.
@interface PreviousSessionInfo : NSObject
// UIApplicationState at the end of the previous session or nil if state is
// unknown.
@property(nonatomic, assign, readonly) UIApplicationState* applicationState;
// The battery level of the device at the end of the previous session.
@property(nonatomic, assign, readonly) float deviceBatteryLevel;
// The battery state of the device at the end of the previous session.
@property(nonatomic, assign, readonly)
previous_session_info_constants::DeviceBatteryState deviceBatteryState;
// The storage available, in kilobytes, at the end of the previous session or -1
// if no previous session data is available.
@property(nonatomic, assign, readonly) NSInteger availableDeviceStorage;
// The thermal state of the device at the end of the previous session.
@property(nonatomic, assign, readonly)
previous_session_info_constants::DeviceThermalState deviceThermalState;
// Whether the app received a memory warning seconds before being terminated.
@property(nonatomic, assign, readonly)
BOOL didSeeMemoryWarningShortlyBeforeTerminating;
// Whether the app was updated between the previous and the current session.
@property(nonatomic, assign, readonly) BOOL isFirstSessionAfterUpgrade;
// Whether the language has been changed between the previous and the current
// session.
@property(nonatomic, assign, readonly) BOOL isFirstSessionAfterLanguageChange;
// Whether or not the OS was restarted between the previous and the current
// session.
@property(nonatomic, assign, readonly) BOOL OSRestartedAfterPreviousSession;
// The OS version during the previous session or nil if no previous session data
// is available.
@property(nonatomic, strong, readonly) NSString* OSVersion;
// The date time at which recording for the previous sesion has started. Note
// that recording usually starts soon after startup, but not exactly at the
// startup.
@property(nonatomic, strong, readonly) NSDate* sessionStartTime;
// The time at which the previous sesion ended. Note that this is only an
// estimate and is updated whenever another value of the receiver is updated.
@property(nonatomic, strong, readonly) NSDate* sessionEndTime;
// YES if the previous session was terminated during session restoration.
// Reset to NO after resetSessionRestorationFlag call.
@property(nonatomic, readonly) BOOL terminatedDuringSessionRestoration;
// Crash report parameters as key-value pairs.
@property(atomic, readonly)
NSDictionary<NSString*, NSString*>* reportParameters;
// Memory footprint in bytes of the browser process.
@property(nonatomic, readonly) NSInteger memoryFootprint;
// YES if ApplicationWillTerminate notification was posted for the previous
// session.
@property(nonatomic, readonly) BOOL applicationWillTerminateWasReceived;
// Number of open tabs in the previous session.
@property(nonatomic, readonly) NSInteger tabCount;
// Number of open inactive tabs in the previous session.
@property(nonatomic, readonly) NSInteger inactiveTabCount;
// Number of open "off the record" tabs in the previous session.
@property(nonatomic, readonly) NSInteger OTRTabCount;
// The breadcrumbs from the previous session.
@property(atomic, readonly) NSString* breadcrumbs;
// Number of warm starts in the previous session.
@property(nonatomic, readonly) NSInteger warmStartCount;
// Singleton PreviousSessionInfo. During the lifetime of the app, the returned
// object is the same, and describes the previous session, even after a new
// session has started (by calling beginRecordingCurrentSession).
+ (instancetype)sharedInstance;
// Clears the persisted information about the previous session and starts
// persisting information about the current session, for use in a next session.
- (void)beginRecordingCurrentSession;
// Start recording active field trials.
- (void)beginRecordingFieldTrials;
// Starts memory usage data recording with given |interval|.
- (void)startRecordingMemoryFootprintWithInterval:(base::TimeDelta)interval;
// Stops memory usage data recording. No-op if
// startRecordingMemoryFootprintWithInterval was no called.
- (void)stopRecordingMemoryFootprint;
// Updates the saved last known session time.
- (void)updateSessionEndTime;
// Updates the saved last known battery level of the device.
- (void)updateStoredBatteryLevel;
// Updates the saved last known battery state of the device.
- (void)updateStoredBatteryState;
// Updates the saved last known thermal state of the device.
- (void)updateStoredThermalState;
// When a session has begun, records that a memory warning was received.
- (void)setMemoryWarningFlag;
// When a session has begun, records that any memory warning flagged can be
// ignored.
- (void)resetMemoryWarningFlag;
// Increments the warm start count by one.
- (void)incrementWarmStartCount;
// Resets the warm start count to zero.
- (void)resetWarmStartCount;
// Must be called when Chrome starts session restoration. The returned closure
// runner will clear up the flag when destroyed. Can be used on different
// threads.
- (base::ScopedClosureRunner)startSessionRestoration;
// Must be called after reporting UTE metrics when app is started after UTE.
// Automatically called when ScopedClosureRunner returned from -startRestoration
// gets destructed.
- (void)resetSessionRestorationFlag;
// Records number of regular (non off the record and non inactive) tabs.
- (void)updateCurrentSessionTabCount:(NSInteger)count;
// Records number of inactive tabs.
- (void)updateCurrentSessionInactiveTabCount:(NSInteger)count;
// Records number of off the record tabs.
- (void)updateCurrentSessionOTRTabCount:(NSInteger)count;
// Records breadcrumbs from the previous session.
- (void)setBreadcrumbsLog:(NSString*)breadcrumbs;
// Records information crash report parameters.
- (void)setReportParameterValue:(NSString*)value forKey:(NSString*)key;
- (void)setReportParameterURL:(const GURL&)URL forKey:(NSString*)key;
- (void)removeReportParameterForKey:(NSString*)key;
@end
#endif // COMPONENTS_PREVIOUS_SESSION_INFO_PREVIOUS_SESSION_INFO_H_
|