-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apple client send and receive support for crash report cohort IDs (CR…
…CIDs) (#1116) Required: Task/Issue URL: https://app.asana.com/0/1208592102886666/1208759541597499/f iOS & macOS PRs: I’m looking for feedback on these BSK changes before posting app-level PRs What kind of version bump will this require?: Minor (is this right? 😊). CC: @LarryTurtis Optional: Tech Design URL: https://app.asana.com/0/1208592102886666/1208660326715650/f Description: DO NOT MERGE - this is a draft for input, not ready to go live yet. Before this is ready to merge: I’ll have to coordinate iOS and macOS changes to match, as the API signatures for the CrashCollection class have changed I will be waiting past the December 9 code freeze, so these changes are not included in the last public release of 2024, and instead have an extended internal testing period
- Loading branch information
Showing
5 changed files
with
309 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// CRCIDManager.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import Persistence | ||
import os.log | ||
|
||
/// Cohort identifier used exclusively to distinguish systemic crashes, only after the user opts in to send them. | ||
/// Its purpose is strictly limited to improving the reliability of crash reporting and is never used elsewhere. | ||
public class CRCIDManager { | ||
static let crcidKey = "CRCIDManager.crcidKey" | ||
var store: KeyValueStoring | ||
|
||
public init(store: KeyValueStoring = UserDefaults.standard) { | ||
self.store = store | ||
} | ||
|
||
public func handleCrashSenderResult(result: Result<Data?, Error>, response: HTTPURLResponse?) { | ||
switch result { | ||
case .success: | ||
Logger.general.debug("Crash Collection - Sending Crash Report: succeeded") | ||
if let receivedCRCID = response?.allHeaderFields[CrashReportSender.httpHeaderCRCID] as? String { | ||
if crcid != receivedCRCID { | ||
Logger.general.debug("Crash Collection - Received new value for CRCID: \(receivedCRCID), setting local crcid value") | ||
crcid = receivedCRCID | ||
} else { | ||
Logger.general.debug("Crash Collection - Received matching value for CRCID: \(receivedCRCID), no update necessary") | ||
} | ||
} else { | ||
Logger.general.debug("Crash Collection - No value for CRCID header: \(CRCIDManager.crcidKey), clearing local crcid value if present") | ||
crcid = "" | ||
} | ||
case .failure(let failure): | ||
Logger.general.debug("Crash Collection - Sending Crash Report: failed (\(failure))") | ||
} | ||
} | ||
|
||
public var crcid: String? { | ||
get { | ||
return self.store.object(forKey: CRCIDManager.crcidKey) as? String | ||
} | ||
|
||
set { | ||
store.set(newValue, forKey: CRCIDManager.crcidKey) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.