forked from mirrors/gecko-dev
		
	Covers adding the new JS global `GleanPings` for JS, the new structs for C++ at mozilla::glean_pings, ping-id and string-table-index codegen, the usual boilerplate for JS and C++ stuff, and tests. Unresolved: * What happens if we call this on a non-parent process? (This isn't a supported mode of operation) Differential Revision: https://phabricator.services.mozilla.com/D98671
		
			
				
	
	
		
			99 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
	
		
			3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
// -*- mode: C++ -*-
 | 
						|
 | 
						|
// AUTOGENERATED BY glean_parser.  DO NOT EDIT.
 | 
						|
 | 
						|
/* 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/. */
 | 
						|
 | 
						|
#ifndef mozilla_GleanJSPingsLookup_h
 | 
						|
#define mozilla_GleanJSPingsLookup_h
 | 
						|
 | 
						|
#define GLEAN_PING_INDEX_BITS (16)
 | 
						|
#define GLEAN_PING_ID(entry) ((entry) >> GLEAN_PING_INDEX_BITS)
 | 
						|
#define GLEAN_PING_INDEX(entry) ((entry) & ((1UL << GLEAN_PING_INDEX_BITS) - 1))
 | 
						|
 | 
						|
namespace mozilla::glean {
 | 
						|
 | 
						|
// Contains the ping id and the index into the ping string table.
 | 
						|
using ping_entry_t = uint32_t;
 | 
						|
 | 
						|
static Maybe<uint32_t> ping_result_check(const nsACString& aKey, ping_entry_t aEntry);
 | 
						|
 | 
						|
#if defined(_MSC_VER) && !defined(__clang__)
 | 
						|
const char gPingStringTable[] = {
 | 
						|
#else
 | 
						|
constexpr char gPingStringTable[] = {
 | 
						|
#endif
 | 
						|
  /*     0 - "notBaseline" */ 'n', 'o', 't', 'B', 'a', 's', 'e', 'l', 'i', 'n', 'e', '\0',
 | 
						|
  /*    12 - "notMetrics" */ 'n', 'o', 't', 'M', 'e', 't', 'r', 'i', 'c', 's', '\0',
 | 
						|
  /*    23 - "notEvents" */ 'n', 'o', 't', 'E', 'v', 'e', 'n', 't', 's', '\0',
 | 
						|
  /*    33 - "notDeletionRequest" */ 'n', 'o', 't', 'D', 'e', 'l', 'e', 't', 'i', 'o', 'n', 'R', 'e', 'q', 'u', 'e', 's', 't', '\0',
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
 | 
						|
const ping_entry_t sPingByNameLookupEntries[] = {
 | 
						|
  65536,
 | 
						|
  196631,
 | 
						|
  262177,
 | 
						|
  131084
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
 | 
						|
static Maybe<uint32_t>
 | 
						|
PingByNameLookup(const nsACString& aKey)
 | 
						|
{
 | 
						|
  static const uint8_t BASES[] = {
 | 
						|
       0,   0,   0,   0,   0,   0,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,
 | 
						|
       0,   0,   0,   0,   0,   2,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
 | 
						|
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   3,
 | 
						|
       0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
 | 
						|
  };
 | 
						|
  
 | 
						|
 | 
						|
  const char* bytes = aKey.BeginReading();
 | 
						|
  size_t length = aKey.Length();
 | 
						|
  auto& entry = mozilla::perfecthash::Lookup(bytes, length, BASES,
 | 
						|
                                             sPingByNameLookupEntries);
 | 
						|
  return ping_result_check(aKey, entry);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * Get a ping's name given its entry from the PHF.
 | 
						|
 */
 | 
						|
static const char* GetPingName(ping_entry_t aEntry) {
 | 
						|
  uint32_t idx = GLEAN_PING_INDEX(aEntry);
 | 
						|
  MOZ_ASSERT(idx < sizeof(gPingStringTable), "Ping index larger than string table");
 | 
						|
  return &gPingStringTable[idx];
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Check if the found entry is pointing at the correct ping.
 | 
						|
 * PHF can false-positive a result when the key isn't present, so we check
 | 
						|
 * for a string match. If it fails, return Nothing(). If we found it,
 | 
						|
 * return the ping's id.
 | 
						|
 */
 | 
						|
static Maybe<uint32_t> ping_result_check(const nsACString& aKey, ping_entry_t aEntry) {
 | 
						|
  uint32_t idx = GLEAN_PING_INDEX(aEntry);
 | 
						|
  uint32_t id = GLEAN_PING_ID(aEntry);
 | 
						|
 | 
						|
  if (MOZ_UNLIKELY(idx > sizeof(gPingStringTable))) {
 | 
						|
    return Nothing();
 | 
						|
  }
 | 
						|
 | 
						|
  if (aKey.EqualsASCII(&gPingStringTable[idx])) {
 | 
						|
    return Some(id);
 | 
						|
  }
 | 
						|
 | 
						|
  return Nothing();
 | 
						|
}
 | 
						|
 | 
						|
#undef GLEAN_PING_INDEX_BITS
 | 
						|
#undef GLEAN_PING_ID
 | 
						|
#undef GLEAN_PING_INDEX
 | 
						|
 | 
						|
}  // namespace mozilla::glean
 | 
						|
#endif  // mozilla_GleanJSPingsLookup_h
 |