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/supervised_user/chromeos/manager_password_service_factory.h"
7 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
8 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/supervised_user/chromeos/manager_password_service.h"
13 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service_factory.h"
14 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_factory.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/user_manager/user.h"
21 ManagerPasswordService
*
22 ManagerPasswordServiceFactory::GetForProfile(Profile
* profile
) {
23 return static_cast<ManagerPasswordService
*>(
24 GetInstance()->GetServiceForBrowserContext(profile
, true));
28 ManagerPasswordServiceFactory
*
29 ManagerPasswordServiceFactory::GetInstance() {
30 return Singleton
<ManagerPasswordServiceFactory
>::get();
33 ManagerPasswordServiceFactory::ManagerPasswordServiceFactory()
34 : BrowserContextKeyedServiceFactory(
35 "ManagerPasswordService",
36 BrowserContextDependencyManager::GetInstance()) {
37 DependsOn(SupervisedUserSharedSettingsServiceFactory::GetInstance());
38 DependsOn(SupervisedUserSyncServiceFactory::GetInstance());
41 ManagerPasswordServiceFactory::
42 ~ManagerPasswordServiceFactory() {}
44 KeyedService
* ManagerPasswordServiceFactory::BuildServiceInstanceFor(
45 content::BrowserContext
* context
) const {
46 Profile
* profile
= static_cast<Profile
*>(context
);
47 const user_manager::User
* user
=
48 ProfileHelper::Get()->GetUserByProfile(profile
);
49 if (ChromeUserManager::Get()->GetSupervisedUserManager()->HasSupervisedUsers(
51 ManagerPasswordService
* result
= new ManagerPasswordService();
54 SupervisedUserSyncServiceFactory::GetForProfile(profile
),
55 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
62 content::BrowserContext
*
63 ManagerPasswordServiceFactory::GetBrowserContextToUse(
64 content::BrowserContext
* context
) const {
65 return chrome::GetBrowserContextRedirectedInIncognito(context
);
68 } // namespace chromeos