Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / ownership / owner_settings_service_chromeos_factory.cc
blobbbd4ca4800ee58802d4c4206ce751fda85a9880a
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.
5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
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/chromeos/settings/device_settings_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chromeos/chromeos_paths.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/ownership/owner_key_util.h"
15 #include "components/ownership/owner_key_util_impl.h"
17 namespace chromeos {
19 namespace {
21 DeviceSettingsService* g_device_settings_service_for_testing_ = nullptr;
23 DeviceSettingsService* GetDeviceSettingsService() {
24 if (g_device_settings_service_for_testing_)
25 return g_device_settings_service_for_testing_;
26 return DeviceSettingsService::IsInitialized() ? DeviceSettingsService::Get()
27 : nullptr;
30 } // namespace
32 OwnerSettingsServiceChromeOSFactory::OwnerSettingsServiceChromeOSFactory()
33 : BrowserContextKeyedServiceFactory(
34 "OwnerSettingsService",
35 BrowserContextDependencyManager::GetInstance()) {
38 OwnerSettingsServiceChromeOSFactory::~OwnerSettingsServiceChromeOSFactory() {
41 // static
42 OwnerSettingsServiceChromeOS*
43 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(
44 content::BrowserContext* context) {
45 return static_cast<OwnerSettingsServiceChromeOS*>(
46 GetInstance()->GetServiceForBrowserContext(context, true));
49 // static
50 OwnerSettingsServiceChromeOSFactory*
51 OwnerSettingsServiceChromeOSFactory::GetInstance() {
52 return base::Singleton<OwnerSettingsServiceChromeOSFactory>::get();
55 // static
56 void OwnerSettingsServiceChromeOSFactory::SetDeviceSettingsServiceForTesting(
57 DeviceSettingsService* device_settings_service) {
58 g_device_settings_service_for_testing_ = device_settings_service;
61 scoped_refptr<ownership::OwnerKeyUtil>
62 OwnerSettingsServiceChromeOSFactory::GetOwnerKeyUtil() {
63 if (owner_key_util_.get())
64 return owner_key_util_;
65 base::FilePath public_key_path;
66 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path))
67 return NULL;
68 owner_key_util_ = new ownership::OwnerKeyUtilImpl(public_key_path);
69 return owner_key_util_;
72 void OwnerSettingsServiceChromeOSFactory::SetOwnerKeyUtilForTesting(
73 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) {
74 owner_key_util_ = owner_key_util;
77 // static
78 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildInstanceFor(
79 content::BrowserContext* browser_context) {
80 Profile* profile = static_cast<Profile*>(browser_context);
81 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile))
82 return NULL;
83 return new OwnerSettingsServiceChromeOS(
84 GetDeviceSettingsService(),
85 profile,
86 GetInstance()->GetOwnerKeyUtil());
89 bool OwnerSettingsServiceChromeOSFactory::ServiceIsCreatedWithBrowserContext()
90 const {
91 return true;
94 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildServiceInstanceFor(
95 content::BrowserContext* context) const {
96 return BuildInstanceFor(context);
99 } // namespace chromeos