1 // Copyright 2013 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 "extensions/browser/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 base::string16
* error
) const {
32 bool ManagementPolicy::Provider::UserMayModifySettings(
33 const Extension
* extension
, base::string16
* error
) const {
37 bool ManagementPolicy::Provider::MustRemainEnabled(const Extension
* extension
,
38 base::string16
* error
)
43 bool ManagementPolicy::Provider::MustRemainDisabled(
44 const Extension
* extension
,
45 Extension::DisableReason
* reason
,
46 base::string16
* error
) const {
50 void ManagementPolicy::RegisterProvider(Provider
* provider
) {
51 providers_
.insert(provider
);
54 void ManagementPolicy::UnregisterProvider(Provider
* provider
) {
55 providers_
.erase(provider
);
58 bool ManagementPolicy::UserMayLoad(const Extension
* extension
,
59 base::string16
* error
) const {
60 return ApplyToProviderList(&Provider::UserMayLoad
, "Installation",
61 true, extension
, error
);
64 bool ManagementPolicy::UserMayModifySettings(const Extension
* extension
,
65 base::string16
* error
) const {
66 return ApplyToProviderList(&Provider::UserMayModifySettings
, "Modification",
67 true, extension
, error
);
70 bool ManagementPolicy::MustRemainEnabled(const Extension
* extension
,
71 base::string16
* error
) const {
72 return ApplyToProviderList(&Provider::MustRemainEnabled
, "Disabling",
73 false, extension
, error
);
76 bool ManagementPolicy::MustRemainDisabled(const Extension
* extension
,
77 Extension::DisableReason
* reason
,
78 base::string16
* error
) const {
79 for (ProviderList::const_iterator it
= providers_
.begin();
80 it
!= providers_
.end(); ++it
)
81 if ((*it
)->MustRemainDisabled(extension
, reason
, error
))
87 void ManagementPolicy::UnregisterAllProviders() {
91 int ManagementPolicy::GetNumProviders() const {
92 return providers_
.size();
95 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function
,
96 const char* debug_operation_name
,
98 const Extension
* extension
,
99 base::string16
* error
) const {
100 for (ProviderList::const_iterator it
= providers_
.begin();
101 it
!= providers_
.end(); ++it
) {
102 const Provider
* provider
= *it
;
103 bool result
= (provider
->*function
)(extension
, error
);
104 if (result
!= normal_result
) {
107 GetExtensionNameAndId(extension
, &name
, &id
);
108 DVLOG(1) << debug_operation_name
<< " of extension " << name
110 << " prohibited by " << provider
->GetDebugPolicyProviderName();
111 return !normal_result
;
114 return normal_result
;
117 } // namespace extensions