1 // Copyright (c) 2012 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.
5 #include "chrome/browser/extensions/management_policy.h"
11 void GetExtensionNameAndId(const Extension
* extension
,
14 // The extension may be NULL in testing.
15 *id
= extension
? extension
->id() : "[test]";
16 *name
= extension
? extension
->name() : "test";
21 ManagementPolicy::ManagementPolicy() {
24 ManagementPolicy::~ManagementPolicy() {
27 bool ManagementPolicy::Provider::UserMayLoad(const Extension
* extension
,
28 string16
* error
) const {
32 bool ManagementPolicy::Provider::UserMayModifySettings(
33 const Extension
* extension
, string16
* error
) const {
37 bool ManagementPolicy::Provider::MustRemainEnabled(const Extension
* extension
,
38 string16
* error
) const {
42 void ManagementPolicy::RegisterProvider(Provider
* provider
) {
43 providers_
.insert(provider
);
46 void ManagementPolicy::UnregisterProvider(Provider
* provider
) {
47 providers_
.erase(provider
);
50 bool ManagementPolicy::UserMayLoad(const Extension
* extension
,
51 string16
* error
) const {
52 return ApplyToProviderList(&Provider::UserMayLoad
, "Installation",
53 true, extension
, error
);
56 bool ManagementPolicy::UserMayModifySettings(const Extension
* extension
,
57 string16
* error
) const {
58 return ApplyToProviderList(&Provider::UserMayModifySettings
, "Modification",
59 true, extension
, error
);
62 bool ManagementPolicy::MustRemainEnabled(const Extension
* extension
,
63 string16
* error
) const {
64 return ApplyToProviderList(&Provider::MustRemainEnabled
, "Disabling",
65 false, extension
, error
);
68 void ManagementPolicy::UnregisterAllProviders() {
72 int ManagementPolicy::GetNumProviders() const {
73 return providers_
.size();
76 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function
,
77 const char* debug_operation_name
,
79 const Extension
* extension
,
80 string16
* error
) const {
81 for (ProviderList::const_iterator it
= providers_
.begin();
82 it
!= providers_
.end(); ++it
) {
83 const Provider
* provider
= *it
;
84 bool result
= (provider
->*function
)(extension
, error
);
85 if (result
!= normal_result
) {
88 GetExtensionNameAndId(extension
, &name
, &id
);
89 DVLOG(1) << debug_operation_name
<< " of extension " << name
91 << " prohibited by " << provider
->GetDebugPolicyProviderName();
92 return !normal_result
;
98 } // namespace extensions