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

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: Address comments by asvitkine 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/strings/string16.h"
10
11 namespace variations {
12
13 // Provides a mapping from hashes of generated reosurce names to their IDs. The
Alexei Svitkine (slow) 2015/09/28 15:01:46 Nit: resource
sdefresne 2015/09/28 16:53:55 Done.
14 // mapping is provided by the embedder as two arrays |resource_hashes|, a sorted
15 // array of resource name hashes, and |resource_indices| an array of resource
16 // indices in the same order.
17 //
18 // The mapping is created by generate_resources_map.py based on generated
19 // resources header files. The script ensure that if one header file contains
20 // |#define IDS_FOO 12345| then for some index |i|, |resource_hashes[i]| will
21 // be equal to |HASH("IDS_FOO")| and |resource_indices[i]| will be equal to
22 // |12345|.
23 //
24 // Both array must have the same length |num_resources|. They are not owned by
25 // the UIStringOverrider and the embedder is responsible for their lifetime
26 // (usually by passing pointer to static data).
27 class UIStringOverrider {
28 public:
29 UIStringOverrider();
30 UIStringOverrider(const uint32_t* resource_hashes,
31 const int* resource_indices,
32 size_t num_resources);
33 ~UIStringOverrider();
34
35 // Returns the resource index corresponding to the given hash or -1 if no
36 // resources is found. Visible for testing.
37 int GetResourceIndex(uint32_t hash);
38
39 // Overrides the string resource specified by |hash| with |string| in the
40 // resource bundle.
41 void OverrideUIString(uint32_t hash, const base::string16& string);
42
43 private:
44 const uint32_t* const resource_hashes_;
45 const int* const resource_indices_;
46 size_t const num_resources_;
47 };
Alexei Svitkine (slow) 2015/09/28 15:01:46 Please add a comment why there's now DISALLOW_ her
sdefresne 2015/09/28 16:53:56 Done.
48
49 } // namespace variations
50
51 #endif // COMPONENTS_VARIATIONS_SERVICE_UI_STRING_OVERRIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698