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 for (ProviderList::const_iterator it
= providers_
.begin();
53 it
!= providers_
.end(); ++it
) {
54 if (!(*it
)->UserMayLoad(extension
, error
)) {
57 GetExtensionNameAndId(extension
, &name
, &id
);
58 DVLOG(1) << "Installation of extension " << name
60 << " prohibited by " << (*it
)->GetDebugPolicyProviderName();
67 bool ManagementPolicy::UserMayModifySettings(const Extension
* extension
,
68 string16
* error
) const {
69 for (ProviderList::const_iterator it
= providers_
.begin();
70 it
!= providers_
.end(); ++it
) {
71 if (!(*it
)->UserMayModifySettings(extension
, error
)) {
74 GetExtensionNameAndId(extension
, &name
, &id
);
75 DVLOG(1) << "Modification of extension " << name
77 << " prohibited by " << (*it
)->GetDebugPolicyProviderName();
84 bool ManagementPolicy::MustRemainEnabled(const Extension
* extension
,
85 string16
* error
) const {
86 for (ProviderList::const_iterator it
= providers_
.begin();
87 it
!= providers_
.end(); ++it
) {
88 if ((*it
)->MustRemainEnabled(extension
, error
)) {
91 GetExtensionNameAndId(extension
, &name
, &id
);
92 DVLOG(1) << "Extension " << name
94 << " required to remain enabled by "
95 << (*it
)->GetDebugPolicyProviderName();
102 void ManagementPolicy::UnregisterAllProviders() {
106 int ManagementPolicy::GetNumProviders() const {
107 return providers_
.size();
110 } // namespace extensions