| OLD | NEW |
| 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 "chrome/browser/chromeos/login/users/user_manager.h" | |
| 8 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" | 7 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 12 #include "components/user_manager/user.h" | 11 #include "components/user_manager/user.h" |
| 12 #include "components/user_manager/user_manager.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 OwnerSettingsServiceFactory::OwnerSettingsServiceFactory() | 16 OwnerSettingsServiceFactory::OwnerSettingsServiceFactory() |
| 17 : BrowserContextKeyedServiceFactory( | 17 : BrowserContextKeyedServiceFactory( |
| 18 "OwnerSettingsService", | 18 "OwnerSettingsService", |
| 19 BrowserContextDependencyManager::GetInstance()) { | 19 BrowserContextDependencyManager::GetInstance()) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 OwnerSettingsServiceFactory::~OwnerSettingsServiceFactory() { | 22 OwnerSettingsServiceFactory::~OwnerSettingsServiceFactory() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 OwnerSettingsService* OwnerSettingsServiceFactory::GetForProfile( | 26 OwnerSettingsService* OwnerSettingsServiceFactory::GetForProfile( |
| 27 Profile* profile) { | 27 Profile* profile) { |
| 28 return static_cast<OwnerSettingsService*>( | 28 return static_cast<OwnerSettingsService*>( |
| 29 GetInstance()->GetServiceForBrowserContext(profile, true)); | 29 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 OwnerSettingsServiceFactory* OwnerSettingsServiceFactory::GetInstance() { | 33 OwnerSettingsServiceFactory* OwnerSettingsServiceFactory::GetInstance() { |
| 34 return Singleton<OwnerSettingsServiceFactory>::get(); | 34 return Singleton<OwnerSettingsServiceFactory>::get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void OwnerSettingsServiceFactory::SetUsername(const std::string& username) { | 37 void OwnerSettingsServiceFactory::SetUsername(const std::string& username) { |
| 38 username_ = username; | 38 username_ = username; |
| 39 if (!UserManager::IsInitialized()) | 39 if (!user_manager::UserManager::IsInitialized()) |
| 40 return; | 40 return; |
| 41 const user_manager::User* user = UserManager::Get()->FindUser(username_); | 41 const user_manager::User* user = |
| 42 user_manager::UserManager::Get()->FindUser(username_); |
| 42 if (!user || !user->is_profile_created()) | 43 if (!user || !user->is_profile_created()) |
| 43 return; | 44 return; |
| 44 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); | 45 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); |
| 45 if (!profile) | 46 if (!profile) |
| 46 return; | 47 return; |
| 47 OwnerSettingsService* service = GetForProfile(profile); | 48 OwnerSettingsService* service = GetForProfile(profile); |
| 48 | 49 |
| 49 // It's safe to call ReloadPrivateKey() here, as profile is fully created | 50 // It's safe to call ReloadPrivateKey() here, as profile is fully created |
| 50 // at this time. | 51 // at this time. |
| 51 if (service) | 52 if (service) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 bool OwnerSettingsServiceFactory::ServiceIsCreatedWithBrowserContext() const { | 69 bool OwnerSettingsServiceFactory::ServiceIsCreatedWithBrowserContext() const { |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 KeyedService* OwnerSettingsServiceFactory::BuildServiceInstanceFor( | 73 KeyedService* OwnerSettingsServiceFactory::BuildServiceInstanceFor( |
| 73 content::BrowserContext* context) const { | 74 content::BrowserContext* context) const { |
| 74 return BuildInstanceFor(context); | 75 return BuildInstanceFor(context); |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace chromeos | 78 } // namespace chromeos |
| OLD | NEW |