Rename desktop_cursor_loader_updater_aurax11.
[chromium-blink-merge.git] / chrome / browser / extensions / management_policy.cc
blob710968f9d6b1eace0425c6b71437876a99f3f4ca
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"
7 namespace extensions {
9 namespace {
11 void GetExtensionNameAndId(const Extension* extension,
12 std::string* name,
13 std::string* id) {
14 // The extension may be NULL in testing.
15 *id = extension ? extension->id() : "[test]";
16 *name = extension ? extension->name() : "test";
19 } // namespace
21 ManagementPolicy::ManagementPolicy() {
24 ManagementPolicy::~ManagementPolicy() {
27 bool ManagementPolicy::Provider::UserMayLoad(const Extension* extension,
28 string16* error) const {
29 return true;
32 bool ManagementPolicy::Provider::UserMayModifySettings(
33 const Extension* extension, string16* error) const {
34 return true;
37 bool ManagementPolicy::Provider::MustRemainEnabled(const Extension* extension,
38 string16* error) const {
39 return false;
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() {
69 providers_.clear();
72 int ManagementPolicy::GetNumProviders() const {
73 return providers_.size();
76 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function,
77 const char* debug_operation_name,
78 bool normal_result,
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) {
86 std::string id;
87 std::string name;
88 GetExtensionNameAndId(extension, &name, &id);
89 DVLOG(1) << debug_operation_name << " of extension " << name
90 << " (" << id << ")"
91 << " prohibited by " << provider->GetDebugPolicyProviderName();
92 return !normal_result;
95 return normal_result;
98 } // namespace extensions