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

Unified Diff: components/policy/core/browser/configuration_policy_handler.h

Issue 341723002: Refactored StringToIntEnumListPolicyHandler to be more general purpose (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/policy/core/browser/configuration_policy_handler.h
diff --git a/components/policy/core/browser/configuration_policy_handler.h b/components/policy/core/browser/configuration_policy_handler.h
index 54e77a257c456ec23281adbe658cd79becbbb0c8..60314b04dfe584363a4d48c8f7153facd14c1a32 100644
--- a/components/policy/core/browser/configuration_policy_handler.h
+++ b/components/policy/core/browser/configuration_policy_handler.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
@@ -159,20 +160,29 @@ class POLICY_EXPORT SimplePolicyHandler : public TypeCheckingPolicyHandler {
DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler);
};
-// A policy handler implementation that maps a string enum list to an int enum
-// list as specified by a mapping table.
-class POLICY_EXPORT StringToIntEnumListPolicyHandler
+// Base class that encapsulates logic for mapping from a string enum list
+// to a separate matching type value.
+class POLICY_EXPORT StringMappingListPolicyHandler
: public TypeCheckingPolicyHandler {
public:
- struct POLICY_EXPORT MappingEntry {
+ // Data structure representing the map between policy strings and
+ // matching pref values.
+ class POLICY_EXPORT MappingEntry {
+ public:
+ MappingEntry(const char* policy_value, scoped_ptr<base::Value> map);
+ ~MappingEntry();
+
const char* enum_value;
- int int_value;
+ scoped_ptr<base::Value> mapped_value;
};
- StringToIntEnumListPolicyHandler(const char* policy_name,
- const char* pref_path,
- const MappingEntry* mapping_begin,
- const MappingEntry* mapping_end);
+ // Callback that generates the map for this instance.
+ typedef base::Callback<void(ScopedVector<MappingEntry>*)> GenerateMapCallback;
+
+ StringMappingListPolicyHandler(const char* policy_name,
+ const char* pref_path,
+ const GenerateMapCallback& map_generator);
+ virtual ~StringMappingListPolicyHandler();
// ConfigurationPolicyHandler methods:
virtual bool CheckPolicySettings(const PolicyMap& policies,
@@ -187,14 +197,21 @@ class POLICY_EXPORT StringToIntEnumListPolicyHandler
base::ListValue* output,
PolicyErrorMap* errors);
+ // Helper method that converts from a policy value string to the associated
+ // pref value.
+ scoped_ptr<base::Value> Map(const std::string& entry_value);
+
// Name of the pref to write.
const char* pref_path_;
- // The mapping table.
- const MappingEntry* mapping_begin_;
- const MappingEntry* mapping_end_;
+ // The callback invoked to generate the map for this instance.
+ GenerateMapCallback map_getter_;
+
+ // Map of string policy values to local pref values. This is generated lazily
+ // so the generation does not have to happen if no policy is present.
+ ScopedVector<MappingEntry> map_;
- DISALLOW_COPY_AND_ASSIGN(StringToIntEnumListPolicyHandler);
+ DISALLOW_COPY_AND_ASSIGN(StringMappingListPolicyHandler);
};
// A policy handler implementation that ensures an int policy's value lies in an

Powered by Google App Engine
This is Rietveld 408576698