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/test_management_policy.h"
7 #include "base/strings/utf_string_conversions.h"
11 TestManagementPolicyProvider::TestManagementPolicyProvider()
13 may_modify_status_(true),
14 must_remain_enabled_(false),
15 must_remain_disabled_(false),
16 must_remain_installed_(false),
17 disable_reason_(Extension::DISABLE_NONE
) {
18 error_message_
= base::UTF8ToUTF16(expected_error());
21 TestManagementPolicyProvider::TestManagementPolicyProvider(
22 int prohibited_actions
) {
23 SetProhibitedActions(prohibited_actions
);
24 error_message_
= base::UTF8ToUTF16(expected_error());
27 void TestManagementPolicyProvider::SetProhibitedActions(
28 int prohibited_actions
) {
29 may_load_
= (prohibited_actions
& PROHIBIT_LOAD
) == 0;
30 may_modify_status_
= (prohibited_actions
& PROHIBIT_MODIFY_STATUS
) == 0;
31 must_remain_enabled_
= (prohibited_actions
& MUST_REMAIN_ENABLED
) != 0;
32 must_remain_disabled_
= (prohibited_actions
& MUST_REMAIN_DISABLED
) != 0;
33 must_remain_installed_
= (prohibited_actions
& MUST_REMAIN_INSTALLED
) != 0;
36 void TestManagementPolicyProvider::SetDisableReason(
37 Extension::DisableReason reason
) {
38 disable_reason_
= reason
;
41 std::string
TestManagementPolicyProvider::GetDebugPolicyProviderName() const {
42 return "the test management policy provider";
45 bool TestManagementPolicyProvider::UserMayLoad(const Extension
* extension
,
46 base::string16
* error
) const {
47 if (error
&& !may_load_
)
48 *error
= error_message_
;
52 bool TestManagementPolicyProvider::UserMayModifySettings(
53 const Extension
* extension
, base::string16
* error
) const {
54 if (error
&& !may_modify_status_
)
55 *error
= error_message_
;
56 return may_modify_status_
;
59 bool TestManagementPolicyProvider::MustRemainEnabled(const Extension
* extension
,
60 base::string16
* error
)
62 if (error
&& must_remain_enabled_
)
63 *error
= error_message_
;
64 return must_remain_enabled_
;
67 bool TestManagementPolicyProvider::MustRemainDisabled(
68 const Extension
* extension
,
69 Extension::DisableReason
* reason
,
70 base::string16
* error
) const {
71 if (must_remain_disabled_
) {
73 *error
= error_message_
;
75 *reason
= disable_reason_
;
77 return must_remain_disabled_
;
80 bool TestManagementPolicyProvider::MustRemainInstalled(
81 const Extension
* extension
,
82 base::string16
* error
) const {
83 if (error
&& must_remain_installed_
)
84 *error
= error_message_
;
85 return must_remain_installed_
;
88 } // namespace extensions