Chromium Code Reviews| 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/api/managed_mode_private/managed_mode_privat e_api.h" | 7 #include "chrome/browser/extensions/api/managed_mode_private/managed_mode_privat e_api.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" | 16 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" |
| 17 #include "chrome/browser/extensions/event_router.h" | 17 #include "chrome/browser/extensions/event_router.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/managed_mode/managed_mode.h" | 19 #include "chrome/browser/managed_mode/managed_mode.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "chrome/common/extensions/api/managed_mode_private.h" | |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 24 | 25 |
| 25 #if defined(ENABLE_CONFIGURATION_POLICY) | 26 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 26 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 27 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 30 namespace GetPolicy = extensions::api::managed_mode_private::GetPolicy; | |
|
cduvall
2013/03/05 21:59:39
Move into namespace extensions block.
Aaron Jacobs
2013/03/05 22:56:02
Done.
| |
| 31 namespace SetPolicy = extensions::api::managed_mode_private::SetPolicy; | |
| 32 | |
| 29 namespace { | 33 namespace { |
| 30 | 34 |
| 31 // Event that is fired when we enter or leave managed mode. | 35 // Event that is fired when we enter or leave managed mode. |
| 32 const char kChangeEventName[] = "managedModePrivate.onChange"; | 36 const char kChangeEventName[] = "managedModePrivate.onChange"; |
| 33 | 37 |
| 34 // Key to report whether the attempt to enter managed mode succeeded. | 38 // Key to report whether the attempt to enter managed mode succeeded. |
| 35 const char kEnterSuccessKey[] = "success"; | 39 const char kEnterSuccessKey[] = "success"; |
| 36 | 40 |
| 37 } // namespace | 41 } // namespace |
| 38 | 42 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 void ManagedModePrivateEnterFunction::SendResult(bool success) { | 94 void ManagedModePrivateEnterFunction::SendResult(bool success) { |
| 91 scoped_ptr<DictionaryValue> result(new DictionaryValue); | 95 scoped_ptr<DictionaryValue> result(new DictionaryValue); |
| 92 result->SetBoolean(kEnterSuccessKey, success); | 96 result->SetBoolean(kEnterSuccessKey, success); |
| 93 SetResult(result.release()); | 97 SetResult(result.release()); |
| 94 SendResponse(true); | 98 SendResponse(true); |
| 95 } | 99 } |
| 96 | 100 |
| 97 ManagedModePrivateGetPolicyFunction::~ManagedModePrivateGetPolicyFunction() { } | 101 ManagedModePrivateGetPolicyFunction::~ManagedModePrivateGetPolicyFunction() { } |
| 98 | 102 |
| 99 bool ManagedModePrivateGetPolicyFunction::RunImpl() { | 103 bool ManagedModePrivateGetPolicyFunction::RunImpl() { |
| 100 std::string key; | 104 scoped_ptr<GetPolicy::Params> params(GetPolicy::Params::Create(*args_)); |
| 101 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); | 105 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 102 #if defined(ENABLE_CONFIGURATION_POLICY) | 106 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 103 policy::ManagedModePolicyProvider* policy_provider = | 107 policy::ManagedModePolicyProvider* policy_provider = |
| 104 profile_->GetManagedModePolicyProvider(); | 108 profile_->GetManagedModePolicyProvider(); |
| 105 const base::Value* policy = policy_provider->GetPolicy(key); | 109 const base::Value* policy = policy_provider->GetPolicy(params->key); |
| 106 if (policy) | 110 if (policy) |
| 107 SetResult(policy->DeepCopy()); | 111 SetResult(policy->DeepCopy()); |
| 108 #endif | 112 #endif |
| 109 return true; | 113 return true; |
| 110 } | 114 } |
| 111 | 115 |
| 112 ManagedModePrivateSetPolicyFunction::~ManagedModePrivateSetPolicyFunction() { } | 116 ManagedModePrivateSetPolicyFunction::~ManagedModePrivateSetPolicyFunction() { } |
| 113 | 117 |
| 114 bool ManagedModePrivateSetPolicyFunction::RunImpl() { | 118 bool ManagedModePrivateSetPolicyFunction::RunImpl() { |
| 115 std::string key; | 119 scoped_ptr<SetPolicy::Params> params(SetPolicy::Params::Create(*args_)); |
| 116 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); | 120 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 117 base::Value* value = NULL; | |
| 118 EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &value)); | |
| 119 #if defined(ENABLE_CONFIGURATION_POLICY) | 121 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 120 policy::ManagedModePolicyProvider* policy_provider = | 122 policy::ManagedModePolicyProvider* policy_provider = |
| 121 profile_->GetManagedModePolicyProvider(); | 123 profile_->GetManagedModePolicyProvider(); |
| 122 policy_provider->SetPolicy(key, value); | 124 policy_provider->SetPolicy(params->key, params->value.get()); |
| 123 #endif | 125 #endif |
| 124 return true; | 126 return true; |
| 125 } | 127 } |
| 126 | 128 |
| 127 ManagedModeAPI::ManagedModeAPI(Profile* profile) | 129 ManagedModeAPI::ManagedModeAPI(Profile* profile) |
| 128 : profile_(profile) { | 130 : profile_(profile) { |
| 129 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 131 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 130 this, kChangeEventName); | 132 this, kChangeEventName); |
| 131 } | 133 } |
| 132 | 134 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 145 return &g_factory.Get(); | 147 return &g_factory.Get(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void ManagedModeAPI::OnListenerAdded( | 150 void ManagedModeAPI::OnListenerAdded( |
| 149 const extensions::EventListenerInfo& details) { | 151 const extensions::EventListenerInfo& details) { |
| 150 managed_mode_event_router_.reset(new ManagedModeEventRouter(profile_)); | 152 managed_mode_event_router_.reset(new ManagedModeEventRouter(profile_)); |
| 151 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 153 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 152 } | 154 } |
| 153 | 155 |
| 154 } // namespace extensions | 156 } // namespace extensions |
| OLD | NEW |