| 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/extensions/api/managed_mode_private.h" |
| 23 #include "chrome/common/extensions/api/managed_mode_private/managed_mode_handler
.h" | |
| 24 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 25 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 26 | 25 |
| 27 #if defined(ENABLE_CONFIGURATION_POLICY) | 26 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 28 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 27 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| 29 #endif | 28 #endif |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 // Event that is fired when we enter or leave managed mode. | 32 // Event that is fired when we enter or leave managed mode. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 profile_->GetManagedModePolicyProvider(); | 123 profile_->GetManagedModePolicyProvider(); |
| 125 policy_provider->SetPolicy(params->key, params->value.get()); | 124 policy_provider->SetPolicy(params->key, params->value.get()); |
| 126 #endif | 125 #endif |
| 127 return true; | 126 return true; |
| 128 } | 127 } |
| 129 | 128 |
| 130 ManagedModeAPI::ManagedModeAPI(Profile* profile) | 129 ManagedModeAPI::ManagedModeAPI(Profile* profile) |
| 131 : profile_(profile) { | 130 : profile_(profile) { |
| 132 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 131 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 133 this, kChangeEventName); | 132 this, kChangeEventName); |
| 134 (new ManagedModeHandler)->Register(); | |
| 135 } | 133 } |
| 136 | 134 |
| 137 ManagedModeAPI::~ManagedModeAPI() { | 135 ManagedModeAPI::~ManagedModeAPI() { |
| 138 } | 136 } |
| 139 | 137 |
| 140 void ManagedModeAPI::Shutdown() { | 138 void ManagedModeAPI::Shutdown() { |
| 141 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 139 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 142 } | 140 } |
| 143 | 141 |
| 144 static base::LazyInstance<ProfileKeyedAPIFactory<ManagedModeAPI> > | 142 static base::LazyInstance<ProfileKeyedAPIFactory<ManagedModeAPI> > |
| 145 g_factory = LAZY_INSTANCE_INITIALIZER; | 143 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 146 | 144 |
| 147 // static | 145 // static |
| 148 ProfileKeyedAPIFactory<ManagedModeAPI>* ManagedModeAPI::GetFactoryInstance() { | 146 ProfileKeyedAPIFactory<ManagedModeAPI>* ManagedModeAPI::GetFactoryInstance() { |
| 149 return &g_factory.Get(); | 147 return &g_factory.Get(); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void ManagedModeAPI::OnListenerAdded( | 150 void ManagedModeAPI::OnListenerAdded( |
| 153 const extensions::EventListenerInfo& details) { | 151 const extensions::EventListenerInfo& details) { |
| 154 managed_mode_event_router_.reset(new ManagedModeEventRouter(profile_)); | 152 managed_mode_event_router_.reset(new ManagedModeEventRouter(profile_)); |
| 155 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 153 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 156 } | 154 } |
| 157 | 155 |
| 158 } // namespace extensions | 156 } // namespace extensions |
| OLD | NEW |