Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Side by Side Diff: components/variations/service/ui_string_overrider.h

Issue 1363243004: Allow embedders to share code to override UI strings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment to test and class and fix typo Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
5 #ifndef COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
6 #define COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
7
8 #include "base/basictypes.h"
9 #include "base/macros.h"
10 #include "base/strings/string16.h"
11
12 namespace variations {
13
14 // Provides a mapping from hashes of generated resource names to their IDs. The
15 // mapping is provided by the embedder as two arrays |resource_hashes|, a sorted
16 // array of resource name hashes, and |resource_indices| an array of resource
17 // indices in the same order.
18 //
19 // The mapping is created by generate_resources_map.py based on generated
20 // resources header files. The script ensure that if one header file contains
21 // |#define IDS_FOO 12345| then for some index |i|, |resource_hashes[i]| will
22 // be equal to |HASH("IDS_FOO")| and |resource_indices[i]| will be equal to
23 // |12345|.
24 //
25 // Both array must have the same length |num_resources|. They are not owned by
26 // the UIStringOverrider and the embedder is responsible for their lifetime
27 // (usually by passing pointer to static data).
28 //
29 // This class is copy-constructible by design as it does not owns the array
30 // and only have reference to globally allocated constants.
31 class UIStringOverrider {
32 public:
33 UIStringOverrider();
34 UIStringOverrider(const uint32_t* resource_hashes,
35 const int* resource_indices,
36 size_t num_resources);
37 ~UIStringOverrider();
38
39 // Returns the resource index corresponding to the given hash or -1 if no
40 // resources is found. Visible for testing.
41 int GetResourceIndex(uint32_t hash);
42
43 // Overrides the string resource specified by |hash| with |string| in the
44 // resource bundle.
45 void OverrideUIString(uint32_t hash, const base::string16& string);
46
47 private:
48 const uint32_t* const resource_hashes_;
49 const int* const resource_indices_;
50 size_t const num_resources_;
51
52 DISALLOW_ASSIGN(UIStringOverrider);
53 };
54
55 } // namespace variations
56
57 #endif // COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
OLDNEW
« no previous file with comments | « components/variations/service/BUILD.gn ('k') | components/variations/service/ui_string_overrider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698