Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / supervised_user / chromeos / manager_password_service_factory.cc
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/manager_password_service_factory.h"
6
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/supervised_user_shared_settings_service_factory.h"
14 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/user_manager/user.h"
17
18 namespace chromeos {
19
20 // static
21 ManagerPasswordService*
22 ManagerPasswordServiceFactory::GetForProfile(Profile* profile) {
23   return static_cast<ManagerPasswordService*>(
24       GetInstance()->GetServiceForBrowserContext(profile, true));
25 }
26
27 // static
28 ManagerPasswordServiceFactory*
29 ManagerPasswordServiceFactory::GetInstance() {
30   return Singleton<ManagerPasswordServiceFactory>::get();
31 }
32
33 ManagerPasswordServiceFactory::ManagerPasswordServiceFactory()
34     : BrowserContextKeyedServiceFactory(
35           "ManagerPasswordService",
36           BrowserContextDependencyManager::GetInstance()) {
37   DependsOn(SupervisedUserSharedSettingsServiceFactory::GetInstance());
38   DependsOn(SupervisedUserSyncServiceFactory::GetInstance());
39 }
40
41 ManagerPasswordServiceFactory::
42     ~ManagerPasswordServiceFactory() {}
43
44 KeyedService* ManagerPasswordServiceFactory::BuildServiceInstanceFor(
45     content::BrowserContext* context) const {
46   Profile* profile= static_cast<Profile*>(context);
47   user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile);
48   if (ChromeUserManager::Get()->GetSupervisedUserManager()->HasSupervisedUsers(
49           user->email())) {
50     ManagerPasswordService* result = new ManagerPasswordService();
51     result->Init(
52         user->email(),
53         SupervisedUserSyncServiceFactory::GetForProfile(profile),
54         SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(
55             profile));
56     return result;
57   }
58   return NULL;
59 }
60
61 content::BrowserContext*
62 ManagerPasswordServiceFactory::GetBrowserContextToUse(
63     content::BrowserContext* context) const {
64   return chrome::GetBrowserContextRedirectedInIncognito(context);
65 }
66
67 }  // namespace chromeos