Chromium Code Reviews| Index: chrome/browser/policy/schema_registry_service_factory.cc |
| diff --git a/chrome/browser/policy/schema_registry_service_factory.cc b/chrome/browser/policy/schema_registry_service_factory.cc |
| index eaa526848015ce7c60056e06a8583ffa2acc077e..89363eac4f50bf14d857541e65424deb15948113 100644 |
| --- a/chrome/browser/policy/schema_registry_service_factory.cc |
| +++ b/chrome/browser/policy/schema_registry_service_factory.cc |
| @@ -11,8 +11,51 @@ |
| #include "components/policy/core/common/schema_registry.h" |
| #include "content/public/browser/browser_context.h" |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/browser_process_platform_part_chromeos.h" |
| +#include "chrome/browser/chromeos/login/users/user.h" |
| +#include "chrome/browser/chromeos/login/users/user_manager.h" |
| +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| +#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
| +#include "chrome/browser/chromeos/profiles/profile_helper.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#endif |
| + |
| namespace policy { |
| +#if defined(OS_CHROMEOS) |
| +namespace { |
| + |
| +DeviceLocalAccountPolicyBroker* GetBroker(content::BrowserContext* context) { |
| + Profile* profile = Profile::FromBrowserContext(context); |
| + |
| + if (chromeos::ProfileHelper::IsSigninProfile(profile)) |
| + return NULL; |
| + |
| + if (!chromeos::UserManager::IsInitialized()) { |
| + // Bail out on unit tests that don't have a UserManager. |
|
bartfab (slow)
2014/06/20 16:41:10
Nit: s/ on / in /.
Joao da Silva
2014/06/20 17:25:33
Done.
|
| + return NULL; |
| + } |
| + |
| + chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| + chromeos::User* user = user_manager->GetUserByProfile(profile); |
| + if (!user) |
| + return NULL; |
| + |
| + BrowserPolicyConnectorChromeOS* connector = |
| + g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| + DeviceLocalAccountPolicyService* service = |
| + connector->GetDeviceLocalAccountPolicyService(); |
| + if (!service) |
| + return NULL; |
| + |
| + return service->GetBrokerForUser(user->email()); |
| +} |
| + |
| +} // namespace |
| +#endif // OS_CHROMEOS |
| + |
| // static |
| SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { |
| return Singleton<SchemaRegistryServiceFactory>::get(); |
| @@ -60,7 +103,23 @@ SchemaRegistryServiceFactory::CreateForContextInternal( |
| CombinedSchemaRegistry* global_registry) { |
| DCHECK(!context->IsOffTheRecord()); |
| DCHECK(registries_.find(context) == registries_.end()); |
| - scoped_ptr<SchemaRegistry> registry(new SchemaRegistry); |
| + |
| + scoped_ptr<SchemaRegistry> registry; |
| + |
| +#if defined(OS_CHROMEOS) |
| + DeviceLocalAccountPolicyBroker* broker = GetBroker(context); |
| + if (broker) { |
| + // The DeviceLocalAccountPolicyBroker creates a SchemaRegistry for |
| + // device-local accounts earlier, so that the external data can be preloaded |
|
bartfab (slow)
2014/06/20 16:41:10
Nit: "earlier" is very hard to interpret in the co
Joao da Silva
2014/06/20 17:25:33
Done.
|
| + // before the session is started. Use a ForwardingSchemaRegistry to wrap |
| + // it here. |
| + registry.reset(new ForwardingSchemaRegistry(broker->schema_registry())); |
| + } |
| +#endif |
| + |
| + if (!registry) |
| + registry.reset(new SchemaRegistry); |
| + |
| scoped_ptr<SchemaRegistryService> service(new SchemaRegistryService( |
| registry.Pass(), chrome_schema, global_registry)); |
| registries_[context] = service.get(); |