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