ui_string_overrider.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
  5. #define COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. namespace variations {
  9. // Provides a mapping from hashes of generated resource names to their IDs. The
  10. // mapping is provided by the embedder as two arrays |resource_hashes|, a sorted
  11. // array of resource name hashes, and |resource_indices| an array of resource
  12. // indices in the same order.
  13. //
  14. // The mapping is created by generate_ui_string_overrider.py based on generated
  15. // resources header files. The script ensure that if one header file contains
  16. // |#define IDS_FOO 12345| then for some index |i|, |resource_hashes[i]| will
  17. // be equal to |HASH("IDS_FOO")| and |resource_indices[i]| will be equal to
  18. // |12345|.
  19. //
  20. // Both array must have the same length |num_resources|. They are not owned by
  21. // the UIStringOverrider and the embedder is responsible for their lifetime
  22. // (usually by passing pointer to static data).
  23. //
  24. // This class is copy-constructible by design as it does not owns the array
  25. // and only have reference to globally allocated constants.
  26. class UIStringOverrider {
  27. public:
  28. UIStringOverrider();
  29. UIStringOverrider(const uint32_t* resource_hashes,
  30. const int* resource_indices,
  31. size_t num_resources);
  32. UIStringOverrider& operator=(const UIStringOverrider&) = delete;
  33. ~UIStringOverrider();
  34. // Returns the resource index corresponding to the given hash or -1 if no
  35. // resources is found. Visible for testing.
  36. int GetResourceIndex(uint32_t hash);
  37. private:
  38. const uint32_t* const resource_hashes_;
  39. const int* const resource_indices_;
  40. size_t const num_resources_;
  41. };
  42. } // namespace variations
  43. #endif // COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_