1// Copyright 2014 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/chromeos/ownership/owner_settings_service_chromeos_factory.h" 6 7#include "base/path_service.h" 8#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 9#include "chrome/browser/chromeos/profiles/profile_helper.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chromeos/chromeos_paths.h" 12#include "components/keyed_service/content/browser_context_dependency_manager.h" 13#include "components/ownership/owner_key_util.h" 14#include "components/ownership/owner_key_util_impl.h" 15 16namespace chromeos { 17 18OwnerSettingsServiceChromeOSFactory::OwnerSettingsServiceChromeOSFactory() 19 : BrowserContextKeyedServiceFactory( 20 "OwnerSettingsService", 21 BrowserContextDependencyManager::GetInstance()) { 22} 23 24OwnerSettingsServiceChromeOSFactory::~OwnerSettingsServiceChromeOSFactory() { 25} 26 27// static 28OwnerSettingsServiceChromeOS* 29OwnerSettingsServiceChromeOSFactory::GetForProfile(Profile* profile) { 30 return static_cast<OwnerSettingsServiceChromeOS*>( 31 GetInstance()->GetServiceForBrowserContext(profile, true)); 32} 33 34// static 35OwnerSettingsServiceChromeOSFactory* 36OwnerSettingsServiceChromeOSFactory::GetInstance() { 37 return Singleton<OwnerSettingsServiceChromeOSFactory>::get(); 38} 39 40scoped_refptr<ownership::OwnerKeyUtil> 41OwnerSettingsServiceChromeOSFactory::GetOwnerKeyUtil() { 42 if (owner_key_util_.get()) 43 return owner_key_util_; 44 base::FilePath public_key_path; 45 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path)) 46 return NULL; 47 owner_key_util_ = new ownership::OwnerKeyUtilImpl(public_key_path); 48 return owner_key_util_; 49} 50 51void OwnerSettingsServiceChromeOSFactory::SetOwnerKeyUtilForTesting( 52 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) { 53 owner_key_util_ = owner_key_util; 54} 55 56// static 57KeyedService* OwnerSettingsServiceChromeOSFactory::BuildInstanceFor( 58 content::BrowserContext* browser_context) { 59 Profile* profile = static_cast<Profile*>(browser_context); 60 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile)) 61 return NULL; 62 return new OwnerSettingsServiceChromeOS(profile, 63 GetInstance()->GetOwnerKeyUtil()); 64} 65 66bool OwnerSettingsServiceChromeOSFactory::ServiceIsCreatedWithBrowserContext() 67 const { 68 return true; 69} 70 71KeyedService* OwnerSettingsServiceChromeOSFactory::BuildServiceInstanceFor( 72 content::BrowserContext* context) const { 73 return BuildInstanceFor(context); 74} 75 76} // namespace chromeos 77