Improve and optimize variations crash keys mechanism.
The previous mechanism would generate the variations crash keys from scratch
whenever a field trial became active, which would often be over 20 times
during startup. Generating the full list required a number of operations,
including SHA1-hashing each trial and group name and copying data between
several intermediate vectors.
This change optimizes this by keeping the intermediate results between
crash key updates, such that only the newly-activated trial needs to
have its strings hashed.
Additionally, cleans up some code, such as moving the responsibility of
monitoring active field trials for crash keys from several different
locations in the code base to the new variations_crash_keys.cc
implementation, thereby getting rid of ios::FieldTrialSynchronizer class.
Also fixes an oversight where synthetic trials were not set up on iOS.
This change clears the path for fixing crbug.com/309729, where a trial
that was just activated would not appear in crash reports, which I plan
to do in a follow-up CL. (This CL enables that by having a single place
that monitors field trials for crash keys, which I plan to convert to a
new API to fix that bug.)
Bug: 309729
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ibb6818600868f9f0e562d56858959516612ba55d
Reviewed-on: https://chromium-review.googlesource.com/947382
Reviewed-by: Ilya Sherman <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Robert Sesek <[email protected]>
Reviewed-by: Rohit Rao <[email protected]>
Commit-Queue: Alexei Svitkine <[email protected]>
Cr-Commit-Position: refs/heads/master@{#542026}
diff --git a/components/variations/variations_crash_keys.h b/components/variations/variations_crash_keys.h
new file mode 100644
index 0000000..499acd8
--- /dev/null
+++ b/components/variations/variations_crash_keys.h
@@ -0,0 +1,31 @@
+// Copyright 2018 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.
+
+#ifndef COMPONENTS_VARIATIONS_VARIATIONS_CRASH_KEYS_H_
+#define COMPONENTS_VARIATIONS_VARIATIONS_CRASH_KEYS_H_
+
+#include <vector>
+
+namespace variations {
+
+struct SyntheticTrialGroup;
+
+// Initializes crash keys that report the current set of active FieldTrial
+// groups (aka variations) for crash reports. After initialization, an observer
+// will be registered on FieldTrialList that will keep the crash keys up-to-date
+// with newly-activated trials. Synthetic trials must be manually updated using
+// the API below.
+void InitCrashKeys();
+
+// Updates variations crash keys by replacing the list of synthetic trials with
+// the specified list. Does not affect non-synthetic trials.
+void UpdateCrashKeysWithSyntheticTrials(
+ const std::vector<SyntheticTrialGroup>& synthetic_trials);
+
+// Clears the internal instance, for testing.
+void ClearCrashKeysInstanceForTesting();
+
+} // namespace variations
+
+#endif // COMPONENTS_VARIATIONS_VARIATIONS_CRASH_KEYS_H_