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 71758ffc9076cbb1247912cd29ca8f1166599b20..1bdd9c7fbd70a7e5f4b80285b516ead10d79ebc8 100644 |
--- a/chrome/browser/policy/schema_registry_service_factory.cc |
+++ b/chrome/browser/policy/schema_registry_service_factory.cc |
@@ -5,14 +5,49 @@ |
#include "chrome/browser/policy/schema_registry_service_factory.h" |
#include "base/logging.h" |
+#include "base/macros.h" |
bartfab (slow)
2014/06/20 09:44:23
Nit: Move this to the header, which uses DISALLOW_
Joao da Silva
2014/06/20 15:36:08
Done.
|
#include "chrome/browser/policy/schema_registry_service.h" |
#include "components/keyed_service/content/browser_context_dependency_manager.h" |
#include "components/policy/core/common/schema.h" |
#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/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; |
+ |
+ 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(); |
bartfab (slow)
2014/06/20 09:44:23
Nit: #include "chrome/browser/browser_process_plat
Joao da Silva
2014/06/20 15:36:08
Done.
|
+ DeviceLocalAccountPolicyService* service = |
+ connector->GetDeviceLocalAccountPolicyService(); |
+ return service->GetBrokerForUser(user->email()); |
+} |
+ |
+} // namespace |
+#endif // OS_CHROMEOS |
+ |
// static |
SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { |
return Singleton<SchemaRegistryServiceFactory>::get(); |
@@ -60,10 +95,24 @@ SchemaRegistryServiceFactory::CreateForContextInternal( |
CombinedSchemaRegistry* global_registry) { |
DCHECK(!context->IsOffTheRecord()); |
DCHECK(registries_.find(context) == registries_.end()); |
- SchemaRegistryService* registry = |
- new SchemaRegistryService(chrome_schema, global_registry); |
- registries_[context] = registry; |
- return make_scoped_ptr(registry); |
+ |
+ scoped_ptr<SchemaRegistryService> registry; |
+ |
+#if defined(OS_CHROMEOS) |
+ DeviceLocalAccountPolicyBroker* broker = GetBroker(context); |
+ if (broker) { |
+ // The DeviceLocalAccountPolicyBroker creates a SchemaRegistryService for |
+ // device local accounts earlier, so that the external data can be preloaded |
bartfab (slow)
2014/06/20 09:44:23
Nit: s/device local/device-local/
Joao da Silva
2014/06/20 15:36:08
Done.
|
+ // before the session is started. Transfer its ownership now. |
+ registry = broker->release_schema_registry(); |
+ } |
+#endif |
+ |
+ if (!registry) |
+ registry.reset(new SchemaRegistryService(chrome_schema, global_registry)); |
+ |
+ registries_[context] = registry.get(); |
+ return registry.Pass(); |
} |
void SchemaRegistryServiceFactory::BrowserContextShutdown( |
@@ -71,10 +120,19 @@ void SchemaRegistryServiceFactory::BrowserContextShutdown( |
if (context->IsOffTheRecord()) |
return; |
RegistryMap::iterator it = registries_.find(context); |
- if (it != registries_.end()) |
+ if (it != registries_.end()) { |
+#if defined(OS_CHROMEOS) |
+ DeviceLocalAccountPolicyBroker* broker = GetBroker(context); |
+ if (broker) { |
+ // Give the broker a notification to clean up any observers of the |
+ // SchemaRegistryService. |
+ broker->OnSchemaRegistryShutdown(); |
+ } |
+#endif |
it->second->Shutdown(); |
- else |
+ } else { |
NOTREACHED(); |
+ } |
} |
void SchemaRegistryServiceFactory::BrowserContextDestroyed( |