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 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_ = base::UTF8ToUTF16(expected_error()); 18 } 19 20 TestManagementPolicyProvider::TestManagementPolicyProvider( 21 int prohibited_actions) { 22 SetProhibitedActions(prohibited_actions); 23 error_message_ = base::UTF8ToUTF16(expected_error()); 24 } 25 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 34 void TestManagementPolicyProvider::SetDisableReason( 35 Extension::DisableReason reason) { 36 disable_reason_ = reason; 37 } 38 39 std::string TestManagementPolicyProvider::GetDebugPolicyProviderName() const { 40 return "the test management policy provider"; 41 } 42 43 bool TestManagementPolicyProvider::UserMayLoad(const Extension* extension, 44 base::string16* error) const { 45 if (error && !may_load_) 46 *error = error_message_; 47 return may_load_; 48 } 49 50 bool TestManagementPolicyProvider::UserMayModifySettings( 51 const Extension* extension, base::string16* error) const { 52 if (error && !may_modify_status_) 53 *error = error_message_; 54 return may_modify_status_; 55 } 56 57 bool TestManagementPolicyProvider::MustRemainEnabled(const Extension* extension, 58 base::string16* error) 59 const { 60 if (error && must_remain_enabled_) 61 *error = error_message_; 62 return must_remain_enabled_; 63 } 64 65 bool TestManagementPolicyProvider::MustRemainDisabled( 66 const Extension* extension, 67 Extension::DisableReason* reason, 68 base::string16* error) const { 69 if (must_remain_disabled_) { 70 if (error) 71 *error = error_message_; 72 if (reason) 73 *reason = disable_reason_; 74 } 75 return must_remain_disabled_; 76 } 77 78 79 } // namespace extensions 80