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. 4 5#include "chrome/browser/supervised_user/chromeos/supervised_user_password_service_factory.h" 6 7#include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 8#include "chrome/browser/chromeos/profiles/profile_helper.h" 9#include "chrome/browser/profiles/incognito_helpers.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/supervised_user/chromeos/supervised_user_password_service.h" 12#include "chrome/browser/supervised_user/supervised_user_shared_settings_service_factory.h" 13#include "components/keyed_service/content/browser_context_dependency_manager.h" 14#include "components/user_manager/user.h" 15#include "components/user_manager/user_type.h" 16 17namespace chromeos { 18 19// static 20SupervisedUserPasswordService* 21SupervisedUserPasswordServiceFactory::GetForProfile(Profile* profile) { 22 return static_cast<SupervisedUserPasswordService*>( 23 GetInstance()->GetServiceForBrowserContext(profile, true)); 24} 25 26// static 27SupervisedUserPasswordServiceFactory* 28SupervisedUserPasswordServiceFactory::GetInstance() { 29 return Singleton<SupervisedUserPasswordServiceFactory>::get(); 30} 31 32SupervisedUserPasswordServiceFactory::SupervisedUserPasswordServiceFactory() 33 : BrowserContextKeyedServiceFactory( 34 "SupervisedUserPasswordService", 35 BrowserContextDependencyManager::GetInstance()) { 36 DependsOn(SupervisedUserSharedSettingsServiceFactory::GetInstance()); 37} 38 39SupervisedUserPasswordServiceFactory:: 40 ~SupervisedUserPasswordServiceFactory() {} 41 42KeyedService* SupervisedUserPasswordServiceFactory::BuildServiceInstanceFor( 43 content::BrowserContext* context) const { 44 Profile* profile= static_cast<Profile*>(context); 45 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); 46 if (user->GetType() != user_manager::USER_TYPE_SUPERVISED) 47 return NULL; 48 SupervisedUserPasswordService* result = new SupervisedUserPasswordService(); 49 result->Init( 50 user->email(), 51 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( 52 profile)); 53 return result; 54} 55 56content::BrowserContext* 57SupervisedUserPasswordServiceFactory::GetBrowserContextToUse( 58 content::BrowserContext* context) const { 59 return chrome::GetBrowserContextRedirectedInIncognito(context); 60} 61 62} // namespace chromeos 63