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.
4
5 #include "extensions/browser/test_management_policy.h"
6
7 #include "base/strings/utf_string_conversions.h"
8
9 namespace extensions {
10
TestManagementPolicyProvider()11 TestManagementPolicyProvider::TestManagementPolicyProvider()
12 : may_load_(true),
13 may_modify_status_(true),
14 must_remain_enabled_(false),
15 must_remain_disabled_(false),
16 disable_reason_(Extension::DISABLE_NONE) {
17 error_message_ = UTF8ToUTF16(expected_error());
18 }
19
TestManagementPolicyProvider(int prohibited_actions)20 TestManagementPolicyProvider::TestManagementPolicyProvider(
21 int prohibited_actions) {
22 SetProhibitedActions(prohibited_actions);
23 error_message_ = UTF8ToUTF16(expected_error());
24 }
25
SetProhibitedActions(int prohibited_actions)26 void TestManagementPolicyProvider::SetProhibitedActions(
27 int prohibited_actions) {
28 may_load_ = (prohibited_actions & PROHIBIT_LOAD) == 0;
29 may_modify_status_ = (prohibited_actions & PROHIBIT_MODIFY_STATUS) == 0;
30 must_remain_enabled_ = (prohibited_actions & MUST_REMAIN_ENABLED) != 0;
31 must_remain_disabled_ = (prohibited_actions & MUST_REMAIN_DISABLED) != 0;
32 }
33
SetDisableReason(Extension::DisableReason reason)34 void TestManagementPolicyProvider::SetDisableReason(
35 Extension::DisableReason reason) {
36 disable_reason_ = reason;
37 }
38
GetDebugPolicyProviderName() const39 std::string TestManagementPolicyProvider::GetDebugPolicyProviderName() const {
40 return "the test management policy provider";
41 }
42
UserMayLoad(const Extension * extension,string16 * error) const43 bool TestManagementPolicyProvider::UserMayLoad(const Extension* extension,
44 string16* error) const {
45 if (error && !may_load_)
46 *error = error_message_;
47 return may_load_;
48 }
49
UserMayModifySettings(const Extension * extension,string16 * error) const50 bool TestManagementPolicyProvider::UserMayModifySettings(
51 const Extension* extension, string16* error) const {
52 if (error && !may_modify_status_)
53 *error = error_message_;
54 return may_modify_status_;
55 }
56
MustRemainEnabled(const Extension * extension,string16 * error) const57 bool TestManagementPolicyProvider::MustRemainEnabled(const Extension* extension,
58 string16* error) const {
59 if (error && must_remain_enabled_)
60 *error = error_message_;
61 return must_remain_enabled_;
62 }
63
MustRemainDisabled(const Extension * extension,Extension::DisableReason * reason,string16 * error) const64 bool TestManagementPolicyProvider::MustRemainDisabled(
65 const Extension* extension,
66 Extension::DisableReason* reason,
67 string16* error) const {
68 if (must_remain_disabled_) {
69 if (error)
70 *error = error_message_;
71 if (reason)
72 *reason = disable_reason_;
73 }
74 return must_remain_disabled_;
75 }
76
77
78 } // namespace extensions
79