Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / policy / schema_registry_service_factory.h
bloba4be07dd2a59cc66bfab94475b5dfef069de1542
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 #ifndef CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
8 #include <map>
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h"
14 #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
16 namespace content {
17 class BrowserContext;
20 namespace policy {
22 class CombinedSchemaRegistry;
23 class Schema;
24 class SchemaRegistryService;
26 // Creates SchemaRegistryServices for BrowserContexts.
27 // TODO(joaodasilva): Convert this class to a proper BCKS once the PrefService
28 // becomes a BCKS too. For now the PrefService depends on the
29 // UserCloudPolicyManager, which depends on this.
30 class SchemaRegistryServiceFactory : public BrowserContextKeyedBaseFactory {
31 public:
32 // Returns the SchemaRegistryServiceFactory singleton.
33 static SchemaRegistryServiceFactory* GetInstance();
35 // Returns the SchemaRegistryService associated with |context|. This is only
36 // valid before |context| is shut down.
37 static SchemaRegistryService* GetForContext(content::BrowserContext* context);
39 // Creates a new SchemaRegistryService for |context|, which must be managed
40 // by the caller. Subsequent calls to GetForContext() will return the instance
41 // created, as long as it lives.
42 static scoped_ptr<SchemaRegistryService> CreateForContext(
43 content::BrowserContext* context,
44 const Schema& chrome_schema,
45 CombinedSchemaRegistry* global_registry);
47 private:
48 friend struct DefaultSingletonTraits<SchemaRegistryServiceFactory>;
50 SchemaRegistryServiceFactory();
51 virtual ~SchemaRegistryServiceFactory();
53 SchemaRegistryService* GetForContextInternal(
54 content::BrowserContext* context);
56 scoped_ptr<SchemaRegistryService> CreateForContextInternal(
57 content::BrowserContext* context,
58 const Schema& chrome_schema,
59 CombinedSchemaRegistry* global_registry);
61 // BrowserContextKeyedBaseFactory:
62 virtual void BrowserContextShutdown(
63 content::BrowserContext* context) override;
64 virtual void BrowserContextDestroyed(
65 content::BrowserContext* context) override;
66 virtual void SetEmptyTestingFactory(
67 content::BrowserContext* context) override;
68 virtual bool HasTestingFactory(content::BrowserContext* context) override;
69 virtual void CreateServiceNow(content::BrowserContext* context) override;
71 typedef std::map<content::BrowserContext*, SchemaRegistryService*>
72 RegistryMap;
73 RegistryMap registries_;
75 DISALLOW_COPY_AND_ASSIGN(SchemaRegistryServiceFactory);
78 } // namespace policy
80 #endif // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_