Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/policy/schema_registry_service_factory.h" | 5 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/policy/schema_registry_service.h" | 8 #include "chrome/browser/policy/schema_registry_service.h" |
| 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 9 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 10 #include "components/policy/core/common/schema.h" | 10 #include "components/policy/core/common/schema.h" |
| 11 #include "components/policy/core/common/schema_registry.h" | 11 #include "components/policy/core/common/schema_registry.h" |
| 12 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 13 | 13 |
| 14 #if defined(OS_CHROMEOS) | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/browser_process_platform_part_chromeos.h" | |
| 17 #include "chrome/browser/chromeos/login/users/user.h" | |
| 18 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 20 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 22 #include "chrome/browser/profiles/profile.h" | |
| 23 #endif | |
| 24 | |
| 14 namespace policy { | 25 namespace policy { |
| 15 | 26 |
| 27 #if defined(OS_CHROMEOS) | |
| 28 namespace { | |
| 29 | |
| 30 DeviceLocalAccountPolicyBroker* GetBroker(content::BrowserContext* context) { | |
| 31 Profile* profile = Profile::FromBrowserContext(context); | |
| 32 | |
| 33 if (chromeos::ProfileHelper::IsSigninProfile(profile)) | |
| 34 return NULL; | |
| 35 | |
| 36 if (!chromeos::UserManager::IsInitialized()) { | |
| 37 // 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.
| |
| 38 return NULL; | |
| 39 } | |
| 40 | |
| 41 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
| 42 chromeos::User* user = user_manager->GetUserByProfile(profile); | |
| 43 if (!user) | |
| 44 return NULL; | |
| 45 | |
| 46 BrowserPolicyConnectorChromeOS* connector = | |
| 47 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 48 DeviceLocalAccountPolicyService* service = | |
| 49 connector->GetDeviceLocalAccountPolicyService(); | |
| 50 if (!service) | |
| 51 return NULL; | |
| 52 | |
| 53 return service->GetBrokerForUser(user->email()); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 #endif // OS_CHROMEOS | |
| 58 | |
| 16 // static | 59 // static |
| 17 SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { | 60 SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { |
| 18 return Singleton<SchemaRegistryServiceFactory>::get(); | 61 return Singleton<SchemaRegistryServiceFactory>::get(); |
| 19 } | 62 } |
| 20 | 63 |
| 21 // static | 64 // static |
| 22 SchemaRegistryService* SchemaRegistryServiceFactory::GetForContext( | 65 SchemaRegistryService* SchemaRegistryServiceFactory::GetForContext( |
| 23 content::BrowserContext* context) { | 66 content::BrowserContext* context) { |
| 24 return GetInstance()->GetForContextInternal(context); | 67 return GetInstance()->GetForContextInternal(context); |
| 25 } | 68 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 53 return it->second; | 96 return it->second; |
| 54 } | 97 } |
| 55 | 98 |
| 56 scoped_ptr<SchemaRegistryService> | 99 scoped_ptr<SchemaRegistryService> |
| 57 SchemaRegistryServiceFactory::CreateForContextInternal( | 100 SchemaRegistryServiceFactory::CreateForContextInternal( |
| 58 content::BrowserContext* context, | 101 content::BrowserContext* context, |
| 59 const Schema& chrome_schema, | 102 const Schema& chrome_schema, |
| 60 CombinedSchemaRegistry* global_registry) { | 103 CombinedSchemaRegistry* global_registry) { |
| 61 DCHECK(!context->IsOffTheRecord()); | 104 DCHECK(!context->IsOffTheRecord()); |
| 62 DCHECK(registries_.find(context) == registries_.end()); | 105 DCHECK(registries_.find(context) == registries_.end()); |
| 63 scoped_ptr<SchemaRegistry> registry(new SchemaRegistry); | 106 |
| 107 scoped_ptr<SchemaRegistry> registry; | |
| 108 | |
| 109 #if defined(OS_CHROMEOS) | |
| 110 DeviceLocalAccountPolicyBroker* broker = GetBroker(context); | |
| 111 if (broker) { | |
| 112 // The DeviceLocalAccountPolicyBroker creates a SchemaRegistry for | |
| 113 // 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.
| |
| 114 // before the session is started. Use a ForwardingSchemaRegistry to wrap | |
| 115 // it here. | |
| 116 registry.reset(new ForwardingSchemaRegistry(broker->schema_registry())); | |
| 117 } | |
| 118 #endif | |
| 119 | |
| 120 if (!registry) | |
| 121 registry.reset(new SchemaRegistry); | |
| 122 | |
| 64 scoped_ptr<SchemaRegistryService> service(new SchemaRegistryService( | 123 scoped_ptr<SchemaRegistryService> service(new SchemaRegistryService( |
| 65 registry.Pass(), chrome_schema, global_registry)); | 124 registry.Pass(), chrome_schema, global_registry)); |
| 66 registries_[context] = service.get(); | 125 registries_[context] = service.get(); |
| 67 return service.Pass(); | 126 return service.Pass(); |
| 68 } | 127 } |
| 69 | 128 |
| 70 void SchemaRegistryServiceFactory::BrowserContextShutdown( | 129 void SchemaRegistryServiceFactory::BrowserContextShutdown( |
| 71 content::BrowserContext* context) { | 130 content::BrowserContext* context) { |
| 72 if (context->IsOffTheRecord()) | 131 if (context->IsOffTheRecord()) |
| 73 return; | 132 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 84 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); | 143 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); |
| 85 } | 144 } |
| 86 | 145 |
| 87 void SchemaRegistryServiceFactory::SetEmptyTestingFactory( | 146 void SchemaRegistryServiceFactory::SetEmptyTestingFactory( |
| 88 content::BrowserContext* context) {} | 147 content::BrowserContext* context) {} |
| 89 | 148 |
| 90 void SchemaRegistryServiceFactory::CreateServiceNow( | 149 void SchemaRegistryServiceFactory::CreateServiceNow( |
| 91 content::BrowserContext* context) {} | 150 content::BrowserContext* context) {} |
| 92 | 151 |
| 93 } // namespace policy | 152 } // namespace policy |
| OLD | NEW |