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
3 // found in the LICENSE file.
5 #include "chrome/browser/policy/schema_registry_service_factory.h"
7 #include "base/logging.h"
8 #include "chrome/browser/policy/schema_registry_service.h"
9 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
10 #include "components/policy/core/common/schema.h"
11 #include "components/policy/core/common/schema_registry.h"
12 #include "content/public/browser/browser_context.h"
17 SchemaRegistryServiceFactory
* SchemaRegistryServiceFactory::GetInstance() {
18 return Singleton
<SchemaRegistryServiceFactory
>::get();
22 SchemaRegistryService
* SchemaRegistryServiceFactory::GetForContext(
23 content::BrowserContext
* context
) {
24 return GetInstance()->GetForContextInternal(context
);
28 scoped_ptr
<SchemaRegistryService
>
29 SchemaRegistryServiceFactory::CreateForContext(
30 content::BrowserContext
* context
,
31 const Schema
& chrome_schema
,
32 CombinedSchemaRegistry
* global_registry
) {
33 return GetInstance()->CreateForContextInternal(
34 context
, chrome_schema
, global_registry
);
37 SchemaRegistryServiceFactory::SchemaRegistryServiceFactory()
38 : BrowserContextKeyedBaseFactory(
39 "SchemaRegistryService",
40 BrowserContextDependencyManager::GetInstance()) {}
42 SchemaRegistryServiceFactory::~SchemaRegistryServiceFactory() {}
44 SchemaRegistryService
* SchemaRegistryServiceFactory::GetForContextInternal(
45 content::BrowserContext
* context
) {
46 // Off-the-record Profiles get their policy from the main Profile's
47 // PolicyService, and don't need their own SchemaRegistry nor any policy
49 if (context
->IsOffTheRecord())
51 RegistryMap::const_iterator it
= registries_
.find(context
);
52 CHECK(it
!= registries_
.end());
56 scoped_ptr
<SchemaRegistryService
>
57 SchemaRegistryServiceFactory::CreateForContextInternal(
58 content::BrowserContext
* context
,
59 const Schema
& chrome_schema
,
60 CombinedSchemaRegistry
* global_registry
) {
61 DCHECK(!context
->IsOffTheRecord());
62 DCHECK(registries_
.find(context
) == registries_
.end());
63 SchemaRegistryService
* registry
=
64 new SchemaRegistryService(chrome_schema
, global_registry
);
65 registries_
[context
] = registry
;
66 return make_scoped_ptr(registry
);
69 void SchemaRegistryServiceFactory::BrowserContextShutdown(
70 content::BrowserContext
* context
) {
71 if (context
->IsOffTheRecord())
73 RegistryMap::iterator it
= registries_
.find(context
);
74 if (it
!= registries_
.end())
75 it
->second
->Shutdown();
80 void SchemaRegistryServiceFactory::BrowserContextDestroyed(
81 content::BrowserContext
* context
) {
82 registries_
.erase(context
);
83 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context
);
86 void SchemaRegistryServiceFactory::SetEmptyTestingFactory(
87 content::BrowserContext
* context
) {}
89 void SchemaRegistryServiceFactory::CreateServiceNow(
90 content::BrowserContext
* context
) {}