Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / schema_registry_service_factory.h
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.
4
5 #ifndef CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
7
8 #include <map>
9
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"
15
16 namespace content {
17 class BrowserContext;
18 }
19
20 namespace policy {
21
22 class CombinedSchemaRegistry;
23 class Schema;
24 class SchemaRegistryService;
25
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();
34
35   // Returns the SchemaRegistryService associated with |context|. This is only
36   // valid before |context| is shut down.
37   static SchemaRegistryService* GetForContext(content::BrowserContext* context);
38
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);
46
47  private:
48   friend struct DefaultSingletonTraits<SchemaRegistryServiceFactory>;
49
50   SchemaRegistryServiceFactory();
51   ~SchemaRegistryServiceFactory() override;
52
53   SchemaRegistryService* GetForContextInternal(
54       content::BrowserContext* context);
55
56   scoped_ptr<SchemaRegistryService> CreateForContextInternal(
57       content::BrowserContext* context,
58       const Schema& chrome_schema,
59       CombinedSchemaRegistry* global_registry);
60
61   // BrowserContextKeyedBaseFactory:
62   void BrowserContextShutdown(content::BrowserContext* context) override;
63   void BrowserContextDestroyed(content::BrowserContext* context) override;
64   void SetEmptyTestingFactory(content::BrowserContext* context) override;
65   bool HasTestingFactory(content::BrowserContext* context) override;
66   void CreateServiceNow(content::BrowserContext* context) override;
67
68   typedef std::map<content::BrowserContext*, SchemaRegistryService*>
69       RegistryMap;
70   RegistryMap registries_;
71
72   DISALLOW_COPY_AND_ASSIGN(SchemaRegistryServiceFactory);
73 };
74
75 }  // namespace policy
76
77 #endif  // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_