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 bool ManagementPolicy::Provider::MustRemainInstalled(
51 const Extension
* extension
,
52 base::string16
* error
) const {
56 void ManagementPolicy::RegisterProvider(Provider
* provider
) {
57 providers_
.insert(provider
);
60 void ManagementPolicy::UnregisterProvider(Provider
* provider
) {
61 providers_
.erase(provider
);
64 void ManagementPolicy::RegisterProviders(std::vector
<Provider
*> providers
) {
65 providers_
.insert(providers
.begin(), providers
.end());
68 bool ManagementPolicy::UserMayLoad(const Extension
* extension
,
69 base::string16
* error
) const {
70 return ApplyToProviderList(
71 &Provider::UserMayLoad
, "Installation", true, extension
, error
);
74 bool ManagementPolicy::UserMayModifySettings(const Extension
* extension
,
75 base::string16
* error
) const {
76 return ApplyToProviderList(
77 &Provider::UserMayModifySettings
, "Modification", true, extension
, error
);
80 bool ManagementPolicy::MustRemainEnabled(const Extension
* extension
,
81 base::string16
* error
) const {
82 return ApplyToProviderList(
83 &Provider::MustRemainEnabled
, "Disabling", false, extension
, error
);
86 bool ManagementPolicy::MustRemainDisabled(const Extension
* extension
,
87 Extension::DisableReason
* reason
,
88 base::string16
* error
) const {
89 for (ProviderList::const_iterator it
= providers_
.begin();
90 it
!= providers_
.end(); ++it
)
91 if ((*it
)->MustRemainDisabled(extension
, reason
, error
))
97 bool ManagementPolicy::MustRemainInstalled(const Extension
* extension
,
98 base::string16
* error
) const {
99 return ApplyToProviderList(
100 &Provider::MustRemainInstalled
, "Removing", false, extension
, error
);
103 void ManagementPolicy::UnregisterAllProviders() {
107 int ManagementPolicy::GetNumProviders() const {
108 return providers_
.size();
111 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function
,
112 const char* debug_operation_name
,
114 const Extension
* extension
,
115 base::string16
* error
) const {
116 for (ProviderList::const_iterator it
= providers_
.begin();
117 it
!= providers_
.end(); ++it
) {
118 const Provider
* provider
= *it
;
119 bool result
= (provider
->*function
)(extension
, error
);
120 if (result
!= normal_result
) {
123 GetExtensionNameAndId(extension
, &name
, &id
);
124 DVLOG(1) << debug_operation_name
<< " of extension " << name
126 << " prohibited by " << provider
->GetDebugPolicyProviderName();
127 return !normal_result
;
130 return normal_result
;
133 } // namespace extensions