schema_registry_service_factory.h revision f2477e01787aa58f445919b809d89e252beef54f
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/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/singleton.h"
14#include "components/browser_context_keyed_service/browser_context_keyed_base_factory.h"
15
16namespace content {
17class BrowserContext;
18}
19
20namespace policy {
21
22class CombinedSchemaRegistry;
23class Schema;
24class 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.
30class 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  virtual ~SchemaRegistryServiceFactory();
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  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 void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
69
70  typedef std::map<content::BrowserContext*, SchemaRegistryService*>
71      RegistryMap;
72  RegistryMap registries_;
73
74  DISALLOW_COPY_AND_ASSIGN(SchemaRegistryServiceFactory);
75};
76
77}  // namespace policy
78
79#endif  // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
80