1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <map>
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/compiler_specific.h"
116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "base/macros.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/singleton.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/content/browser_context_keyed_base_factory.h"
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace content {
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class BrowserContext;
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace policy {
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class CombinedSchemaRegistry;
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Schema;
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class SchemaRegistryService;
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Creates SchemaRegistryServices for BrowserContexts.
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// TODO(joaodasilva): Convert this class to a proper BCKS once the PrefService
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// becomes a BCKS too. For now the PrefService depends on the
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// UserCloudPolicyManager, which depends on this.
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class SchemaRegistryServiceFactory : public BrowserContextKeyedBaseFactory {
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public:
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the SchemaRegistryServiceFactory singleton.
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static SchemaRegistryServiceFactory* GetInstance();
34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the SchemaRegistryService associated with |context|. This is only
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // valid before |context| is shut down.
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static SchemaRegistryService* GetForContext(content::BrowserContext* context);
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Creates a new SchemaRegistryService for |context|, which must be managed
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // by the caller. Subsequent calls to GetForContext() will return the instance
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // created, as long as it lives.
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static scoped_ptr<SchemaRegistryService> CreateForContext(
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context,
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const Schema& chrome_schema,
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CombinedSchemaRegistry* global_registry);
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private:
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  friend struct DefaultSingletonTraits<SchemaRegistryServiceFactory>;
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SchemaRegistryServiceFactory();
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ~SchemaRegistryServiceFactory();
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SchemaRegistryService* GetForContextInternal(
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context);
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<SchemaRegistryService> CreateForContextInternal(
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context,
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const Schema& chrome_schema,
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CombinedSchemaRegistry* global_registry);
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // BrowserContextKeyedBaseFactory:
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void BrowserContextShutdown(
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context) OVERRIDE;
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void BrowserContextDestroyed(
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context) OVERRIDE;
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void SetEmptyTestingFactory(
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::BrowserContext* context) OVERRIDE;
68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE;
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE;
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  typedef std::map<content::BrowserContext*, SchemaRegistryService*>
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      RegistryMap;
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RegistryMap registries_;
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SchemaRegistryServiceFactory);
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)};
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace policy
79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif  // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_
81