| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Implementation of the Chrome Extensions Managed Mode API. | 5 // Implementation of the Chrome Extensions Managed Mode API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_managed_mode_api.h" | 7 #include "chrome/browser/extensions/extension_managed_mode_api.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 extensions::EventFilteringInfo()); | 71 extensions::EventFilteringInfo()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 GetManagedModeFunction::~GetManagedModeFunction() { } | 74 GetManagedModeFunction::~GetManagedModeFunction() { } |
| 75 | 75 |
| 76 bool GetManagedModeFunction::RunImpl() { | 76 bool GetManagedModeFunction::RunImpl() { |
| 77 bool in_managed_mode = ManagedMode::IsInManagedMode(); | 77 bool in_managed_mode = ManagedMode::IsInManagedMode(); |
| 78 | 78 |
| 79 scoped_ptr<DictionaryValue> result(new DictionaryValue); | 79 scoped_ptr<DictionaryValue> result(new DictionaryValue); |
| 80 result->SetBoolean(keys::kValue, in_managed_mode); | 80 result->SetBoolean(keys::kValue, in_managed_mode); |
| 81 result_.reset(result.release()); | 81 SetResult(result.release()); |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 EnterManagedModeFunction::~EnterManagedModeFunction() { } | 85 EnterManagedModeFunction::~EnterManagedModeFunction() { } |
| 86 | 86 |
| 87 bool EnterManagedModeFunction::RunImpl() { | 87 bool EnterManagedModeFunction::RunImpl() { |
| 88 ManagedMode::EnterManagedMode( | 88 ManagedMode::EnterManagedMode( |
| 89 profile(), | 89 profile(), |
| 90 base::Bind(&EnterManagedModeFunction::SendResult, this)); | 90 base::Bind(&EnterManagedModeFunction::SendResult, this)); |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void EnterManagedModeFunction::SendResult(bool success) { | 94 void EnterManagedModeFunction::SendResult(bool success) { |
| 95 scoped_ptr<DictionaryValue> result(new DictionaryValue); | 95 scoped_ptr<DictionaryValue> result(new DictionaryValue); |
| 96 result->SetBoolean(kEnterSuccessKey, success); | 96 result->SetBoolean(kEnterSuccessKey, success); |
| 97 result_.reset(result.release()); | 97 SetResult(result.release()); |
| 98 SendResponse(true); | 98 SendResponse(true); |
| 99 } | 99 } |
| 100 | 100 |
| 101 GetPolicyFunction::~GetPolicyFunction() { } | 101 GetPolicyFunction::~GetPolicyFunction() { } |
| 102 | 102 |
| 103 bool GetPolicyFunction::RunImpl() { | 103 bool GetPolicyFunction::RunImpl() { |
| 104 std::string key; | 104 std::string key; |
| 105 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); | 105 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); |
| 106 #if defined(ENABLE_CONFIGURATION_POLICY) | 106 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 107 policy::ManagedModePolicyProvider* policy_provider = | 107 policy::ManagedModePolicyProvider* policy_provider = |
| 108 ManagedModePolicyProviderFactory::GetForProfile(profile_); | 108 ManagedModePolicyProviderFactory::GetForProfile(profile_); |
| 109 const base::Value* policy = policy_provider->GetPolicy(key); | 109 const base::Value* policy = policy_provider->GetPolicy(key); |
| 110 if (policy) | 110 if (policy) |
| 111 result_.reset(policy->DeepCopy()); | 111 SetResult(policy->DeepCopy()); |
| 112 #endif | 112 #endif |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 SetPolicyFunction::~SetPolicyFunction() { } | 116 SetPolicyFunction::~SetPolicyFunction() { } |
| 117 | 117 |
| 118 bool SetPolicyFunction::RunImpl() { | 118 bool SetPolicyFunction::RunImpl() { |
| 119 std::string key; | 119 std::string key; |
| 120 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); | 120 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); |
| 121 base::Value* value = NULL; | 121 base::Value* value = NULL; |
| 122 EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &value)); | 122 EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &value)); |
| 123 #if defined(ENABLE_CONFIGURATION_POLICY) | 123 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 124 policy::ManagedModePolicyProvider* policy_provider = | 124 policy::ManagedModePolicyProvider* policy_provider = |
| 125 ManagedModePolicyProviderFactory::GetForProfile(profile_); | 125 ManagedModePolicyProviderFactory::GetForProfile(profile_); |
| 126 policy_provider->SetPolicy(key, value); | 126 policy_provider->SetPolicy(key, value); |
| 127 #endif | 127 #endif |
| 128 return true; | 128 return true; |
| 129 } | 129 } |
| OLD | NEW |