schema_registry_service_factory.cc 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#include "chrome/browser/policy/schema_registry_service_factory.h" 6 7#include "base/logging.h" 8#include "chrome/browser/policy/schema_registry_service.h" 9#include "components/browser_context_keyed_service/browser_context_dependency_manager.h" 10#include "components/policy/core/common/schema.h" 11#include "components/policy/core/common/schema_registry.h" 12#include "content/public/browser/browser_context.h" 13 14namespace policy { 15 16// static 17SchemaRegistryServiceFactory* SchemaRegistryServiceFactory::GetInstance() { 18 return Singleton<SchemaRegistryServiceFactory>::get(); 19} 20 21// static 22SchemaRegistryService* SchemaRegistryServiceFactory::GetForContext( 23 content::BrowserContext* context) { 24 return GetInstance()->GetForContextInternal(context); 25} 26 27// static 28scoped_ptr<SchemaRegistryService> 29SchemaRegistryServiceFactory::CreateForContext( 30 content::BrowserContext* context, 31 const Schema& chrome_schema, 32 CombinedSchemaRegistry* global_registry) { 33 return GetInstance()->CreateForContextInternal( 34 context, chrome_schema, global_registry); 35} 36 37SchemaRegistryServiceFactory::SchemaRegistryServiceFactory() 38 : BrowserContextKeyedBaseFactory( 39 "SchemaRegistryService", 40 BrowserContextDependencyManager::GetInstance()) {} 41 42SchemaRegistryServiceFactory::~SchemaRegistryServiceFactory() {} 43 44SchemaRegistryService* SchemaRegistryServiceFactory::GetForContextInternal( 45 content::BrowserContext* context) { 46 // Off-the-record Profiles get their policy from the main Profile's 47 // PolicyService, and don't need their own SchemaRegistry nor any policy 48 // providers. 49 if (context->IsOffTheRecord()) 50 return NULL; 51 RegistryMap::const_iterator it = registries_.find(context); 52 CHECK(it != registries_.end()); 53 return it->second; 54} 55 56scoped_ptr<SchemaRegistryService> 57SchemaRegistryServiceFactory::CreateForContextInternal( 58 content::BrowserContext* context, 59 const Schema& chrome_schema, 60 CombinedSchemaRegistry* global_registry) { 61 DCHECK(!context->IsOffTheRecord()); 62 DCHECK(registries_.find(context) == registries_.end()); 63 SchemaRegistryService* registry = 64 new SchemaRegistryService(chrome_schema, global_registry); 65 registries_[context] = registry; 66 return make_scoped_ptr(registry); 67} 68 69void SchemaRegistryServiceFactory::BrowserContextShutdown( 70 content::BrowserContext* context) { 71 if (context->IsOffTheRecord()) 72 return; 73 RegistryMap::iterator it = registries_.find(context); 74 if (it != registries_.end()) 75 it->second->Shutdown(); 76 else 77 NOTREACHED(); 78} 79 80void SchemaRegistryServiceFactory::BrowserContextDestroyed( 81 content::BrowserContext* context) { 82 registries_.erase(context); 83 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); 84} 85 86void SchemaRegistryServiceFactory::SetEmptyTestingFactory( 87 content::BrowserContext* context) {} 88 89void SchemaRegistryServiceFactory::CreateServiceNow( 90 content::BrowserContext* context) {} 91 92} // namespace policy 93