Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.cc

Issue 985093002: Fix up Owner settings on first load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: based off mattias' patch that injects CrosSettings for testing Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 8 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" 9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/chromeos/settings/cros_settings.h"
10 #include "chrome/browser/chromeos/settings/device_settings_service.h" 11 #include "chrome/browser/chromeos/settings/device_settings_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chromeos/chromeos_paths.h" 13 #include "chromeos/chromeos_paths.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h" 14 #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.h"
15 #include "components/ownership/owner_key_util_impl.h" 16 #include "components/ownership/owner_key_util_impl.h"
16 17
17 namespace chromeos { 18 namespace chromeos {
18 19
19 namespace { 20 namespace {
20 21
21 DeviceSettingsService* g_device_settings_service_for_testing_ = nullptr; 22 DeviceSettingsService* g_device_settings_service_for_testing_ = nullptr;
23 CrosSettings* g_cros_settings_for_testing = nullptr;
22 24
23 DeviceSettingsService* GetDeviceSettingsService() { 25 DeviceSettingsService* GetDeviceSettingsService() {
24 if (g_device_settings_service_for_testing_) 26 if (g_device_settings_service_for_testing_)
25 return g_device_settings_service_for_testing_; 27 return g_device_settings_service_for_testing_;
26 return DeviceSettingsService::IsInitialized() ? DeviceSettingsService::Get() 28 return DeviceSettingsService::IsInitialized() ? DeviceSettingsService::Get()
27 : nullptr; 29 : nullptr;
28 } 30 }
29 31
32 CrosSettings* GetCrosSettings() {
33 if (g_cros_settings_for_testing)
34 return g_cros_settings_for_testing;
35 return CrosSettings::IsInitialized() ? CrosSettings::Get() : nullptr;
36 }
37
30 } // namespace 38 } // namespace
31 39
32 OwnerSettingsServiceChromeOSFactory::OwnerSettingsServiceChromeOSFactory() 40 OwnerSettingsServiceChromeOSFactory::OwnerSettingsServiceChromeOSFactory()
33 : BrowserContextKeyedServiceFactory( 41 : BrowserContextKeyedServiceFactory(
34 "OwnerSettingsService", 42 "OwnerSettingsService",
35 BrowserContextDependencyManager::GetInstance()) { 43 BrowserContextDependencyManager::GetInstance()) {
36 } 44 }
37 45
38 OwnerSettingsServiceChromeOSFactory::~OwnerSettingsServiceChromeOSFactory() { 46 OwnerSettingsServiceChromeOSFactory::~OwnerSettingsServiceChromeOSFactory() {
39 } 47 }
(...skipping 11 matching lines...) Expand all
51 OwnerSettingsServiceChromeOSFactory::GetInstance() { 59 OwnerSettingsServiceChromeOSFactory::GetInstance() {
52 return Singleton<OwnerSettingsServiceChromeOSFactory>::get(); 60 return Singleton<OwnerSettingsServiceChromeOSFactory>::get();
53 } 61 }
54 62
55 // static 63 // static
56 void OwnerSettingsServiceChromeOSFactory::SetDeviceSettingsServiceForTesting( 64 void OwnerSettingsServiceChromeOSFactory::SetDeviceSettingsServiceForTesting(
57 DeviceSettingsService* device_settings_service) { 65 DeviceSettingsService* device_settings_service) {
58 g_device_settings_service_for_testing_ = device_settings_service; 66 g_device_settings_service_for_testing_ = device_settings_service;
59 } 67 }
60 68
69 // static
70 void OwnerSettingsServiceChromeOSFactory::SetCrosSettingsForTesting(
71 CrosSettings* cros_settings) {
72 g_cros_settings_for_testing = cros_settings;
73 }
74
61 scoped_refptr<ownership::OwnerKeyUtil> 75 scoped_refptr<ownership::OwnerKeyUtil>
62 OwnerSettingsServiceChromeOSFactory::GetOwnerKeyUtil() { 76 OwnerSettingsServiceChromeOSFactory::GetOwnerKeyUtil() {
63 if (owner_key_util_.get()) 77 if (owner_key_util_.get())
64 return owner_key_util_; 78 return owner_key_util_;
65 base::FilePath public_key_path; 79 base::FilePath public_key_path;
66 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path)) 80 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path))
67 return NULL; 81 return NULL;
68 owner_key_util_ = new ownership::OwnerKeyUtilImpl(public_key_path); 82 owner_key_util_ = new ownership::OwnerKeyUtilImpl(public_key_path);
69 return owner_key_util_; 83 return owner_key_util_;
70 } 84 }
71 85
72 void OwnerSettingsServiceChromeOSFactory::SetOwnerKeyUtilForTesting( 86 void OwnerSettingsServiceChromeOSFactory::SetOwnerKeyUtilForTesting(
73 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) { 87 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) {
74 owner_key_util_ = owner_key_util; 88 owner_key_util_ = owner_key_util;
75 } 89 }
76 90
77 // static 91 // static
78 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildInstanceFor( 92 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildInstanceFor(
79 content::BrowserContext* browser_context) { 93 content::BrowserContext* browser_context) {
80 Profile* profile = static_cast<Profile*>(browser_context); 94 Profile* profile = static_cast<Profile*>(browser_context);
81 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile)) 95 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile))
82 return NULL; 96 return NULL;
83 return new OwnerSettingsServiceChromeOS( 97 return new OwnerSettingsServiceChromeOS(
84 GetDeviceSettingsService(), 98 GetDeviceSettingsService(),
99 GetCrosSettings(),
85 profile, 100 profile,
86 GetInstance()->GetOwnerKeyUtil()); 101 GetInstance()->GetOwnerKeyUtil());
87 } 102 }
88 103
89 bool OwnerSettingsServiceChromeOSFactory::ServiceIsCreatedWithBrowserContext() 104 bool OwnerSettingsServiceChromeOSFactory::ServiceIsCreatedWithBrowserContext()
90 const { 105 const {
91 return true; 106 return true;
92 } 107 }
93 108
94 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildServiceInstanceFor( 109 KeyedService* OwnerSettingsServiceChromeOSFactory::BuildServiceInstanceFor(
95 content::BrowserContext* context) const { 110 content::BrowserContext* context) const {
96 return BuildInstanceFor(context); 111 return BuildInstanceFor(context);
97 } 112 }
98 113
99 } // namespace chromeos 114 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698