schema_registry_service_factory.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 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 bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; 69 virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; 70 71 typedef std::map<content::BrowserContext*, SchemaRegistryService*> 72 RegistryMap; 73 RegistryMap registries_; 74 75 DISALLOW_COPY_AND_ASSIGN(SchemaRegistryServiceFactory); 76}; 77 78} // namespace policy 79 80#endif // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_SERVICE_FACTORY_H_ 81