| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/management_policy.h" | 5 #include "extensions/browser/management_policy.h" |
| 6 | 6 |
| 7 namespace extensions { | 7 namespace extensions { |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 void GetExtensionNameAndId(const Extension* extension, | 11 void GetExtensionNameAndId(const Extension* extension, |
| 12 std::string* name, | 12 std::string* name, |
| 13 std::string* id) { | 13 std::string* id) { |
| 14 // The extension may be NULL in testing. | 14 // The extension may be NULL in testing. |
| 15 *id = extension ? extension->id() : "[test]"; | 15 *id = extension ? extension->id() : "[test]"; |
| 16 *name = extension ? extension->name() : "test"; | 16 *name = extension ? extension->name() : "test"; |
| 17 } | 17 } |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 ManagementPolicy::ManagementPolicy() { | 21 ManagementPolicy::ManagementPolicy() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 ManagementPolicy::~ManagementPolicy() { | 24 ManagementPolicy::~ManagementPolicy() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool ManagementPolicy::Provider::UserMayLoad(const Extension* extension, | 27 bool ManagementPolicy::Provider::UserMayLoad(const Extension* extension, |
| 28 int install_flags, |
| 28 base::string16* error) const { | 29 base::string16* error) const { |
| 29 return true; | 30 return true; |
| 30 } | 31 } |
| 31 | 32 |
| 32 bool ManagementPolicy::Provider::UserMayModifySettings( | 33 bool ManagementPolicy::Provider::UserMayModifySettings( |
| 33 const Extension* extension, base::string16* error) const { | 34 const Extension* extension, base::string16* error) const { |
| 34 return true; | 35 return true; |
| 35 } | 36 } |
| 36 | 37 |
| 37 bool ManagementPolicy::Provider::MustRemainEnabled(const Extension* extension, | 38 bool ManagementPolicy::Provider::MustRemainEnabled(const Extension* extension, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 void ManagementPolicy::RegisterProvider(Provider* provider) { | 51 void ManagementPolicy::RegisterProvider(Provider* provider) { |
| 51 providers_.insert(provider); | 52 providers_.insert(provider); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void ManagementPolicy::UnregisterProvider(Provider* provider) { | 55 void ManagementPolicy::UnregisterProvider(Provider* provider) { |
| 55 providers_.erase(provider); | 56 providers_.erase(provider); |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool ManagementPolicy::UserMayLoad(const Extension* extension, | 59 bool ManagementPolicy::UserMayLoad(const Extension* extension, |
| 60 int install_flags, |
| 59 base::string16* error) const { | 61 base::string16* error) const { |
| 60 return ApplyToProviderList(&Provider::UserMayLoad, "Installation", | 62 for (ProviderList::const_iterator it = providers_.begin(); |
| 61 true, extension, error); | 63 it != providers_.end(); |
| 64 ++it) { |
| 65 const Provider* provider = *it; |
| 66 if (!provider->UserMayLoad(extension, install_flags, error)) { |
| 67 LogProhibitedOperation("Installation", extension, provider); |
| 68 return false; |
| 69 } |
| 70 } |
| 71 return true; |
| 62 } | 72 } |
| 63 | 73 |
| 64 bool ManagementPolicy::UserMayModifySettings(const Extension* extension, | 74 bool ManagementPolicy::UserMayModifySettings(const Extension* extension, |
| 65 base::string16* error) const { | 75 base::string16* error) const { |
| 66 return ApplyToProviderList(&Provider::UserMayModifySettings, "Modification", | 76 return ApplyToProviderList(&Provider::UserMayModifySettings, "Modification", |
| 67 true, extension, error); | 77 true, extension, error); |
| 68 } | 78 } |
| 69 | 79 |
| 70 bool ManagementPolicy::MustRemainEnabled(const Extension* extension, | 80 bool ManagementPolicy::MustRemainEnabled(const Extension* extension, |
| 71 base::string16* error) const { | 81 base::string16* error) const { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function, | 105 bool ManagementPolicy::ApplyToProviderList(ProviderFunction function, |
| 96 const char* debug_operation_name, | 106 const char* debug_operation_name, |
| 97 bool normal_result, | 107 bool normal_result, |
| 98 const Extension* extension, | 108 const Extension* extension, |
| 99 base::string16* error) const { | 109 base::string16* error) const { |
| 100 for (ProviderList::const_iterator it = providers_.begin(); | 110 for (ProviderList::const_iterator it = providers_.begin(); |
| 101 it != providers_.end(); ++it) { | 111 it != providers_.end(); ++it) { |
| 102 const Provider* provider = *it; | 112 const Provider* provider = *it; |
| 103 bool result = (provider->*function)(extension, error); | 113 bool result = (provider->*function)(extension, error); |
| 104 if (result != normal_result) { | 114 if (result != normal_result) { |
| 105 std::string id; | 115 LogProhibitedOperation(debug_operation_name, extension, provider); |
| 106 std::string name; | |
| 107 GetExtensionNameAndId(extension, &name, &id); | |
| 108 DVLOG(1) << debug_operation_name << " of extension " << name | |
| 109 << " (" << id << ")" | |
| 110 << " prohibited by " << provider->GetDebugPolicyProviderName(); | |
| 111 return !normal_result; | 116 return !normal_result; |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 return normal_result; | 119 return normal_result; |
| 115 } | 120 } |
| 116 | 121 |
| 122 void ManagementPolicy::LogProhibitedOperation(const char* debug_operation_name, |
| 123 const Extension* extension, |
| 124 const Provider* provider) const { |
| 125 std::string id; |
| 126 std::string name; |
| 127 GetExtensionNameAndId(extension, &name, &id); |
| 128 DVLOG(1) << debug_operation_name << " of extension " << name |
| 129 << " (" << id << ")" |
| 130 << " prohibited by " << provider->GetDebugPolicyProviderName(); |
| 131 } |
| 132 |
| 117 } // namespace extensions | 133 } // namespace extensions |
| OLD | NEW |