toolkit/crashreporter/CrashAnnotations.cpp
author owlishDeveloper <bugzeeeeee@gmail.com>
Thu, 23 Mar 2023 17:05:27 +0000
changeset 657741 75b3c6c4437624f59fcaff278bb8f5b88358e3a6
parent 617713 d8ba10a8bc4f056dac750fb899b284ea88c4e0a6
permissions -rw-r--r--
Bug 1806179 - Add tests for the cookie banner events API r=geckoview-reviewers,m_kato,amejiamarmol Differential Revision: https://phabricator.services.mozilla.com/D172854

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "CrashAnnotations.h"

#include <algorithm>
#include <cstring>
#include <iterator>

using std::begin;
using std::end;
using std::find_if;

namespace CrashReporter {

bool AnnotationFromString(Annotation& aResult, const char* aValue) {
  auto elem = find_if(
      begin(kAnnotationStrings), end(kAnnotationStrings),
      [&aValue](const char* aString) { return strcmp(aString, aValue) == 0; });

  if (elem == end(kAnnotationStrings)) {
    return false;
  }

  aResult = static_cast<Annotation>(elem - begin(kAnnotationStrings));
  return true;
}

bool IsAnnotationAllowlistedForPing(Annotation aAnnotation) {
  auto elem = find_if(
      begin(kCrashPingAllowlist), end(kCrashPingAllowlist),
      [&aAnnotation](Annotation aElement) { return aElement == aAnnotation; });

  return elem != end(kCrashPingAllowlist);
}

}  // namespace CrashReporter