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

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

Issue 516243002: Instantiation of OwnerKeyUtil is delegated to OwnerSettingsServiceFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 6 years, 3 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_factory.h" 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h"
6 6
7 #include "base/path_service.h"
7 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" 8 #include "chrome/browser/chromeos/ownership/owner_settings_service.h"
8 #include "chrome/browser/chromeos/profiles/profile_helper.h" 9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chromeos/chromeos_paths.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" 12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "components/ownership/mock_owner_key_util.h"
14 #include "components/ownership/owner_key_util_impl.h"
11 15
12 namespace chromeos { 16 namespace chromeos {
13 17
14 OwnerSettingsServiceFactory::OwnerSettingsServiceFactory() 18 OwnerSettingsServiceFactory::OwnerSettingsServiceFactory()
15 : BrowserContextKeyedServiceFactory( 19 : BrowserContextKeyedServiceFactory(
16 "OwnerSettingsService", 20 "OwnerSettingsService",
17 BrowserContextDependencyManager::GetInstance()) { 21 BrowserContextDependencyManager::GetInstance()) {
18 } 22 }
19 23
20 OwnerSettingsServiceFactory::~OwnerSettingsServiceFactory() { 24 OwnerSettingsServiceFactory::~OwnerSettingsServiceFactory() {
21 } 25 }
22 26
23 // static 27 // static
24 OwnerSettingsService* OwnerSettingsServiceFactory::GetForProfile( 28 OwnerSettingsService* OwnerSettingsServiceFactory::GetForProfile(
25 Profile* profile) { 29 Profile* profile) {
26 return static_cast<OwnerSettingsService*>( 30 return static_cast<OwnerSettingsService*>(
27 GetInstance()->GetServiceForBrowserContext(profile, true)); 31 GetInstance()->GetServiceForBrowserContext(profile, true));
28 } 32 }
29 33
30 // static 34 // static
31 OwnerSettingsServiceFactory* OwnerSettingsServiceFactory::GetInstance() { 35 OwnerSettingsServiceFactory* OwnerSettingsServiceFactory::GetInstance() {
32 return Singleton<OwnerSettingsServiceFactory>::get(); 36 return Singleton<OwnerSettingsServiceFactory>::get();
33 } 37 }
34 38
39 scoped_refptr<ownership::OwnerKeyUtil>
40 OwnerSettingsServiceFactory::GetOwnerKeyUtil() {
41 if (owner_key_util_.get())
42 return owner_key_util_;
43 base::FilePath public_key_path;
44 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path))
45 return NULL;
46 owner_key_util_ = new ownership::OwnerKeyUtilImpl(public_key_path);
47 return owner_key_util_;
48 }
49
50 void OwnerSettingsServiceFactory::SetOwnerKeyUtilForTesting(
51 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util) {
52 owner_key_util_ = owner_key_util;
53 }
54
35 // static 55 // static
36 KeyedService* OwnerSettingsServiceFactory::BuildInstanceFor( 56 KeyedService* OwnerSettingsServiceFactory::BuildInstanceFor(
37 content::BrowserContext* browser_context) { 57 content::BrowserContext* browser_context) {
38 Profile* profile = static_cast<Profile*>(browser_context); 58 Profile* profile = static_cast<Profile*>(browser_context);
39 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile)) 59 if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile))
40 return NULL; 60 return NULL;
41 return new OwnerSettingsService(profile); 61 return new OwnerSettingsService(profile, GetInstance()->GetOwnerKeyUtil());
42 } 62 }
43 63
44 bool OwnerSettingsServiceFactory::ServiceIsCreatedWithBrowserContext() const { 64 bool OwnerSettingsServiceFactory::ServiceIsCreatedWithBrowserContext() const {
45 return true; 65 return true;
46 } 66 }
47 67
48 KeyedService* OwnerSettingsServiceFactory::BuildServiceInstanceFor( 68 KeyedService* OwnerSettingsServiceFactory::BuildServiceInstanceFor(
49 content::BrowserContext* context) const { 69 content::BrowserContext* context) const {
50 return BuildInstanceFor(context); 70 return BuildInstanceFor(context);
51 } 71 }
52 72
53 } // namespace chromeos 73 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698