Skip to content

Commit

Permalink
Pass chrome schema to policy::BuildHandlerList()
Browse files Browse the repository at this point in the history
Chrome schema is necessary to be accessible in policy::BuildHandlerList() since some of the handlers will be migrated to a new policy handler based on schema(as defined in policy_templates.json).

This CL changed the signature of BuildHandlerList() and thus modification to constructor of BrowserPolicyConncector was made, taking callback to BuildHandlerList instead of the result returned by it, and postponed the generation of policy handler list. 

BUG=258339

Review URL: https://codereview.chromium.org/147033004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249126 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
binjin@chromium.org committed Feb 5, 2014
1 parent 5cd9ac1 commit 7fb9986
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion chrome/browser/policy/chrome_browser_policy_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <string>

#include "base/callback.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
Expand Down Expand Up @@ -130,7 +131,7 @@ class DeviceManagementServiceConfiguration
} // namespace

ChromeBrowserPolicyConnector::ChromeBrowserPolicyConnector()
: BrowserPolicyConnector(BuildHandlerList()) {
: BrowserPolicyConnector(base::Bind(&BuildHandlerList)) {
ConfigurationPolicyProvider* platform_provider = CreatePlatformProvider();
if (platform_provider)
SetPlatformPolicyProvider(make_scoped_ptr(platform_provider));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "components/policy/core/common/policy_details.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/policy/core/common/schema.h"
#include "components/translate/core/common/translate_pref_names.h"
#include "grit/component_strings.h"
#include "policy/policy_constants.h"
Expand Down Expand Up @@ -474,7 +475,8 @@ StringToIntEnumListPolicyHandler::MappingEntry kExtensionAllowedTypesMap[] = {

} // namespace

scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList() {
scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
const Schema& chrome_schema) {
scoped_ptr<ConfigurationPolicyHandlerList> handlers(
new ConfigurationPolicyHandlerList(base::Bind(&GetChromePolicyDetails)));
for (size_t i = 0; i < arraysize(kSimplePolicyMap); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
namespace policy {

class ConfigurationPolicyHandlerList;
class Schema;

// Builds a platform-specific handler list.
scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList();
scoped_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
const Schema& chrome_schema);

} // namespace policy

Expand Down
4 changes: 2 additions & 2 deletions components/policy/core/browser/browser_policy_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ bool MatchDomain(const base::string16& domain, const base::string16& pattern) {
} // namespace

BrowserPolicyConnector::BrowserPolicyConnector(
scoped_ptr<ConfigurationPolicyHandlerList> handler_list)
const HandlerListFactory& handler_list_factory)
: is_initialized_(false),
handler_list_(handler_list.Pass()),
platform_policy_provider_(NULL) {
// GetPolicyService() must be ready after the constructor is done.
// The connector is created very early during startup, when the browser
Expand All @@ -68,6 +67,7 @@ BrowserPolicyConnector::BrowserPolicyConnector(
// Initialize the SchemaRegistry with the Chrome schema before creating any
// of the policy providers in subclasses.
chrome_schema_ = Schema::Wrap(GetChromeSchemaData());
handler_list_ = handler_list_factory.Run(chrome_schema_);
schema_registry_.RegisterComponent(PolicyNamespace(POLICY_DOMAIN_CHROME, ""),
chrome_schema_);
}
Expand Down
2 changes: 1 addition & 1 deletion components/policy/core/browser/browser_policy_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class POLICY_EXPORT BrowserPolicyConnector {
// Builds an uninitialized BrowserPolicyConnector.
// Init() should be called to create and start the policy components.
explicit BrowserPolicyConnector(
scoped_ptr<ConfigurationPolicyHandlerList> handler_list);
const HandlerListFactory& handler_list_factory);

// Helper for the public Init() that must be called by subclasses.
void Init(PrefService* local_state,
Expand Down
5 changes: 2 additions & 3 deletions components/policy/core/browser/browser_policy_connector_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ namespace policy {
// Extends BrowserPolicyConnector with the setup for iOS builds.
class POLICY_EXPORT BrowserPolicyConnectorIOS : public BrowserPolicyConnector {
public:
BrowserPolicyConnectorIOS(
scoped_ptr<ConfigurationPolicyHandlerList> handler_list,
const std::string& user_agent);
BrowserPolicyConnectorIOS(const HandlerListFactory& handler_list_factory,
const std::string& user_agent);

virtual ~BrowserPolicyConnectorIOS();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ explicit DeviceManagementServiceConfiguration(const std::string& user_agent)
} // namespace

BrowserPolicyConnectorIOS::BrowserPolicyConnectorIOS(
scoped_ptr<ConfigurationPolicyHandlerList> handler_list,
const HandlerListFactory& handler_list_factory,
const std::string& user_agent)
: BrowserPolicyConnector(handler_list.Pass()),
: BrowserPolicyConnector(handler_list_factory),
user_agent_(user_agent) {}

BrowserPolicyConnectorIOS::~BrowserPolicyConnectorIOS() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ConfigurationPolicyHandler;
class PolicyErrorMap;
class PolicyMap;
struct PolicyToPreferenceMapEntry;
class Schema;

// Converts policies to their corresponding preferences by applying a list of
// ConfigurationPolicyHandler objects. This includes error checking and
Expand Down Expand Up @@ -51,6 +52,11 @@ class POLICY_EXPORT ConfigurationPolicyHandlerList {
DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandlerList);
};

// Callback with signature of BuildHandlerList(), to be used in constructor of
// BrowserPolicyConnector.
typedef base::Callback<scoped_ptr<ConfigurationPolicyHandlerList>(
const Schema&)> HandlerListFactory;

} // namespace policy

#endif // COMPONENTS_POLICY_CORE_BROWSER_CONFIGURATION_POLICY_HANDLER_LIST_H_

0 comments on commit 7fb9986

Please sign in to comment.